From 98ba22e7064db57316dfff1ae127feb3dceeb73e Mon Sep 17 00:00:00 2001 From: Justin Worthe Date: Thu, 31 Jul 2014 13:58:22 +0200 Subject: Initial commit --- docs/html/_bitmap_store_8cpp_source.html | 345 +++++++++++++++++++++++++++++++ 1 file changed, 345 insertions(+) create mode 100644 docs/html/_bitmap_store_8cpp_source.html (limited to 'docs/html/_bitmap_store_8cpp_source.html') diff --git a/docs/html/_bitmap_store_8cpp_source.html b/docs/html/_bitmap_store_8cpp_source.html new file mode 100644 index 0000000..0f739cf --- /dev/null +++ b/docs/html/_bitmap_store_8cpp_source.html @@ -0,0 +1,345 @@ + + + + +Rally X: source/presentation/BitmapStore.cpp Source File + + + + + + + + + + + +
+ + +
+ + + + + + + + + + + + + +
+
Rally X + +
+
ELEN3009 Project by Justin Wernick and David Schneider
+
+
+ + + + + +
+
+
source/presentation/BitmapStore.cpp
+
+
+Go to the documentation of this file.
00001 #include "BitmapStore.h"
+00002 
+00003 BitmapStore::BitmapStore(unsigned int blockWidth)
+00004     :_blockWidth(blockWidth)
+00005 {
+00006     _bitmapFont = al_load_font("junction 02.ttf", blockWidth/6, 0);
+00007     if (_bitmapFont == NULL)
+00008     {
+00009         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);
+00010         throw InstallFailure();
+00011     }
+00012 }
+00013 
+00014 BitmapStore::~BitmapStore()
+00015 {
+00016     for (map<Image,ALLEGRO_BITMAP*>::iterator iter = _bitmaps.begin();
+00017         iter != _bitmaps.end(); ++iter)
+00018     {
+00019         al_destroy_bitmap(iter->second);
+00020     }
+00021     _bitmaps.clear();
+00022     al_destroy_font(_bitmapFont);
+00023 }
+00024 
+00025 ALLEGRO_BITMAP* BitmapStore::getBitmap(Image image)
+00026 {
+00027     map<Image,ALLEGRO_BITMAP*>::const_iterator iter = _bitmaps.find(image);
+00028     if (iter != _bitmaps.end())
+00029     {
+00030         return iter->second;
+00031     }
+00032     else
+00033     {
+00034         ALLEGRO_BITMAP* newImage = al_create_bitmap(_blockWidth, _blockWidth);
+00035         switch (image)
+00036         {
+00037             case PLAYER:
+00038                 drawPlayerCar(newImage);
+00039                 break;
+00040             case ENEMY:
+00041                 drawEnemyCar(newImage);
+00042                 break;
+00043             case CHECKPOINT:
+00044                 drawCheckpoint(newImage);
+00045                 break;
+00046             case ROCK:
+00047                 drawRock(newImage);
+00048                 break;
+00049             case MAZE_WALL:
+00050                 drawMazeWall(newImage);
+00051                 break;
+00052             case MAZE_FLOOR:
+00053                 drawMazeFloor(newImage);
+00054                 break;
+00055             case SMOKE:
+00056                 drawSmoke(newImage);
+00057                 break;
+00058             case CRASHED_CAR:
+00059                 drawCrashedCar(newImage);
+00060                 break;
+00061             case CLAIMED_CHECKPOINT:
+00062                 drawClaimedCheckpoint(newImage);
+00063                 break;
+00064         }
+00065 
+00066         _bitmaps.insert(make_pair(image, newImage));
+00067         return newImage;
+00068     }
+00069 }
+00070 
+00071 void BitmapStore::drawPlayerCar(ALLEGRO_BITMAP* canvas)
+00072 {
+00073     ALLEGRO_BITMAP* prev_draw = al_get_target_bitmap();
+00074     al_set_target_bitmap(canvas);
+00075 
+00076     //car body
+00077     al_draw_filled_rounded_rectangle(_blockWidth*0.2, 0, _blockWidth*0.8, _blockWidth*0.96, _blockWidth*0.1, _blockWidth*0.1, al_map_rgb(0,0,255));
+00078 
+00079     //racing stripes
+00080     al_draw_filled_rectangle(_blockWidth*0.35, 0, _blockWidth*0.4, _blockWidth*0.3, al_map_rgb(255,255,255));
+00081     al_draw_filled_rectangle(_blockWidth*0.6, 0, _blockWidth*0.65, _blockWidth*0.3, al_map_rgb(255,255,255));
+00082 
+00083     //windscreen
+00084     al_draw_filled_rectangle(_blockWidth*0.3, _blockWidth*0.3, _blockWidth*0.7, _blockWidth*0.5, al_map_rgb (0,0,0));
+00085 
+00086     //roof
+00087     al_draw_rounded_rectangle(_blockWidth*0.3, _blockWidth*0.5, _blockWidth*0.7, _blockWidth*0.9, _blockWidth*0.04, _blockWidth*0.04, al_map_rgb (25,25, 112), _blockWidth*0.04);
+00088 
+00089     //spoiler
+00090     al_draw_filled_rectangle(_blockWidth*0.2, _blockWidth*0.96, _blockWidth*0.8, _blockWidth, al_map_rgb (0,0, 225));
+00091     al_draw_rectangle(_blockWidth*0.2, _blockWidth*0.96, _blockWidth*0.8, _blockWidth, al_map_rgb(25,25, 112),_blockWidth*0.04);
+00092 
+00093     //headlights
+00094     al_draw_filled_rectangle (_blockWidth*0.3,0,_blockWidth*0.35,_blockWidth*0.06, al_map_rgb(255,225,0));
+00095     al_draw_filled_rectangle (_blockWidth*0.65,0,_blockWidth*0.7,_blockWidth*0.06, al_map_rgb(255,225,0));
+00096 
+00097     //tyres
+00098     al_draw_filled_rounded_rectangle (_blockWidth*0.1,_blockWidth*0.13,_blockWidth*0.2,_blockWidth*0.37,_blockWidth*0.03,_blockWidth*0.03, al_map_rgb(131,139,131));
+00099     al_draw_filled_rounded_rectangle (_blockWidth*0.8,_blockWidth*0.13,_blockWidth*0.9,_blockWidth*0.37,_blockWidth*0.03,_blockWidth*0.03, al_map_rgb(131,139,131));
+00100     al_draw_filled_rounded_rectangle (_blockWidth*0.1,_blockWidth*0.63,_blockWidth*0.2,_blockWidth*0.87,_blockWidth*0.03,_blockWidth*0.03, al_map_rgb(131,139,131));
+00101     al_draw_filled_rounded_rectangle (_blockWidth*0.8,_blockWidth*0.63,_blockWidth*0.9,_blockWidth*0.87,_blockWidth*0.03,_blockWidth*0.03, al_map_rgb(131,139,131));
+00102 
+00103     al_set_target_bitmap(prev_draw);
+00104 }
+00105 void BitmapStore::drawEnemyCar(ALLEGRO_BITMAP* canvas)
+00106 {
+00107     ALLEGRO_BITMAP* prev_draw = al_get_target_bitmap();
+00108     al_set_target_bitmap(canvas);
+00109 
+00110     //car body
+00111     al_draw_filled_rounded_rectangle(_blockWidth*0.2, 0, _blockWidth*0.8, _blockWidth*0.96, _blockWidth*0.1, _blockWidth*0.1, al_map_rgb(255,0,0));
+00112 
+00113     //racing stripes
+00114     al_draw_filled_rectangle(_blockWidth*0.35, 0, _blockWidth*0.4, _blockWidth*0.3, al_map_rgb(255,255,255));
+00115     al_draw_filled_rectangle(_blockWidth*0.6, 0, _blockWidth*0.65, _blockWidth*0.3, al_map_rgb(255,255,255));
+00116 
+00117     //windscreen
+00118     al_draw_filled_rectangle(_blockWidth*0.3, _blockWidth*0.3, _blockWidth*0.7, _blockWidth*0.5, al_map_rgb (0,0,0));
+00119 
+00120     //roof
+00121     al_draw_rounded_rectangle(_blockWidth*0.3, _blockWidth*0.5, _blockWidth*0.7, _blockWidth*0.9, _blockWidth*0.04, _blockWidth*0.04, al_map_rgb (25,25, 112), _blockWidth*0.04);
+00122 
+00123     //spoiler
+00124     al_draw_filled_rectangle(_blockWidth*0.2, _blockWidth*0.96, _blockWidth*0.8, _blockWidth, al_map_rgb (0,0, 225));
+00125     al_draw_rectangle(_blockWidth*0.2, _blockWidth*0.96, _blockWidth*0.8, _blockWidth, al_map_rgb(25,25, 112),_blockWidth*0.04);
+00126 
+00127     //headlights
+00128     al_draw_filled_rectangle (_blockWidth*0.3,0,_blockWidth*0.35,_blockWidth*0.06, al_map_rgb(255,225,0));
+00129     al_draw_filled_rectangle (_blockWidth*0.65,0,_blockWidth*0.7,_blockWidth*0.06, al_map_rgb(255,225,0));
+00130 
+00131     //tyres
+00132     al_draw_filled_rounded_rectangle (_blockWidth*0.1,_blockWidth*0.13,_blockWidth*0.2,_blockWidth*0.37,_blockWidth*0.03,_blockWidth*0.03, al_map_rgb(131,139,131));
+00133     al_draw_filled_rounded_rectangle (_blockWidth*0.8,_blockWidth*0.13,_blockWidth*0.9,_blockWidth*0.37,_blockWidth*0.03,_blockWidth*0.03, al_map_rgb(131,139,131));
+00134     al_draw_filled_rounded_rectangle (_blockWidth*0.1,_blockWidth*0.63,_blockWidth*0.2,_blockWidth*0.87,_blockWidth*0.03,_blockWidth*0.03, al_map_rgb(131,139,131));
+00135     al_draw_filled_rounded_rectangle (_blockWidth*0.8,_blockWidth*0.63,_blockWidth*0.9,_blockWidth*0.87,_blockWidth*0.03,_blockWidth*0.03, al_map_rgb(131,139,131));
+00136 
+00137     al_set_target_bitmap(prev_draw);
+00138 }
+00139 void BitmapStore::drawRock(ALLEGRO_BITMAP* canvas)
+00140 {
+00141     ALLEGRO_BITMAP* prev_draw = al_get_target_bitmap();
+00142     al_set_target_bitmap(canvas);
+00143 
+00144     ALLEGRO_COLOR colour = al_map_rgb(131,139,131);
+00145     al_draw_filled_circle(_blockWidth/2, _blockWidth/2, _blockWidth/2-1, colour);
+00146 
+00147     al_draw_filled_circle(_blockWidth/2, _blockWidth/2, _blockWidth/2-6, colour);
+00148     al_draw_filled_circle(_blockWidth/4, _blockWidth/4, _blockWidth/4-1, al_map_rgb(205,197,191));
+00149     al_draw_filled_circle(_blockWidth/3.2, _blockWidth/4.2, _blockWidth/4-2, al_map_rgb(205,197,191));
+00150     al_draw_filled_circle(_blockWidth/1.2, _blockWidth/2, _blockWidth/2-15, al_map_rgb(205,197,191));
+00151     al_draw_filled_circle(_blockWidth/2, _blockWidth/2, _blockWidth/2-8, al_map_rgb(205,205,193));
+00152 
+00153     al_set_target_bitmap(prev_draw);
+00154 }
+00155 void BitmapStore::drawCheckpoint(ALLEGRO_BITMAP* canvas)
+00156 {
+00157     ALLEGRO_BITMAP* prev_draw = al_get_target_bitmap();
+00158     al_set_target_bitmap(canvas);
+00159 
+00160     ALLEGRO_COLOR colour = al_map_rgb(255,255,0);
+00161 
+00162     al_draw_filled_rectangle (_blockWidth*0.44, _blockWidth*0.1, _blockWidth*0.5, _blockWidth*0.9, colour);
+00163     al_draw_filled_rounded_rectangle (_blockWidth*0.34, _blockWidth*0.9, _blockWidth*0.6, _blockWidth*0.98, _blockWidth*0.01, _blockWidth*0.01, colour);
+00164     al_draw_filled_circle (_blockWidth*0.47, _blockWidth*0.14, _blockWidth*0.1, colour);
+00165     al_draw_filled_triangle (_blockWidth*0.44, _blockWidth*0.26, _blockWidth*0.44, _blockWidth*0.58, _blockWidth*0.8, _blockWidth*0.42, colour);
+00166 
+00167     al_set_target_bitmap(prev_draw);
+00168 }
+00169 void BitmapStore::drawMazeWall(ALLEGRO_BITMAP* canvas)
+00170 {
+00171     ALLEGRO_BITMAP* prev_draw = al_get_target_bitmap();
+00172     al_set_target_bitmap(canvas);
+00173 
+00174     ALLEGRO_COLOR colour = al_map_rgb(203,255,151);
+00175     al_clear_to_color(colour);
+00176 
+00177     al_set_target_bitmap(prev_draw);
+00178 }
+00179 void BitmapStore::drawMazeFloor(ALLEGRO_BITMAP* canvas)
+00180 {
+00181     ALLEGRO_BITMAP* prev_draw = al_get_target_bitmap();
+00182     al_set_target_bitmap(canvas);
+00183 
+00184     ALLEGRO_COLOR colour = al_map_rgb(0,0,0);
+00185     al_clear_to_color(colour);
+00186 
+00187     al_set_target_bitmap(prev_draw);
+00188 }
+00189 void BitmapStore::drawSmoke(ALLEGRO_BITMAP* canvas)
+00190 {
+00191     ALLEGRO_BITMAP* prev_draw = al_get_target_bitmap();
+00192     al_set_target_bitmap(canvas);
+00193 
+00194     ALLEGRO_COLOR colour = al_map_rgb(255,255,255);
+00195     al_draw_circle (_blockWidth/2.3, _blockWidth/2.1, _blockWidth/2-1, colour,1);
+00196     al_draw_circle (_blockWidth/4, _blockWidth/4, _blockWidth/4, colour,2);
+00197     al_draw_circle (_blockWidth/5, _blockWidth/1.5, _blockWidth/4, colour,4);
+00198     al_draw_circle (_blockWidth/2.5, _blockWidth/2.7, _blockWidth/3, colour,3);
+00199     al_draw_circle (_blockWidth/1.2, _blockWidth/1.8, _blockWidth/3.7, colour,2);
+00200     al_draw_circle (_blockWidth/2.8, _blockWidth/2.2, _blockWidth/6, colour,3);
+00201     al_draw_circle (_blockWidth/1.1, _blockWidth/1.2, _blockWidth/3, colour,2);
+00202     al_draw_circle (_blockWidth/1.2, _blockWidth/1.7, _blockWidth/2, colour,3);
+00203     al_draw_circle (_blockWidth/1.3, _blockWidth/1.3, _blockWidth/5, colour,2);
+00204 
+00205     al_set_target_bitmap(prev_draw);
+00206 }
+00207 
+00208 void BitmapStore::drawCrashedCar(ALLEGRO_BITMAP* canvas)
+00209 {
+00210     ALLEGRO_BITMAP* prev_draw = al_get_target_bitmap();
+00211     al_set_target_bitmap(canvas);
+00212 
+00213     al_draw_filled_rounded_rectangle(_blockWidth/3.33, _blockWidth/5, _blockWidth/1.25, _blockWidth/1.04, 5, 5, al_map_rgb (200, 200, 200));
+00214     al_draw_circle (_blockWidth/2.3, _blockWidth/2.1, _blockWidth/2-1, al_map_rgb (255, 0, 0),1);
+00215     al_draw_circle (_blockWidth/4, _blockWidth/4, _blockWidth/4, al_map_rgb (100, 100, 100),2);
+00216     al_draw_circle (_blockWidth/5, _blockWidth/1.5, _blockWidth/4, al_map_rgb (255, 0, 0),4);
+00217     al_draw_filled_rectangle(_blockWidth/2.5, _blockWidth/2, _blockWidth/1.43, _blockWidth/1.7, al_map_rgb (0,0, 0));
+00218     al_draw_circle (_blockWidth/2.5, _blockWidth/2.7, _blockWidth/3, al_map_rgb (100, 100, 100),3);
+00219     al_draw_circle (_blockWidth/1.2, _blockWidth/1.8, _blockWidth/3.7, al_map_rgb (255, 0, 0),2);
+00220     al_draw_rectangle(_blockWidth/3.13, _blockWidth/1.04, _blockWidth/1.25, _blockWidth, al_map_rgb (25,25, 112),1);
+00221     al_draw_circle (_blockWidth/2.8, _blockWidth/2.2, _blockWidth/6, al_map_rgb (255, 0, 0),3);
+00222     al_draw_circle (_blockWidth/1.1, _blockWidth/1.2, _blockWidth/3, al_map_rgb (100, 100, 100),2);
+00223     al_draw_circle (_blockWidth/1.2, _blockWidth/1.7, _blockWidth/2, al_map_rgb (100, 100, 100),3);
+00224     al_draw_circle (_blockWidth/1.3, _blockWidth/1.3, _blockWidth/5, al_map_rgb (255, 0, 0),2);
+00225 
+00226     al_set_target_bitmap(prev_draw);
+00227 }
+00228 
+00229 void BitmapStore::drawClaimedCheckpoint(ALLEGRO_BITMAP* canvas)
+00230 {
+00231     ALLEGRO_BITMAP* prev_draw = al_get_target_bitmap();
+00232     al_set_target_bitmap(canvas);
+00233 
+00234     ALLEGRO_COLOR colour = al_map_rgb(255,255,255);
+00235     al_draw_text(_bitmapFont, colour, _blockWidth/2, _blockWidth/2, ALLEGRO_ALIGN_CENTRE , "GOTCHA");
+00236 
+00237     al_set_target_bitmap(prev_draw);
+00238 }
+
+
+ +
+ All Classes Files Functions Variables Typedefs Enumerations Enumerator
+ + +
+ +
+ + + + + + + -- cgit v1.2.3