Rally X
ELEN3009 Project by Justin Wernick and David Schneider
source/presentation/InfoPanel.cpp
Go to the documentation of this file.
00001 #include "InfoPanel.h"
00002 
00003 InfoPanel::InfoPanel(ALLEGRO_BITMAP* back, ALLEGRO_BITMAP* front, int x, int y, int width, int height)
00004     :ScreenPanel(back, front, x, y, width, height),
00005     _petrolHeadingY(_width/10),
00006     _petrolGuageY(_petrolHeadingY + _width/10),
00007     _petrolGuageHeight(_width/10),
00008     _checkpointHeadingY(_petrolGuageY + _petrolGuageHeight + _width/10),
00009     _checkpointValueY(_checkpointHeadingY + _width/10),
00010     _miniMazeY(_checkpointValueY + _width/5),
00011     _miniMazeHeight(_height - _miniMazeY),
00012     _miniMazeblockWidth(0)
00013 {
00014     _panelFont = al_load_font("junction 02.ttf", _width/10, 0);
00015     if (_panelFont == NULL)
00016     {
00017         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);
00018         throw InstallFailure();
00019     }
00020 }
00021 
00022 InfoPanel::~InfoPanel()
00023 {
00024     al_destroy_font(_panelFont);
00025 }
00026 
00027 void InfoPanel::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)
00028 {
00029     ALLEGRO_BITMAP* prev_draw = al_get_target_bitmap();
00030     al_set_target_bitmap(_back);
00031 
00032     double petrol = 0;
00033     if (!players.empty())
00034     {
00035         petrol = players.front().petrol();
00036     }
00037 
00038     al_clear_to_color(_colourStore.getColour(BitmapStore::MAZE_FLOOR));
00039 
00040     //gets a mazeblock width the fits the current maze
00041     _miniMazeblockWidth = min(static_cast<float>(_width)/maze.width(), static_cast<float>(_miniMazeHeight)/maze.height());
00042 
00043     //draws petrol heading and bar
00044     al_draw_text(_panelFont, al_map_rgb(255,255,255), 1, _petrolHeadingY, ALLEGRO_ALIGN_LEFT , "Petrol");
00045     al_draw_filled_rectangle(0,_petrolGuageY,_width*petrol, _petrolGuageY+_petrolGuageHeight, al_map_rgb(255,128,0));
00046 
00047     //draws checkpoints remaining heading and value
00048     al_draw_text(_panelFont, al_map_rgb(255,255,255), 1, _checkpointHeadingY, ALLEGRO_ALIGN_LEFT , "Checkpoints");
00049     stringstream checkpointCountString;
00050     checkpointCountString << Checkpoint::checkpointCount();
00051     al_draw_text(_panelFont, al_map_rgb(255,255,255), 1, _checkpointValueY, ALLEGRO_ALIGN_LEFT , checkpointCountString.str().c_str());
00052 
00053     draw(maze);
00054     for (list<PlayerCar>::const_iterator iter = players.begin(); iter != players.end(); ++iter)
00055     {
00056         draw(*iter);
00057     }
00058     for (list<EnemyCar>::const_iterator iter = enemies.begin(); iter != enemies.end(); ++iter)
00059     {
00060         draw(*iter);
00061     }
00062     for (list<Checkpoint>::const_iterator iter = checkpoints.begin(); iter != checkpoints.end(); ++iter)
00063     {
00064         draw(*iter);
00065     }
00066 
00067     //restore draw target
00068     al_set_target_bitmap(prev_draw);
00069 }
00070 
00071 void InfoPanel::draw(const Maze& maze)
00072 {
00073     ALLEGRO_COLOR wallColour = _colourStore.getColour(BitmapStore::MAZE_WALL);
00074     ALLEGRO_COLOR floorColour = _colourStore.getColour(BitmapStore::MAZE_FLOOR);
00075 
00076     for (int x=0; x<maze.width(); ++x)
00077     {
00078         for (int y=0; y<maze.height(); ++y)
00079         {
00080             float x1 = getPanelX(x);
00081             float x2 = x1 + _miniMazeblockWidth;
00082             float y1 = getPanelY(y) + _miniMazeY;
00083             float y2 = y1 + _miniMazeblockWidth;
00084             if (maze.getSolid(x,y))
00085             {
00086                 al_draw_filled_rectangle(x1, y1, x2, y2, wallColour);
00087             }
00088             else
00089             {
00090                 al_draw_filled_rectangle(x1, y1, x2, y2, floorColour);
00091             }
00092         }
00093     }
00094 }
00095 
00096 void InfoPanel::draw(const GameObject& object)
00097 {
00098     float r = _miniMazeblockWidth/2;
00099     float cx = getPanelX(object.x()) + r;
00100     float cy = getPanelY(object.y()) + _miniMazeY + r;
00101     al_draw_filled_circle(cx, cy, r, _colourStore.getColour(object.image()));
00102 }
00103 
00104 float InfoPanel::getPanelX(const double& x) const
00105 {
00106     return static_cast<float>(x*_miniMazeblockWidth);
00107 }
00108 float InfoPanel::getPanelY(const double& y) const
00109 {
00110     return static_cast<float>(y*_miniMazeblockWidth);
00111 }
 All Classes Files Functions Variables Typedefs Enumerations Enumerator