Example #1
0
        public override void Update(GameTime gameTime)
        {
            if (!Visible)
            {
                return;
            }

            MovePlayer();
            Collisions();

            weapon.Move(movement);
            this.Move(movement);

            if (InputEngine.IsKeyHeld(Keys.Space) && !weapon.Active)
            {
                weapon.Active = true;
                Frames        = 4;
                _moveState    = (int)_moveStates.ATTACK;
                Image         = _States[5];
            }
            //if(InputEngine.IsKeyPressed(Keys.B) && gun.projectiles.Count < 5)
            //{
            //    if (_dir == "right")
            //        gun.projectiles.Add(new Projectile(game, _States[6], new Vector2(Position.X + Dimensions.X/2,Position.Y + Dimensions.Y/3), "bullet", boundtx, new Vector2(8, 8), 1, 5, 1));
            //    else
            //        gun.projectiles.Add(new Projectile(game, _States[6], new Vector2(Position.X + Dimensions.X / 2, Position.Y + Dimensions.Y / 3), "bullet", boundtx, new Vector2(8, 8), 1, 5, -1));
            //}
            weapon._dir = _dir;
            weapon.Update(gameTime);
            gun.Update(gameTime);
            foreach (Projectile p in gun.projectiles)
            {
                p.Update(gameTime);
            }



            base.Update(gameTime);
        }
Example #2
0
        void MovePlayer()
        {
            oldPosition = Position;
            int LastState = _moveState;

            bool jump = false;

            if (!grounded)
            {
                movement.Y += 1f;
            }
            else
            {
                if (!weapon.Active)
                {
                    _moveState = (int)_moveStates.STOP;
                    Frames     = 4;
                }
                gravity = 0f;
            }

            if (InputEngine.IsKeyHeld(Keys.Left) || InputEngine.IsKeyHeld(Keys.A))
            {
                movement.X += -1;
                if (movement.X > 0)
                {
                    movement.X += -1;
                }
                if (grounded)
                {
                    _moveState = (int)_moveStates.LEFT;
                }
            }
            if (InputEngine.IsKeyHeld(Keys.Right) || InputEngine.IsKeyHeld(Keys.D))
            {
                movement.X += 1;
                if (movement.X < 0)
                {
                    movement.X += 1;
                }
                if (grounded)
                {
                    _moveState = (int)_moveStates.RIGHT;
                }
            }
            if ((InputEngine.IsKeyHeld(Keys.Up) || InputEngine.IsKeyHeld(Keys.W)) && grounded)
            {
                movement.Y -= 20;
                grounded    = false;

                _moveState = (int)_moveStates.UP;
            }

            if (movement.X > 6)
            {
                movement.X = 6;
            }
            if (movement.X < -6)
            {
                movement.X = -6;
            }

            if (movement.Y > 0)
            {
                _moveState = (int)_moveStates.DOWN;
            }
            if (!weapon.Active)
            {
                if (LastState != _moveState)
                {
                    currentFrame = 0;
                    switch (_moveState)
                    {
                    case (int)_moveStates.RIGHT:
                        Image  = _States[1];
                        Frames = 7;
                        break;

                    case (int)_moveStates.LEFT:
                        Image  = _States[1];
                        Frames = 7;
                        break;

                    case (int)_moveStates.UP:
                        Image  = _States[2];
                        Frames = 2;
                        break;

                    case (int)_moveStates.DOWN:
                        Image  = _States[3];
                        Frames = 2;
                        break;

                    default:
                        Image = _States[0];
                        break;
                    }
                }
            }



            if (movement.X > 0)
            {
                _dir        = "right";
                movement.X -= 0.2f;
            }
            if (movement.X < 0)
            {
                _dir        = "left";
                movement.X += 0.2f;
            }

            if (movement.X <= 0.2f && movement.X >= -0.2f)
            {
                movement.X = 0;
            }

            if (_dir == "right")
            {
                weapon.Position = new Vector2(this.Position.X, this.Position.Y + Dimensions.Y / 2);
                gun.Position    = new Vector2(this.Position.X, this.Position.Y + Dimensions.Y / 2);
            }
            if (_dir == "left")
            {
                weapon.Position = new Vector2(this.Position.X - 24, this.Position.Y + Dimensions.Y / 2);
                gun.Position    = new Vector2(this.Position.X, this.Position.Y + Dimensions.Y / 2);
            }
        }