/// <summary> /// Updates the <c>Player</c>. /// </summary> /// <param name="gameTime"></param> public void Update(GameTime gameTime) { float dt = (float)gameTime.ElapsedGameTime.TotalMilliseconds; invulnTimer -= dt; rocketTimer -= dt; InputManager im = InputManager.Instance; Vector2 velocity = GamePad.GetState(index).ThumbSticks.Left; velocity.Y *= -1; if (ScreenManager.DEV_MODE) { if (im.KeyDown(Keys.W)) { velocity.Y = -1; } else if (im.KeyDown(Keys.S)) { velocity.Y = 1; } if (im.KeyDown(Keys.A)) { velocity.X = -1; } else if (im.KeyDown(Keys.D)) { velocity.X = 1; } } if (ScreenManager.DEV_MODE && velocity.Length() != 0) { velocity.Normalize(); } bulletTimer += dt; shieldTimer -= dt; shieldRechargeTimer -= dt; Velocity = velocity; Velocity *= SPEED; if (invulnTimer <= 0) { CheckBulletCollision(); } else { float vMag = Math.Max(0, (invulnTimer - INVULNERABILITY_TIMESTAMP / 2) / INVULNERABILITY_TIMESTAMP); GamePad.SetVibration(index, vMag, vMag); } if (shieldTimer < 0f && shieldRechargeTimer <= 0 && im.IsButtonDown(Buttons.A, (int)index) || (ScreenManager.DEV_MODE && im.KeyPressed(Keys.Q))) { shieldTimer = 3000f; shieldRechargeTimer = shieldTimer * 2f; } // Shoots bullets if (bulletTimer > 450f && (im.IsButtonDown(Buttons.RightTrigger, (int)index) || (ScreenManager.DEV_MODE && im.KeyDown(Keys.Space)))) { //int shootFx = rand.Next(0, 3); shootSound.Play(1f, 0f, 0f); bulletTimer = 0; SinBullet b = new SinBullet(EntitySide.PLAYER, 7000f, 800, true, true); SinBullet b2 = new SinBullet(EntitySide.PLAYER, 7000f, 800, true, false); LinearBullet b3 = new LinearBullet(EntitySide.PLAYER, 7000f, new Vector2(0, -800)); Vector2 offsetVel = Velocity / 4f; b.Texture = BulletTexture; b.Size = new Point(8, 7); b.Position = Position; b.InitVelocity = offsetVel; b.Color = Color.SkyBlue; b2.Texture = BulletTexture; b2.Size = new Point(8, 7); b2.InitVelocity = offsetVel; b2.Position = Position; b2.Color = Color.SkyBlue; b3.Texture = BulletTexture; b3.InitVelocity = offsetVel; b3.Size = new Point(8, 8); b3.Position = Position; b3.Color = Color.SkyBlue; bullets.Add(b); bullets.Add(b2); bullets.Add(b3); } ; // Fire rocket if (im.IsButtonDown(Buttons.LeftTrigger, (int)index) && rocketTimer < 0) { rocketTimer = 900f; List <Sprite> sprites = new List <Sprite>(); sprites.AddRange(GameScreen.CurrentStage.Enemies); Rocket r = new Rocket(sprites, blank, rocketLaunch, rocketImpact) { Texture = RocketTexture, Explosion = Explosion, Color = Color.White, Position = Position, Size = new Point(RocketTexture.Width, RocketTexture.Height), }; CurrentStage.AddRocket(r); } // inverts the y-axis to be NOT INVERTED if (Velocity.Length() > 0) { Rotation = (float)Math.Atan2(velocity.Y, velocity.X); } UpdatePosition(gameTime); }