Exemple #1
0
        internal void Update(GameTime gameTime)
        {
            switch (state)
            {
            case (State.Here):
                celAnimationPlayer.Play(spinning);
                celAnimationPlayer.Update(gameTime);
                coinTimer += gameTime.ElapsedGameTime.TotalSeconds;
                if (coinTimer > 15)
                {
                    state = State.Gone;
                }
                break;

            case (State.Gone):
                break;
            }
        }
Exemple #2
0
        internal void Update(GameTime gameTime)
        {
            int rightSide = 675 - (int)_dimensions.X;

            switch (state)
            {
            case State.Up:
                if (_position.X > rightSide)
                {
                    _position.X = rightSide;
                }
                if (_position.X < 0)
                {
                    _position.X = 0;
                }
                _position  += velocity * (float)gameTime.ElapsedGameTime.TotalSeconds;
                velocity.Y += Game1.Gravity;
                if (velocity.X > 0)
                {
                    velocity.X -= speed * (float)gameTime.ElapsedGameTime.TotalSeconds;
                }
                if (velocity.X < 0)
                {
                    velocity.X += speed * (float)gameTime.ElapsedGameTime.TotalSeconds;
                }
                if (Math.Abs(velocity.Y) > 16 * Game1.Gravity)
                {
                    state = State.Falling;
                }
                break;

            case State.Falling:
                if (_position.X > rightSide)
                {
                    _position.X = rightSide;
                }
                if (_position.X < 0)
                {
                    _position.X = 0;
                }
                _position  += velocity * (float)gameTime.ElapsedGameTime.TotalSeconds;
                velocity.Y += Game1.Gravity;
                if (velocity.X > 0)
                {
                    velocity.X -= speed * (float)gameTime.ElapsedGameTime.TotalSeconds;
                }
                if (velocity.X < 0)
                {
                    velocity.X += speed * (float)gameTime.ElapsedGameTime.TotalSeconds;
                }
                break;

            case State.Down:
                if (_position.X > rightSide)
                {
                    _position.X = rightSide;
                }
                if (_position.X < 0)
                {
                    _position.X = 0;
                }
                _position  += velocity * (float)gameTime.ElapsedGameTime.TotalSeconds;
                velocity.Y += Game1.Gravity;
                if (velocity.X > 0)
                {
                    velocity.X -= speed * (float)gameTime.ElapsedGameTime.TotalSeconds;
                }
                if (velocity.X < 0)
                {
                    velocity.X += speed * (float)gameTime.ElapsedGameTime.TotalSeconds;
                }
                if (Math.Abs(velocity.Y) > 16 * Game1.Gravity)
                {
                    state = State.Falling;
                }
                break;

            case State.Dying:
                celAnimationPlayer.Play(brokenAnimationSequence);
                dyingTimer += gameTime.ElapsedGameTime.TotalSeconds;
                celAnimationPlayer.Update(gameTime);
                if (dyingTimer > 3)
                {
                    state = State.Dead;
                }
                break;
            }
        }
Exemple #3
0
        internal void Update(GameTime gameTime)
        {
            int           rightSide = 675 - (int)dimensions.X;
            KeyboardState kb        = Keyboard.GetState();

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

            position   += velocity * (float)gameTime.ElapsedGameTime.TotalSeconds;
            velocity.Y += Game1.Gravity;
            if (Math.Abs(velocity.Y) > 16 * Game1.Gravity)
            {
                state = State.Jumping;
            }

            switch (state)
            {
            case (State.Idle):
                break;

            case (State.Walking):
                if (kb.IsKeyDown(Keys.Left))
                {
                    animationPlayer.Play(walkSequence);
                    animationPlayer.Update(gameTime);
                    se = SpriteEffects.None;
                }
                if (kb.IsKeyDown(Keys.Right))
                {
                    animationPlayer.Play(walkSequence);
                    animationPlayer.Update(gameTime);
                    se = SpriteEffects.FlipHorizontally;
                }
                break;

            case (State.Jumping):
                if (kb.IsKeyDown(Keys.Left))
                {
                    animationPlayer.Play(walkSequence);
                    animationPlayer.Update(gameTime);
                    se = SpriteEffects.None;
                }
                if (kb.IsKeyDown(Keys.Right))
                {
                    animationPlayer.Play(walkSequence);
                    animationPlayer.Update(gameTime);
                    se = SpriteEffects.FlipHorizontally;
                }
                break;
            }
        }