protected override void OnCancel(PlayerIndex playerIndex)
The StartGameMenuEntrySelected method causes the pause screen and an associated background screen to exit.
This step concludes the exercise. In the next exercise, you will add the game’s main screen, which both draws the game and contains its logic.
Exercise 2: Game rendering and logic
In the previous exercise we have implemented a “game” which contains little else than game state management capabilities and several basic game screens. In this exercise, we will focus on implementing the actual game by implementing the class responsible for the gameplay screen, which we will call GameplayScreen, and its supporting game classes.
Before we get going, let us review the general architecture of the gameplay screen.
GameplayScreen and Game Classes
Technically, the game’s update and drawing logic will be contained in the GameplayScreen class. However, the GameplayScreen itself will not directly handle all of the work, as some of it will be the responsibly of the relevant game classes.
Let us review some of the game classes and their intended purpose:
Player: The player class will represent one of the two players participating in the game and will be responsible for drawing its associated catapult on the screen. Two different sub-classes of the Player class will actually represent each of the players. The Human class will represent the human player and will contain additional logic for handling input and providing visual feedback, while the AI class will represent the computer player and will contain additional logic for automatically aiming and firing at the opposing human player.
Catapult: The catapult class will encapsulate all the drawing and logic related to one of the catapults in the game. The class will keep track of its associated catapult’s state and will animate it according to that state.
Projectile: This class will represent a projectile fired by one of the catapults. It will be responsible for rendering the projectile and updating its position, but not for determining whether or not the projectile has hit anything, as this will be the job of the Catapult class.
Animation: A helper class for displaying animations.
AudioManager: A helper class for playing sounds.
Page | 31