Esempio n. 1
0
        public void Update(GameTime gameTime)
        {
            CheckKeyboardAndUpdateMovement();
            PlayerLib.AffectWithGravity();
            PlayerLib.SimulateFriction();
            PlayerLib.MoveAsFarAsPossible((float)gameTime.ElapsedGameTime.TotalMilliseconds / 15);
            PlayerLib.StopMovingIfBlocked();
            PlayerLib.IsDead(PlayerInfo.Life);

            position            = new Vector2(PlayerLib.Position.X, PlayerLib.Position.Y);
            _animation.Position = new Vector2(PlayerLib.Position.X + 20, PlayerLib.Position.Y + 35);
            _animation.Update(gameTime);
            Weapon.Update(gameTime);
            CheckMovementAndUpdateAnimation();
            PlayerInfo.Life = MathHelper.Clamp(PlayerInfo.Life, 0, 100);
            if (PlayerLib.IsOnFirmGround())
            {
                PlayerInfo.Energy++;
            }
            PlayerInfo.Energy = MathHelper.Clamp(PlayerInfo.Energy, 0, 100);

            for (int i = 0; i < _bombs.Count; i++)
            {
                _bombs[i].Update(gameTime);
                if (_bombs[i].IsFinished)
                {
                    _bombs.Remove(_bombs[i]);
                }
            }
        }
Esempio n. 2
0
        private void CheckKeyboardAndUpdateMovement()
        {
            KeyboardState keyboardState     = Keyboard.GetState();
            int           movementXPosition = (_animation.Effect == SpriteEffects.FlipHorizontally) ? -20 : 20;

            if (keyboardState.IsKeyDown(Keys.Q))
            {
                PlayerLib.Left();
            }
            if (keyboardState.IsKeyDown(Keys.D))
            {
                PlayerLib.Right();
            }
            if (keyboardState.IsKeyDown(Keys.Z) && PlayerLib.IsOnFirmGround())
            {
                PlayerLib.Jump();
            }
            if (keyboardState.IsKeyDown(Keys.B) && !_previousKey.IsKeyDown(Keys.B) && PlayerInfo.Energy >= 50)
            {
                Bomb bomb = new Bomb(_texturebomb, _sfx, position, _spritebatch, 0, this, _enemys);
                bomb.ItemLib.Movement = System.Numerics.Vector2.UnitX * movementXPosition;
                _bombs.Add(bomb);
                PlayerInfo.Energy -= 50;
            }
            if (keyboardState.IsKeyDown(Keys.A) && !_previousKey.IsKeyDown(Keys.A) && !Shield.IsActive)
            {
                Shield.IsActive = true;
            }
            else if (keyboardState.IsKeyDown(Keys.A) && !_previousKey.IsKeyDown(Keys.A) && Shield.IsActive)
            {
                Shield.IsActive = false;
            }
            if (Shield.IsActive)
            {
                PlayerInfo.Energy -= 2;
            }
            if (PlayerInfo.Energy <= 0)
            {
                Shield.IsActive = false;
            }
            _previousKey = keyboardState;
        }
Esempio n. 3
0
        private void CheckMovementAndUpdateAnimation()
        {
            if (PlayerLib.IsOnFirmGround())
            {
                if (PlayerLib.Movement.X < -1)
                {
                    if (_animeState != 0)
                    {
                        _animation.CurrentFrameCol = 0;
                        _animeState = 0;
                    }
                    _animation.FrameWidth      = 47;
                    _animation.FrameCount      = 5;
                    _animation.Effect          = SpriteEffects.FlipHorizontally;
                    _animation.CurrentFrameLin = 2;
                    _animation.FrameTime       = 150;
                }
                else if (PlayerLib.Movement.X > 1)
                {
                    if (_animeState != 1)
                    {
                        _animation.CurrentFrameCol = 0;
                        _animeState = 1;
                    }
                    _animation.FrameWidth      = 47;
                    _animation.FrameCount      = 5;
                    _animation.Effect          = SpriteEffects.None;
                    _animation.CurrentFrameLin = 2;
                    _animation.FrameTime       = 150;
                }
                else
                {
                    if (_animeState != 2)
                    {
                        _animation.CurrentFrameCol = 0;
                        _animeState = 2;
                    }
                    _animation.FrameTime       = 300;
                    _animation.FrameWidth      = 40;
                    _animation.FrameCount      = 2;
                    _animation.CurrentFrameLin = 0;
                }
            }
            else
            {
                if (PlayerLib.Movement.Y < -3)
                {
                    _animation.CurrentFrameCol = 2;
                    _animation.FrameWidth      = 40;
                    _animation.FrameCount      = 0;
                    _animation.CurrentFrameLin = 1;
                    _animation.FrameTime       = 1000;
                }
                else if (PlayerLib.Movement.Y > 3)
                {
                    _animation.CurrentFrameCol = 0;

                    _animation.FrameWidth      = 40;
                    _animation.FrameCount      = 0;
                    _animation.CurrentFrameLin = 1;
                    _animation.FrameTime       = 1000;
                }
                else
                {
                    _animation.CurrentFrameCol = 1;

                    _animation.FrameTime       = 1000;
                    _animation.FrameWidth      = 40;
                    _animation.FrameCount      = 1;
                    _animation.CurrentFrameLin = 1;
                }
            }
        }