Esempio n. 1
0
File: Player.cs Progetto: pens/hs
 public void Update(GameTime gameTime)
 {
     if (InputManager.KeyDown(Keys.W, false))
     {
         position.Y -= Speed * (float)gameTime.ElapsedGameTime.TotalSeconds;
     }
     else if (InputManager.KeyDown(Keys.S, false))
     {
         position.Y += Speed * (float)gameTime.ElapsedGameTime.TotalSeconds;
     }
     if (InputManager.KeyDown(Keys.A, false))
     {
         position.X -= Speed * (float)gameTime.ElapsedGameTime.TotalSeconds;
     }
     else if (InputManager.KeyDown(Keys.D, false))
     {
         position.X += Speed * (float)gameTime.ElapsedGameTime.TotalSeconds;
     }
     Gun.Position = RightArm.Position = LeftArm.Position = Head.Position = Chest.Position = Feet.Position = position;
     Gun.Rotation = RightArm.Rotation = LeftArm.Rotation = Head.Rotation = Chest.Rotation = Feet.Rotation =
         (float)Math.Atan2(-Head.Position.Y + InputManager.MousePos().Y, -Head.Position.X + InputManager.MousePos().X);
     Gun.Position      += Vector2.Transform(new Vector2(16, 0), Matrix.CreateRotationZ((float)Math.Atan2(-Head.Position.Y + InputManager.MousePos().Y, -Head.Position.X + InputManager.MousePos().X)));
     RightArm.Position += Vector2.Transform(new Vector2(0, 24), Matrix.CreateRotationZ(Head.Rotation));
     LeftArm.Position  -= Vector2.Transform(new Vector2(0, 24), Matrix.CreateRotationZ(Head.Rotation));
     RightArm.Rotation -= MathHelper.ToRadians(45f);
     LeftArm.Rotation  += MathHelper.ToRadians(45f);
     if (InputManager.MouseLClicked(true))
     {
         AddBullet(Gun.Position, Gun.Rotation);
     }
     for (int i = 0; i < active; i++)
     {
         bullets[i].Update(gameTime);
     }
     health.String = "Health: " + Health.ToString();
 }