Esempio n. 1
0
 public Player(Vector2 position)
     : base(position)
 {
     this.position = position;
     this.name = "Player";
     player = this;
     velocity = new Vector2(5, 5);
     for (int i = 0; i < ammo; i++)
     {
         Obj o = new Bullet(this.position);
         o.alive = false;
         currentClip.Add(o);
     }
     this.health = maxHealth;
 }
Esempio n. 2
0
        public override void Update()
        {
            player = this;
            if (!alive) return;
            if (health <= 0)
            {
                /*alive = false;
                health = 0;*/
                Game.switchGameState(Game.GameState.exit);
            }

            area.X = (int)position.X - (sprite.Width / 2);
            area.Y = (int)position.Y - (sprite.Height / 2);

            mouse = Mouse.GetState();
            key = Keyboard.GetState();

            if ((key.IsKeyDown(Keys.Up) || key.IsKeyDown(Keys.W)) && !Collision(new Vector2(0, -velocity.Y), true))
                position.Y -= velocity.Y;
            if ((key.IsKeyDown(Keys.Down) || key.IsKeyDown(Keys.S)) && !Collision(new Vector2(0, velocity.Y), true))
                position.Y += velocity.Y;
            if ((key.IsKeyDown(Keys.Right) || key.IsKeyDown(Keys.D)) && !Collision(new Vector2(velocity.X, 0), true))
                position.X += velocity.X;
            if ((key.IsKeyDown(Keys.Left) || key.IsKeyDown(Keys.A)) && !Collision(new Vector2(-velocity.X, 0), true))
                position.X -= velocity.X;
            if (key.IsKeyDown(Keys.Escape))
                Menu();

            if (position.Y < 0)
                position.Y = 0;
            else if (position.Y > Game.stage.Height)
                position.Y = Game.stage.Height;

            if (position.X < 0)
                position.X = 0;
            else if (position.X > Game.stage.Width)
                position.X = Game.stage.Width;

            shootingTimer++;
            if (mouse.LeftButton == ButtonState.Pressed && !reloading)
            {
                checkTimer();
            }
            if (currentClip.Count > 0)
            {
                for (int i = 0; i < currentClip.Count; i++)
                    currentClip[i].Update();
            }

            if (key.IsKeyDown(Keys.R) || mouse.RightButton == ButtonState.Pressed)
            {
                reloading = true;
            }
            Reload();

            rotation = pointDirection(Camera.globalToLocal(position), new Vector2(mouse.X, mouse.Y));

            prevMouse = mouse;
            prevKey = key;
        }