summaryrefslogtreecommitdiff
path: root/source/presentation/GamePanel.h
diff options
context:
space:
mode:
Diffstat (limited to 'source/presentation/GamePanel.h')
-rw-r--r--source/presentation/GamePanel.h117
1 files changed, 117 insertions, 0 deletions
diff --git a/source/presentation/GamePanel.h b/source/presentation/GamePanel.h
new file mode 100644
index 0000000..916ac13
--- /dev/null
+++ b/source/presentation/GamePanel.h
@@ -0,0 +1,117 @@
+#ifndef GAMEPANEL_H
+#define GAMEPANEL_H
+
+#include "../presentation/ScreenPanel.h"
+#include "../logic/Maze.h"
+#include "../logic/GameObject.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"
+
+/**
+* @brief ScreenPanel to be drawn on the screen to draw the area where the game takes place.
+*
+* This includes the scrolling maze and all of the GameObjects.
+*
+* @author Justin Wernick
+* @author David Schneider
+*/
+class GamePanel : public ScreenPanel
+{
+ public:
+ /**
+ * @brief Creates a GamePanel from the given back and front buffers.
+ *
+ * The sub-bitmaps that GamePanel uses are created from a rectangular region on back and front
+ * that has its top left corner at the coordinate x,y, is width long in the x direction, and
+ * height long in the y direction.
+ *
+ * @param [in] back The current back buffer of the display being sub-bitmapped.
+ * @param [in] front The current front buffer (image currently being displayed) of the display being sub-bitmapped.
+ * @param [in] x The x coordinate of the left side of the sub-bitmap in pixels.
+ * @param [in] y The x coordinate of the top of the sub-bitmap in pixels.
+ * @param [in] width The length in the x direction of the new sub-bitmap in pixels.
+ * @param [in] height The length in the y direction of the new sub-bitmap in pixels.
+ */
+ GamePanel(ALLEGRO_BITMAP* back, ALLEGRO_BITMAP* front, int x, int y, int width, int height);
+
+
+ /**
+ * @brief Draws the given objects on the screen.
+ *
+ * The drawing is offset so that the first entry in players is in the middle of the panel.
+ * However, the offset will never be such that the drawing area will be outside of the maze.
+ *
+ * @param [in] maze The Maze that all of the objects are in.
+ * @param [in] players The list of PlayerCars to be drawn.
+ * @param [in] enemies The list of EnemyCars to be drawn.
+ * @param [in] checkpoints The list of Checkpoints to be drawn.
+ * @param [in] rocks The list of Rocks to be drawn.
+ * @param [in] smokescreens The list of Smokescreens to be drawn.
+ * @param [in] popups The list of DestroyedObjectPopups to be drawn.
+ */
+ virtual void draw(const Maze& maze, const list<PlayerCar>& players, const list<EnemyCar>& enemies, const list<Checkpoint>& checkpoints, const list<Rock>& rocks, const list<Smokescreen>& smokescreens, const list<DestroyedObjectPopup>& popups);
+ private:
+ /**
+ * @brief Copy constructor not implemented, ScreenPanels should not be copied.
+ */
+ GamePanel(const GamePanel& ref);
+ /**
+ * @brief Assignment operator not implemented, ScreenPanels should not be copied.
+ */
+ GamePanel& operator=(const GamePanel& rhs);
+ /**
+ * @brief Converts an x game coordinate value to its equivalent in pixels.
+ *
+ * Converting to the pixel coordinates happens for every object every frame. To increase
+ * performance, the parameters are passed in by constant reference instead of by value.
+ *
+ * @param [in] x The game coordinate to be converted into pixels.
+ */
+ float getPanelX(const double& x) const;
+ /**
+ * @brief Converts a y game coordinate value to its equivalent in pixels.
+ *
+ * Converting to the pixel coordinates happens for every object every frame. To increase
+ * performance, the parameters are passed in by constant reference instead of by value.
+ *
+ * @param [in] y The game coordinate to be converted into pixels.
+ */
+ float getPanelY(const double& y) const;
+
+ /**
+ * @brief Draws a Maze on the screen.
+ *
+ * Bitmaps used to represent solid and non-solid parts of the Maze are stored in the
+ * BitmapStore.
+ *
+ * @param [in] maze The Maze to be drawn.
+ */
+ void draw(const Maze& maze);
+
+ /**
+ * @brief Draws a single GameObject on the screen.
+ *
+ * The bitmap to be drawn is retrieved from the BitmapStore using the GameObject's image.
+ *
+ * @param [in] object The GameObject to be drawn.
+ */
+ void draw(const GameObject& object);
+
+ const static int BLOCKS_PER_ROW = 15; ///< The number of Maze blocks in one row shown on the panel at a time. Used to determine the scale.
+
+ unsigned int _mazeblockWidth; ///< The width of one (square) Maze block on the screen, in pixels.
+
+ float _offsetX; ///< The amount that drawing should be offset to the right, recalculated every frame.
+ float _offsetY; ///< The amount that drawing should be offset downwards, recalculated every frame.
+
+ BitmapStore _bitmapStore; ///< Used to cache ALLEGRO_BITMAPs, so that they only need to be drawn once.
+
+ AllegroInit _allegro; ///< Handles dependencies on Allegro.
+};
+
+#endif // GAMEPANEL_H