public void Kill() { PlayerStatus.RemoveLife(); framesUntilRespawn = PlayerStatus.IsGameOver ? 300 : 120; }
/// <summary> /// The update loop for the player ship /// </summary> public override void Update() { // Check to see if the ship is dead if (IsDead) { // Wait until the ship can respawn if (--framesUntilRespawn == 0) { // Check to see if the player has no more lives if (PlayerStatus.Lives <= 0) { // Reset all game information and go back to the main menu EntityManager.Reset(); PlayerStatus.Reset(); GameBase.State = GameBase.GameState.MainMenu; } } // End the update loop return; } // NOTE: With regards to the firing, the maximum number of alloted shots on the screen is less than 10. // In this kind of game, I personally find it incredibly tedious to have to worry about when to fire and // a maximum carrying capacity of shots. Though it could be implemented easily, I prefer having an automatic // stream of bullets in this kind of game // Set the bullet aim direction as going directly up for the classic game mode Vector2 aim = new Vector2(0, -1); // Check to see if the player is in the free game mode if (GameBase.State == GameBase.GameState.FreeGameplay) { // Set the aim as the mouse direction aim = HandleInput.GetMouseAimDirection(); } // If there is no more cooldown and there is a position to aim in if (aim.LengthSquared() > 0 && cooldowmRemaining <= 0) { // Reset the cooldown cooldowmRemaining = cooldownFrames; // Get the aim angle float aimAngle = aim.ToAngle(); Quaternion aimQuat = Quaternion.CreateFromYawPitchRoll(0, 0, aimAngle); // Define the bullet velocity Vector2 vel = 8f * new Vector2((float)Math.Cos(aimAngle), (float)Math.Sin(aimAngle)); // Define the bullet offset Vector2 offset = Vector2.Transform(new Vector2(40, -8), aimQuat); // Add the bullet to the entity manager EntityManager.Add(new Bullet(Position + offset, vel)); // Player a shot sound effect Sound.Shot.Play(0.2f, rand.NextFloat(-0.2f, 0.2f), 0); } // If there is a cooldown remaining, continue to wait if (cooldowmRemaining > 0) { cooldowmRemaining--; } // Set the speed in pixels for the bullet const float speed = 8; // Set the velocity of the bullet as the speed times the movement direction Velocity += speed * HandleInput.GetMovementDirection(); // Increase the position by the velocity and clamp it to the game window Position += Velocity; Position = Vector2.Clamp(Position, Size / 2, GameBase.ScreenSize - Size / 2); // Set the bullet orientation if (Velocity.LengthSquared() > 0) { Orientation = Velocity.ToAngle(); } // Generate the ship exhaust fire upon movement and reset the velocity MakeExhaustFire(); Velocity = Vector2.Zero; }