Page 3 of 4
Game Logic
The "game logic" is really the essence of the game; it creates the player character, the enemies, the environment, the user interface, everything! The game logic code uses the game engine code to achieve its goals (by expressing the game through graphics, sound, and input). Contained within the game.cpp file is the CGame class code. It handles all of the "game screen" input, and ensures that this input is appropriately passed to the player's game entity. (The code for the player and enemy entities will be explained below.) CGame ensures that all game entities are given a chance to "Update" each frame, by calling the CEntity::UpdateAll() method.
Additionally, the CGame class handles a number of housekeeping tasks, such as pausing the game if the escape key is pressed, updating the game timer that tracks how long the player has taken on the level, and checking for victory and failure conditions.
The terrain and the collectable tokens are coded in the entityTerrainGlue.cpp, entityTerrainGrass.cpp, and entityToken.cpp files. These entities are fairly simple, and are primarily responsible for loading the appropriate sprites to give themselves a graphical expression on-screen. The CEntityToken class also contains some logic to handle the "mouse-click collecting" game mechanic: It detects clicks, and responds to them by moving the token towards the player. The CEntityToken class also checks for collisions with the terrain, as tokens will stop moving towards the player when they collide with terrain entities.
Each time a frame is processed, CGame calls CEntity::UpdateAll() to allow all of the entities to run their respective "Update" methods and handle their sprites and collision detection and movement (if necessary). CGame then checks for keyboard input and passes it to the CEntityPlayer object in the form of Run, Jump, and Drop method calls. Additionally, CGame passes mouse click data to the CEntityToken class so that the various CEntityToken objects can respond properly if they have been clicked. It is in this way that CGame facilitates the update and display of the game state, including the player, enemy, token, and terrain objects.
|
||||||



