Ok, so before going any further, I think I better prepare some entities to contain and track the data during the game.
Usually I would not put any logic in such entities, using an external class to handle it, but in this case I wanna try a different approach, inserting the logic of each entity inside the class it self.
I said usually I would not do it, because in my experience an entity always need its context to perform even the most basic operation, but in this game it has revelead a good approach.
The Level class
This class will store the data regarding the current level of the game, such as the tile map.
The initialisation will load the tilemap and the bitmaps needed to draw the level backround:
– The tilemap is a 18×34 matrix of integer, each cell referring to a particular tile type, and it’s loaded from a properties file stored in the assets folder
– There are around 20 different tiles, this class will store each bitmap in an array
– Additional bitmaps are the prize disappearing animation and the “hole in the ground”animation
The drawing method will render the current level, based on the current camera position.
The GameCharacter class
This class keeps each chracter information, such as position, status and style.
The initialisation method will load the character animations set (i.e. stop, running, climbing and so on), and cache the bitmaps.
The drawing method will render the player on the screen at its current position. For enemies outside the screen, an arrow will be rendered to inform the user about the enemy position.
The Player and Enemy classes
This classes simply extend the Game Character class, without any logic or information except for indicating the character as a player (overriding the method isPlayer())
The Score class
This class stores the current game score and lives count, and also calculate when the player gains a life at certain level caps.
The initialisation loads and keeps in memory the Bitmap used to draw the score.
The drawing method renders the score on the game Canvas, at the bottom of the screen.
Now I’m ready to fill up these entities and draw something on the screen, in next posts I will post portion of the source code for each of these classes.