Пример #1
0
 // non animated sprite
 public StaticSprite(Texture2D textureImage, Vector2 position, Point frameSize)
     : base(textureImage, position, frameSize)
 {
     CollisionBox.UpdateCollisionBox(
         new Vector2(position.X, position.Y),                              // top left vertex (AABB max)
         new Vector2(position.X + frameSize.X, position.Y + frameSize.Y)); // bottom right vertex (AABB min)
 }
Пример #2
0
 public StaticSprite(Texture2D textureImage, Vector2 position, Point frameSize, Point currentFrame, Point sheetSize, int millisecondsPerFrame)
     : base(textureImage, position, frameSize, currentFrame, sheetSize, millisecondsPerFrame)
 {
     CollisionBox.UpdateCollisionBox(
         new Vector2(position.X, position.Y),                              // top left vertex (AABB max)
         new Vector2(position.X + frameSize.X, position.Y + frameSize.Y)); // bottom right vertex (AABB min)
 }
Пример #3
0
        public override void Update(GameTime gameTime, Rectangle clientBounds)
        {
            KeyboardState keyboard = Keyboard.GetState();

            if (lastPosition >= position.Y)
            {
                isFalling = false;
            }
            else
            {
                isFalling = true;
                isJumping = false;
            }
            lastPosition = position.Y;

            if (isJumping && !isFalling)
            {
                velocity = speed * Direction + new Vector2(0, jump) + Physics.World.Gravity;
            }
            else
            {
                velocity = speed * Direction + Physics.World.Gravity;
            }

            position      += velocity;                                                  // update position
            playerPosition = position;

            // Keep sprite inside of game screen
            if (position.X < 0)
            {
                position.X = 0;
            }

            if (position.Y < 0)
            {
                position.Y = 0;
            }

            if (position.X > clientBounds.Width - frameSize.X)
            {
                position.X = clientBounds.Width - frameSize.X;
            }

            if (position.Y > clientBounds.Height - frameSize.Y)
            {
                position.Y = clientBounds.Height - frameSize.Y;
            }

            // Update collision box to current position
            CollisionBox.UpdateCollisionBox(
                new Vector2(position.X, position.Y),                              // player top left vertex (AABB max)
                new Vector2(position.X + frameSize.X, position.Y + frameSize.Y)); // player bottom right vertex (AABB min)

            base.Update(gameTime, clientBounds);
        }
Пример #4
0
        public override void Update(GameTime gameTime, Rectangle clientBounds)
        {
            //move logic
            position += speed * Direction;                                                       // update position


            // Update collision box to current position
            CollisionBox.UpdateCollisionBox(
                new Vector2(position.X, position.Y),                              // top left vertex (AABB max)
                new Vector2(position.X + frameSize.X, position.Y + frameSize.Y)); // bottom right vertex (AABB min)

            base.Update(gameTime, clientBounds);
        }