The game currently includes the following data structures:
- A collection of game squares. Each square has a number of properties describing its current state – isPath, isHighlighted, isSelected, Position, hasTurret and RotationAngle.
- A collection of Enemies – Position, Health and Pathsection.
- A collection of Enemy Paths – PathSection and PathEnd.
- GameState – a class containing the collections above, the list of textures and game logic functions.
isPath – A boolean property determines if the game square is a part of the path. During the draw cycle, if isPath is set to false, a bitmap is used to draw the square, otherwise it is left blank.
hasTurret – As stated above, a bitmap is associated with the game square if it is not a path. hasTurret is a boolean variable, and indicates the user has selected a gun turret to be placed on the square. A turret bitmap is drawn on the square if true.
isHighlighted/isSelected – if the user touches a square with their finger, the square’s isHighlighted flag is set. This square is then drawn with the red bitmap. If the user touches the square again, the square isSelected, and it is assumed a gun turret is being placed on that square. At a later stage, I’ll be changing this logic to include a purchase turret button.
Position – Position is used in a number of structures to determine where the object should be drawn. Position is represented as a Vector2D structure – an XNA data type which holds two float values, x and y.
RotationAngle – Static turrets don’t look very convincing. As the enemies pass the turrets, they should swing round to face them. The spriteBatch.Draw XNA method provides an overload which allows the drawn image to be rotated. I’ll talk about this in a later post.
Health – determines the state of an enemy. Will start at 100, and decrease as shots from the turret hit the enemy. As the enemies are enhanced, it will be possible for them to have more health points. At this stage, I’m looking at a simple prototype.
PathSection – This is used in two places, enemypath and enemy. The enemypath structure has an integer pathsection, and a vector2D pathend. The purpose of these two values is to provide a sequence for the enemies to follow. On each draw cycle, the enemy’s path section will be checked. Initially this will be set to 1. In the enemypath structure, the coordinates of the first turn in the path will be associated with the pathsection of 1. The coordinates of the path end and the enemy’s position are compared, and the enemy’s x or y position coordinates will be decremented/incremented as appropriate. There will be no diagonal movement (x and y changing together) as the path is drawn across the x and y axes. When the enemy’s position is identical to the path’s end coordinates, the enemy’s pathsection is incremented. On our test level there are 4 path sections representing each turn in the path.
Gamestate – This class keeps track of the game logic, and creates instances of the required objects. This class, and some of the underlying data structures, are coupled to the XNA framework through the passing of XNA specific types. Functions such as Draw require SpriteBatch objects, and some of the position variables are stored as Vector2D. At a later point, I’ll try to loosen this up a bit. If this game is to port to other platforms, the XNA specific code will have to be replaced. Using a layered strategy, like in MVC would be a sensible option, separating the code logic from the platform implementation.