From 98ba22e7064db57316dfff1ae127feb3dceeb73e Mon Sep 17 00:00:00 2001 From: Justin Worthe Date: Thu, 31 Jul 2014 13:58:22 +0200 Subject: Initial commit --- source/presentation/InfoPanel.cpp | 111 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 111 insertions(+) create mode 100644 source/presentation/InfoPanel.cpp (limited to 'source/presentation/InfoPanel.cpp') diff --git a/source/presentation/InfoPanel.cpp b/source/presentation/InfoPanel.cpp new file mode 100644 index 0000000..b4d33fa --- /dev/null +++ b/source/presentation/InfoPanel.cpp @@ -0,0 +1,111 @@ +#include "InfoPanel.h" + +InfoPanel::InfoPanel(ALLEGRO_BITMAP* back, ALLEGRO_BITMAP* front, int x, int y, int width, int height) + :ScreenPanel(back, front, x, y, width, height), + _petrolHeadingY(_width/10), + _petrolGuageY(_petrolHeadingY + _width/10), + _petrolGuageHeight(_width/10), + _checkpointHeadingY(_petrolGuageY + _petrolGuageHeight + _width/10), + _checkpointValueY(_checkpointHeadingY + _width/10), + _miniMazeY(_checkpointValueY + _width/5), + _miniMazeHeight(_height - _miniMazeY), + _miniMazeblockWidth(0) +{ + _panelFont = al_load_font("junction 02.ttf", _width/10, 0); + if (_panelFont == NULL) + { + al_show_native_message_box(NULL, "Fatal error", "Fatal error", "The file 'junction 02.ttf' was not found. Ensure that it is located in the working directory.", NULL, ALLEGRO_MESSAGEBOX_ERROR); + throw InstallFailure(); + } +} + +InfoPanel::~InfoPanel() +{ + al_destroy_font(_panelFont); +} + +void InfoPanel::draw(const Maze& maze, const list& players, const list& enemies, const list& checkpoints, const list& rocks, const list& smokescreens, const list& popups) +{ + ALLEGRO_BITMAP* prev_draw = al_get_target_bitmap(); + al_set_target_bitmap(_back); + + double petrol = 0; + if (!players.empty()) + { + petrol = players.front().petrol(); + } + + al_clear_to_color(_colourStore.getColour(BitmapStore::MAZE_FLOOR)); + + //gets a mazeblock width the fits the current maze + _miniMazeblockWidth = min(static_cast(_width)/maze.width(), static_cast(_miniMazeHeight)/maze.height()); + + //draws petrol heading and bar + al_draw_text(_panelFont, al_map_rgb(255,255,255), 1, _petrolHeadingY, ALLEGRO_ALIGN_LEFT , "Petrol"); + al_draw_filled_rectangle(0,_petrolGuageY,_width*petrol, _petrolGuageY+_petrolGuageHeight, al_map_rgb(255,128,0)); + + //draws checkpoints remaining heading and value + al_draw_text(_panelFont, al_map_rgb(255,255,255), 1, _checkpointHeadingY, ALLEGRO_ALIGN_LEFT , "Checkpoints"); + stringstream checkpointCountString; + checkpointCountString << Checkpoint::checkpointCount(); + al_draw_text(_panelFont, al_map_rgb(255,255,255), 1, _checkpointValueY, ALLEGRO_ALIGN_LEFT , checkpointCountString.str().c_str()); + + draw(maze); + for (list::const_iterator iter = players.begin(); iter != players.end(); ++iter) + { + draw(*iter); + } + for (list::const_iterator iter = enemies.begin(); iter != enemies.end(); ++iter) + { + draw(*iter); + } + for (list::const_iterator iter = checkpoints.begin(); iter != checkpoints.end(); ++iter) + { + draw(*iter); + } + + //restore draw target + al_set_target_bitmap(prev_draw); +} + +void InfoPanel::draw(const Maze& maze) +{ + ALLEGRO_COLOR wallColour = _colourStore.getColour(BitmapStore::MAZE_WALL); + ALLEGRO_COLOR floorColour = _colourStore.getColour(BitmapStore::MAZE_FLOOR); + + for (int x=0; x(x*_miniMazeblockWidth); +} +float InfoPanel::getPanelY(const double& y) const +{ + return static_cast(y*_miniMazeblockWidth); +} -- cgit v1.2.3