summaryrefslogtreecommitdiff
path: root/source/logic/Game.h
diff options
context:
space:
mode:
Diffstat (limited to 'source/logic/Game.h')
-rw-r--r--source/logic/Game.h135
1 files changed, 135 insertions, 0 deletions
diff --git a/source/logic/Game.h b/source/logic/Game.h
new file mode 100644
index 0000000..9adff76
--- /dev/null
+++ b/source/logic/Game.h
@@ -0,0 +1,135 @@
+#ifndef GAME_H
+#define GAME_H
+
+#include <list>
+#include <algorithm>
+using namespace std;
+
+#include <allegro5/allegro.h>
+
+#include "../presentation/Screen.h"
+#include "../presentation/BitmapStore.h"
+
+#include "../logic/Maze.h"
+#include "../logic/PlayerCar.h"
+#include "../logic/EnemyCar.h"
+#include "../logic/Checkpoint.h"
+#include "../logic/Rock.h"
+#include "../logic/Smokescreen.h"
+#include "../logic/DestroyedObjectPopup.h"
+#include "../logic/AllegroWrappers.h"
+#include "../logic/CollisionDetector.h"
+
+#include "../data/LevelReader.h"
+#include "../data/Config.h"
+
+/**
+* @brief The object that controls the flow of the game, and the launch point of the game.
+*
+* Game contains the various components, including the screen, the maze, and all of the
+* objects in the maze. The timing of the gameloop also falls under Game's control.
+* Essencially, Game is the central point that everything connects to.
+*
+* @author Justin Wernick
+* @author David Schneider
+*/
+class Game
+{
+ public:
+ static const unsigned int FPS = 30; ///< Frames per second, the number of times the gameloop is run every second.
+
+ /**
+ * @brief Constructor, that creates the relevant Allegro entities.
+ */
+ Game();
+
+ /**
+ * @brief Constructor, that destroys the relevant Allegro entities.
+ */
+ ~Game();
+
+ /**
+ * @brief Entry point for the program. This should be called from main.
+ */
+ void start();
+
+ private:
+ /**
+ * @brief Unimplemented copy constructor, prevents copying of Game objects.
+ *
+ * Copying a Game is unneccesary as there should only be a single Game object.
+ */
+ Game(const Game& ref);
+ /**
+ * @brief Unimplemented assignment operator.
+ *
+ * @see Game::Game(const Game& ref)
+ */
+ Game& operator=(const Game& rhs);
+
+ /**
+ * @brief Initialises all of the GameObject lists using a file.
+ *
+ * @param [in] levelFile The path of the file that contains the level layout.
+ */
+ void initLevel(const string& levelFile);
+
+ /**
+ * @brief Main part of the game, performs the actions in each frame FPS times per second until the game is over.
+ *
+ * Each frame runs the update methods of each of the GameObjects in the lists. The CollisionDetector
+ * then checks for collisions between objects. Any GameObjects that have been destroyed are then removed
+ * from their lists. Finally, the Screen is called to draw all of the GameObjects that still exist in
+ * their new positions.
+ *
+ * Before the next iteration begins, a check is done for the victory and loss conditions. The loop is
+ * ended if either of these are met, or if the player has quit the game.
+ */
+ void runloop();
+
+ /**
+ * @brief Calls the update method on each of the GameObjects in the game.
+ */
+ void update();
+ /**
+ * @brief Removes any GameObjects that have been destroyed from their lists.
+ */
+ void cleanup();
+
+ /**
+ * @brief Destroys all GameObjects in the game, resetting the lists for a new level to be loaded.
+ *
+ * This should always be called before a new level is loaded.
+ */
+ void clearLists();
+
+ AllegroInit _allegro; ///< Handles dependencies on Allegro being installed.
+
+ Config _config; ///< Loads configuration from file on construction, used to set resolution of screen.
+ Screen _screen; ///< Handles all drawing operations.
+ ALLEGRO_TIMER* _timer; ///< Creates FPS events per second, that are put into _timerEvents.
+ ALLEGRO_EVENT_QUEUE* _timerEvents; ///< Catches events from _timer, used to regulate speed of runloop.
+
+ Maze _maze; ///< The environment that confines the movements of GameObjects, specifically Cars.
+ /**
+ * @brief Typically a single PlayerCar, controlled by the person playing the game.
+ *
+ * A list was used for _players to allow the Game object to be constructed without needing to initialise
+ * a meaningless PlayerCar object. This also allows the PlayerCar to be destroyed by Rocks or EnemyCars.
+ * An added benefit is that it adds the ease of extending the game to allow multiple players. To add
+ * multiplayer, the KeyboardHandler would need to be modified to allow different sets of input keys,
+ * and the Screen would need to be modified to keep all players visible, but the Game class would be
+ * able to remain largely unchanged.
+ */
+ list<PlayerCar> _players;
+
+ list<EnemyCar> _enemies; ///< List of all EnemyCars chasing the player.
+ list<Checkpoint> _checkpoints; ///< List of checkpoints that the player needs to collect.
+ list<Rock> _rocks; ///< List of rocks that the player and EnemyCars need to avoid.
+ list<Smokescreen> _smokescreens; ///< List of Smokescreen objects that are currently able to delay EnemyCars.
+ list<DestroyedObjectPopup> _popups; ///< List of purely visual DestroyedObjectPopups that need to be drawn.
+
+ CollisionDetector _collisionDetector; ///< Object that checks for collisions each frame.
+};
+
+#endif // GAME_H