summaryrefslogtreecommitdiff
path: root/source/presentation/BitmapStore.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'source/presentation/BitmapStore.cpp')
-rw-r--r--source/presentation/BitmapStore.cpp238
1 files changed, 238 insertions, 0 deletions
diff --git a/source/presentation/BitmapStore.cpp b/source/presentation/BitmapStore.cpp
new file mode 100644
index 0000000..c289ff3
--- /dev/null
+++ b/source/presentation/BitmapStore.cpp
@@ -0,0 +1,238 @@
+#include "BitmapStore.h"
+
+BitmapStore::BitmapStore(unsigned int blockWidth)
+ :_blockWidth(blockWidth)
+{
+ _bitmapFont = al_load_font("junction 02.ttf", blockWidth/6, 0);
+ if (_bitmapFont == 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();
+ }
+}
+
+BitmapStore::~BitmapStore()
+{
+ for (map<Image,ALLEGRO_BITMAP*>::iterator iter = _bitmaps.begin();
+ iter != _bitmaps.end(); ++iter)
+ {
+ al_destroy_bitmap(iter->second);
+ }
+ _bitmaps.clear();
+ al_destroy_font(_bitmapFont);
+}
+
+ALLEGRO_BITMAP* BitmapStore::getBitmap(Image image)
+{
+ map<Image,ALLEGRO_BITMAP*>::const_iterator iter = _bitmaps.find(image);
+ if (iter != _bitmaps.end())
+ {
+ return iter->second;
+ }
+ else
+ {
+ ALLEGRO_BITMAP* newImage = al_create_bitmap(_blockWidth, _blockWidth);
+ switch (image)
+ {
+ case PLAYER:
+ drawPlayerCar(newImage);
+ break;
+ case ENEMY:
+ drawEnemyCar(newImage);
+ break;
+ case CHECKPOINT:
+ drawCheckpoint(newImage);
+ break;
+ case ROCK:
+ drawRock(newImage);
+ break;
+ case MAZE_WALL:
+ drawMazeWall(newImage);
+ break;
+ case MAZE_FLOOR:
+ drawMazeFloor(newImage);
+ break;
+ case SMOKE:
+ drawSmoke(newImage);
+ break;
+ case CRASHED_CAR:
+ drawCrashedCar(newImage);
+ break;
+ case CLAIMED_CHECKPOINT:
+ drawClaimedCheckpoint(newImage);
+ break;
+ }
+
+ _bitmaps.insert(make_pair(image, newImage));
+ return newImage;
+ }
+}
+
+void BitmapStore::drawPlayerCar(ALLEGRO_BITMAP* canvas)
+{
+ ALLEGRO_BITMAP* prev_draw = al_get_target_bitmap();
+ al_set_target_bitmap(canvas);
+
+ //car body
+ 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));
+
+ //racing stripes
+ al_draw_filled_rectangle(_blockWidth*0.35, 0, _blockWidth*0.4, _blockWidth*0.3, al_map_rgb(255,255,255));
+ al_draw_filled_rectangle(_blockWidth*0.6, 0, _blockWidth*0.65, _blockWidth*0.3, al_map_rgb(255,255,255));
+
+ //windscreen
+ al_draw_filled_rectangle(_blockWidth*0.3, _blockWidth*0.3, _blockWidth*0.7, _blockWidth*0.5, al_map_rgb (0,0,0));
+
+ //roof
+ 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);
+
+ //spoiler
+ al_draw_filled_rectangle(_blockWidth*0.2, _blockWidth*0.96, _blockWidth*0.8, _blockWidth, al_map_rgb (0,0, 225));
+ al_draw_rectangle(_blockWidth*0.2, _blockWidth*0.96, _blockWidth*0.8, _blockWidth, al_map_rgb(25,25, 112),_blockWidth*0.04);
+
+ //headlights
+ al_draw_filled_rectangle (_blockWidth*0.3,0,_blockWidth*0.35,_blockWidth*0.06, al_map_rgb(255,225,0));
+ al_draw_filled_rectangle (_blockWidth*0.65,0,_blockWidth*0.7,_blockWidth*0.06, al_map_rgb(255,225,0));
+
+ //tyres
+ 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));
+ 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));
+ 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));
+ 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));
+
+ al_set_target_bitmap(prev_draw);
+}
+void BitmapStore::drawEnemyCar(ALLEGRO_BITMAP* canvas)
+{
+ ALLEGRO_BITMAP* prev_draw = al_get_target_bitmap();
+ al_set_target_bitmap(canvas);
+
+ //car body
+ 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));
+
+ //racing stripes
+ al_draw_filled_rectangle(_blockWidth*0.35, 0, _blockWidth*0.4, _blockWidth*0.3, al_map_rgb(255,255,255));
+ al_draw_filled_rectangle(_blockWidth*0.6, 0, _blockWidth*0.65, _blockWidth*0.3, al_map_rgb(255,255,255));
+
+ //windscreen
+ al_draw_filled_rectangle(_blockWidth*0.3, _blockWidth*0.3, _blockWidth*0.7, _blockWidth*0.5, al_map_rgb (0,0,0));
+
+ //roof
+ 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);
+
+ //spoiler
+ al_draw_filled_rectangle(_blockWidth*0.2, _blockWidth*0.96, _blockWidth*0.8, _blockWidth, al_map_rgb (0,0, 225));
+ al_draw_rectangle(_blockWidth*0.2, _blockWidth*0.96, _blockWidth*0.8, _blockWidth, al_map_rgb(25,25, 112),_blockWidth*0.04);
+
+ //headlights
+ al_draw_filled_rectangle (_blockWidth*0.3,0,_blockWidth*0.35,_blockWidth*0.06, al_map_rgb(255,225,0));
+ al_draw_filled_rectangle (_blockWidth*0.65,0,_blockWidth*0.7,_blockWidth*0.06, al_map_rgb(255,225,0));
+
+ //tyres
+ 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));
+ 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));
+ 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));
+ 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));
+
+ al_set_target_bitmap(prev_draw);
+}
+void BitmapStore::drawRock(ALLEGRO_BITMAP* canvas)
+{
+ ALLEGRO_BITMAP* prev_draw = al_get_target_bitmap();
+ al_set_target_bitmap(canvas);
+
+ ALLEGRO_COLOR colour = al_map_rgb(131,139,131);
+ al_draw_filled_circle(_blockWidth/2, _blockWidth/2, _blockWidth/2-1, colour);
+
+ al_draw_filled_circle(_blockWidth/2, _blockWidth/2, _blockWidth/2-6, colour);
+ al_draw_filled_circle(_blockWidth/4, _blockWidth/4, _blockWidth/4-1, al_map_rgb(205,197,191));
+ al_draw_filled_circle(_blockWidth/3.2, _blockWidth/4.2, _blockWidth/4-2, al_map_rgb(205,197,191));
+ al_draw_filled_circle(_blockWidth/1.2, _blockWidth/2, _blockWidth/2-15, al_map_rgb(205,197,191));
+ al_draw_filled_circle(_blockWidth/2, _blockWidth/2, _blockWidth/2-8, al_map_rgb(205,205,193));
+
+ al_set_target_bitmap(prev_draw);
+}
+void BitmapStore::drawCheckpoint(ALLEGRO_BITMAP* canvas)
+{
+ ALLEGRO_BITMAP* prev_draw = al_get_target_bitmap();
+ al_set_target_bitmap(canvas);
+
+ ALLEGRO_COLOR colour = al_map_rgb(255,255,0);
+
+ al_draw_filled_rectangle (_blockWidth*0.44, _blockWidth*0.1, _blockWidth*0.5, _blockWidth*0.9, colour);
+ al_draw_filled_rounded_rectangle (_blockWidth*0.34, _blockWidth*0.9, _blockWidth*0.6, _blockWidth*0.98, _blockWidth*0.01, _blockWidth*0.01, colour);
+ al_draw_filled_circle (_blockWidth*0.47, _blockWidth*0.14, _blockWidth*0.1, colour);
+ al_draw_filled_triangle (_blockWidth*0.44, _blockWidth*0.26, _blockWidth*0.44, _blockWidth*0.58, _blockWidth*0.8, _blockWidth*0.42, colour);
+
+ al_set_target_bitmap(prev_draw);
+}
+void BitmapStore::drawMazeWall(ALLEGRO_BITMAP* canvas)
+{
+ ALLEGRO_BITMAP* prev_draw = al_get_target_bitmap();
+ al_set_target_bitmap(canvas);
+
+ ALLEGRO_COLOR colour = al_map_rgb(203,255,151);
+ al_clear_to_color(colour);
+
+ al_set_target_bitmap(prev_draw);
+}
+void BitmapStore::drawMazeFloor(ALLEGRO_BITMAP* canvas)
+{
+ ALLEGRO_BITMAP* prev_draw = al_get_target_bitmap();
+ al_set_target_bitmap(canvas);
+
+ ALLEGRO_COLOR colour = al_map_rgb(0,0,0);
+ al_clear_to_color(colour);
+
+ al_set_target_bitmap(prev_draw);
+}
+void BitmapStore::drawSmoke(ALLEGRO_BITMAP* canvas)
+{
+ ALLEGRO_BITMAP* prev_draw = al_get_target_bitmap();
+ al_set_target_bitmap(canvas);
+
+ ALLEGRO_COLOR colour = al_map_rgb(255,255,255);
+ al_draw_circle (_blockWidth/2.3, _blockWidth/2.1, _blockWidth/2-1, colour,1);
+ al_draw_circle (_blockWidth/4, _blockWidth/4, _blockWidth/4, colour,2);
+ al_draw_circle (_blockWidth/5, _blockWidth/1.5, _blockWidth/4, colour,4);
+ al_draw_circle (_blockWidth/2.5, _blockWidth/2.7, _blockWidth/3, colour,3);
+ al_draw_circle (_blockWidth/1.2, _blockWidth/1.8, _blockWidth/3.7, colour,2);
+ al_draw_circle (_blockWidth/2.8, _blockWidth/2.2, _blockWidth/6, colour,3);
+ al_draw_circle (_blockWidth/1.1, _blockWidth/1.2, _blockWidth/3, colour,2);
+ al_draw_circle (_blockWidth/1.2, _blockWidth/1.7, _blockWidth/2, colour,3);
+ al_draw_circle (_blockWidth/1.3, _blockWidth/1.3, _blockWidth/5, colour,2);
+
+ al_set_target_bitmap(prev_draw);
+}
+
+void BitmapStore::drawCrashedCar(ALLEGRO_BITMAP* canvas)
+{
+ ALLEGRO_BITMAP* prev_draw = al_get_target_bitmap();
+ al_set_target_bitmap(canvas);
+
+ al_draw_filled_rounded_rectangle(_blockWidth/3.33, _blockWidth/5, _blockWidth/1.25, _blockWidth/1.04, 5, 5, al_map_rgb (200, 200, 200));
+ al_draw_circle (_blockWidth/2.3, _blockWidth/2.1, _blockWidth/2-1, al_map_rgb (255, 0, 0),1);
+ al_draw_circle (_blockWidth/4, _blockWidth/4, _blockWidth/4, al_map_rgb (100, 100, 100),2);
+ al_draw_circle (_blockWidth/5, _blockWidth/1.5, _blockWidth/4, al_map_rgb (255, 0, 0),4);
+ al_draw_filled_rectangle(_blockWidth/2.5, _blockWidth/2, _blockWidth/1.43, _blockWidth/1.7, al_map_rgb (0,0, 0));
+ al_draw_circle (_blockWidth/2.5, _blockWidth/2.7, _blockWidth/3, al_map_rgb (100, 100, 100),3);
+ al_draw_circle (_blockWidth/1.2, _blockWidth/1.8, _blockWidth/3.7, al_map_rgb (255, 0, 0),2);
+ al_draw_rectangle(_blockWidth/3.13, _blockWidth/1.04, _blockWidth/1.25, _blockWidth, al_map_rgb (25,25, 112),1);
+ al_draw_circle (_blockWidth/2.8, _blockWidth/2.2, _blockWidth/6, al_map_rgb (255, 0, 0),3);
+ al_draw_circle (_blockWidth/1.1, _blockWidth/1.2, _blockWidth/3, al_map_rgb (100, 100, 100),2);
+ al_draw_circle (_blockWidth/1.2, _blockWidth/1.7, _blockWidth/2, al_map_rgb (100, 100, 100),3);
+ al_draw_circle (_blockWidth/1.3, _blockWidth/1.3, _blockWidth/5, al_map_rgb (255, 0, 0),2);
+
+ al_set_target_bitmap(prev_draw);
+}
+
+void BitmapStore::drawClaimedCheckpoint(ALLEGRO_BITMAP* canvas)
+{
+ ALLEGRO_BITMAP* prev_draw = al_get_target_bitmap();
+ al_set_target_bitmap(canvas);
+
+ ALLEGRO_COLOR colour = al_map_rgb(255,255,255);
+ al_draw_text(_bitmapFont, colour, _blockWidth/2, _blockWidth/2, ALLEGRO_ALIGN_CENTRE , "GOTCHA");
+
+ al_set_target_bitmap(prev_draw);
+}