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
        public bool HasTouchedBoss(PlayerLib playerLib)
        {
            foreach (Boss boss in _bosses)
            {
                if (new System.Drawing.Rectangle((int)position.X, (int)position.Y, 18, 13).IntersectsWith(boss.BossLib.Bounds))
                {
                    if (_animationBullet != null)
                    {
                        boss.BossLib.Life -= 40;
                    }

                    if (PlayerInfo.ActualBullet == PlayerInfo.BulletState.None)
                    {
                        boss.BossLib.Life -= 10;
                        boss.BossLib.ReceiveDamage(playerLib);
                        boss.BossLib.State = 0;
                    }
                    else if (PlayerInfo.ActualBullet == PlayerInfo.BulletState.Fire)
                    {
                        boss.BossLib.Life -= 10;
                        boss.BossLib.ReceiveDamage(playerLib);
                        boss.BossLib.State = 1;
                    }
                    else if (PlayerInfo.ActualBullet == PlayerInfo.BulletState.Slime)
                    {
                        boss.BossLib.Life -= 10;
                        boss.BossLib.ReceiveDamage(playerLib);
                        boss.BossLib.State = 2;
                    }
                    return(true);
                }
            }
            return(false);
        }
Esempio n. 3
0
 public Player(Texture2D texturePlayer, Texture2D textureWeapon, Texture2D textureBomb, Texture2D sfx, Texture2D textureBullet, DungeonPlanetGame ctx, Vector2 position, SpriteBatch spritebatch, List <Enemy> enemys, List <Boss> bosses)
     : base(texturePlayer, position, spritebatch)
 {
     PlayerLib  = new PlayerLib(new System.Numerics.Vector2(position.X, position.Y), 40, 64);
     PlayerInfo = new PlayerInfo();
     _animation = new Animation();
     _animation.Initialize(texturePlayer, position, 40, 64, 0, 0, 2, 150, Color.White, 1, true, false);
     _sfx          = sfx;
     Weapon        = new Weapon(textureWeapon, textureBullet, ctx, position, spritebatch, bosses);
     _bombs        = new List <Bomb>();
     _texturebomb  = textureBomb;
     _spritebatch  = spritebatch;
     _enemys       = enemys;
     CurrentPlayer = this;
 }
Esempio n. 4
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. 5
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;
                }
            }
        }