Ben Evans University Second Year Project. Game Called Defender.
Embed:
(wiki syntax)
Show/hide line numbers
HUD.cpp
00001 #include "HUD.h" 00002 00003 const int k_spaceship_lives[6][7] = { 00004 { 0,1,1,0,1,1,0 }, 00005 { 1,1,1,1,1,1,1 }, 00006 { 1,1,1,1,1,1,1 }, 00007 { 0,1,1,1,1,1,0 }, 00008 { 0,0,1,1,1,0,0 }, 00009 { 0,0,0,1,0,0,0 }, 00010 }; 00011 00012 const int k_smart_bombs[6][5] = { 00013 { 0,0,1,0,0 }, 00014 { 0,1,1,1,0 }, 00015 { 0,1,1,1,0 }, 00016 { 0,1,1,1,0 }, 00017 { 1,1,1,1,1 }, 00018 { 0,1,0,1,0 }, 00019 }; 00020 00021 HUD::HUD() { 00022 00023 } 00024 00025 HUD::~HUD() { 00026 00027 } 00028 00029 void HUD::draw_HUD(N5110 &lcd,int spaceship_lives, int points, 00030 int smart_bomb_counter) { 00031 lcd.drawLine(0, 8, 84, 8,1); 00032 00033 // Draws points at top of screen 00034 char buffer[4]; 00035 sprintf(buffer,"%.4d",points); 00036 lcd.printString(buffer,30,0); 00037 00038 // Draw lives and smart bombs 00039 draw_lives(lcd, spaceship_lives); 00040 draw_smart_bombs(lcd, smart_bomb_counter); 00041 } 00042 00043 void HUD::draw_lives(N5110 &lcd,int spaceship_lives) { 00044 // Draw one two or three lives 00045 if (spaceship_lives >= 1) { 00046 lcd.drawSprite(1, 1, 6, 7, (int*)k_spaceship_lives); 00047 } 00048 if (spaceship_lives >= 2) { 00049 lcd.drawSprite(9, 1, 6, 7, (int*)k_spaceship_lives); 00050 } 00051 if (spaceship_lives == 3) { 00052 lcd.drawSprite(17, 1, 6, 7, (int*)k_spaceship_lives); 00053 } 00054 } 00055 00056 void HUD::draw_smart_bombs(N5110 &lcd,int smart_bomb_counter) { 00057 // Draws each smart bomb depending on counter 00058 if (smart_bomb_counter >= 1) { 00059 lcd.drawSprite(78, 1, 6, 5, (int*)k_smart_bombs); 00060 } 00061 if (smart_bomb_counter >= 2) { 00062 lcd.drawSprite(72, 1, 6, 5, (int*)k_smart_bombs); 00063 } 00064 if (smart_bomb_counter >= 3) { 00065 lcd.drawSprite(66, 1, 6, 5, (int*)k_smart_bombs); 00066 } 00067 if (smart_bomb_counter >= 4) { 00068 lcd.drawSprite(60, 1, 6, 5, (int*)k_smart_bombs); 00069 } 00070 }
Generated on Fri Aug 5 2022 06:55:07 by
1.7.2