Nemesis game, stats

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers Stats.cpp Source File

Stats.cpp

00001 #include "Stats.h"
00002 
00003 Stats::Stats()
00004 {
00005 }
00006 
00007 Stats::~Stats()
00008 {
00009 }
00010 
00011 
00012 // Draws initial inner and outer borders to the LCD:
00013 
00014 void Stats::draw_grid(N5110 &lcd)
00015 {
00016     lcd.drawRect(0, 0, WIDTH, HEIGHT-8, FILL_TRANSPARENT);  // Outer border.
00017     lcd.drawLine(WIDTH-1, HEIGHT-8, WIDTH-1, HEIGHT, 1);    // Health border, right side.
00018     lcd.drawLine(WIDTH-11, HEIGHT-8, WIDTH-11, HEIGHT, 1);  // Health border, left side.
00019     lcd.drawLine(18, HEIGHT-1, WIDTH, HEIGHT-1, 1);         // Bottom border.
00020     lcd.drawLine(18, HEIGHT-8, 18, HEIGHT, 1);              // Wave counter border.
00021 }
00022 
00023 
00024 // Draws the wave counter onto the LCD:
00025 
00026 void Stats::draw_wave_counter(N5110 &lcd, int wave_counter)
00027 {
00028     char buffer[14];
00029     int length = sprintf(buffer,"%2d",wave_counter);
00030     lcd.printString(buffer,0,5);    // Draws constantly-updating value for waves survived onto the bottom left corner of the grid.
00031 }
00032 
00033 
00034 // Draws the health bar heart onto the LCD (initially empty):
00035 
00036 void Stats::draw_health(N5110 &lcd)
00037 {
00038     lcd.drawLine(76,40,77,40,1);
00039     lcd.drawLine(79,40,80,40,1);
00040     lcd.drawLine(75,41,75,43,1);
00041     lcd.drawLine(81,41,81,43,1);
00042     lcd.setPixel(78,41);
00043     lcd.setPixel(76,44);
00044     lcd.setPixel(80,44);
00045     lcd.setPixel(77,45);
00046     lcd.setPixel(79,45);
00047     lcd.setPixel(78,46);
00048 }
00049 
00050 
00051 // Draws the first rocket onto the LCD:
00052 
00053 void Stats::draw_rocket1(N5110 &lcd, int state)
00054 {
00055     // State is input when method is used:
00056     lcd.drawLine(27, HEIGHT-3, 30, HEIGHT-3, state);
00057     lcd.drawLine(28, HEIGHT-4, 40, HEIGHT-4, state);
00058     lcd.drawLine(29, HEIGHT-5, 41, HEIGHT-5, state);
00059     lcd.drawLine(28, HEIGHT-6, 40, HEIGHT-6, state);
00060     lcd.drawLine(27, HEIGHT-7, 30, HEIGHT-7, state);
00061 }
00062 
00063 
00064 // Draws the second rocket onto the LCD:
00065 
00066 void Stats::draw_rocket2(N5110 &lcd, int state)
00067 {
00068     // State is input when method is used:
00069     lcd.drawLine(42, HEIGHT-3, 45, HEIGHT-3, state);
00070     lcd.drawLine(43, HEIGHT-4, 55, HEIGHT-4, state);
00071     lcd.drawLine(44, HEIGHT-5, 56, HEIGHT-5, state);
00072     lcd.drawLine(43, HEIGHT-6, 55, HEIGHT-6, state);
00073     lcd.drawLine(42, HEIGHT-7, 45, HEIGHT-7, state);
00074 }
00075 
00076 
00077 // Draws the third rocket onto the LCD:
00078 
00079 void Stats::draw_rocket3(N5110 &lcd, int state)
00080 {
00081     // State is input when method is used:
00082     lcd.drawLine(57, HEIGHT-3, 60, HEIGHT-3, state);
00083     lcd.drawLine(58, HEIGHT-4, 70, HEIGHT-4, state);
00084     lcd.drawLine(59, HEIGHT-5, 71, HEIGHT-5, state);
00085     lcd.drawLine(58, HEIGHT-6, 70, HEIGHT-6, state);
00086     lcd.drawLine(57, HEIGHT-7, 60, HEIGHT-7, state);
00087 }
00088 
00089 
00090 // Draws the star onto the LCD:
00091 
00092 void Stats::draw_star(N5110 &lcd, int state)
00093 {
00094     // State is input when method is used:
00095     lcd.drawLine(20, HEIGHT-6, 24, HEIGHT-6, state);
00096     lcd.drawLine(20, HEIGHT-4, 24, HEIGHT-4, state);
00097     lcd.drawLine(21, HEIGHT-3, 21, HEIGHT-7, state);
00098     lcd.drawLine(23, HEIGHT-3, 23, HEIGHT-7, state);
00099     lcd.setPixel(20,41);
00100     lcd.setPixel(20,45);
00101     lcd.setPixel(24,41);
00102     lcd.setPixel(24,45);
00103 }
00104 
00105 
00106 // Checks and draws the health bar (for high health):
00107 
00108 void Stats::check_health_high(N5110 &lcd, int collisions)
00109 {
00110     // Collisions is input and checked when method is used:
00111     if (collisions == 0) 
00112     {   
00113         lcd.drawLine(76,41,80,41,1);
00114         lcd.drawLine(76,42,80,42,1);
00115         lcd.drawLine(76,43,80,43,1);
00116         lcd.drawLine(77,44,79,44,1);
00117         lcd.setPixel(78,45);
00118     }
00119     else if (collisions == 1) 
00120     {
00121         lcd.drawLine(76,42,80,42,1);
00122         lcd.drawLine(76,43,80,43,1);
00123         lcd.drawLine(77,44,79,44,1);
00124         lcd.setPixel(78,45);
00125     }
00126 }
00127 
00128 
00129 // Checks and draws the health bar (for low health):
00130 
00131 void Stats::check_health_low(N5110 &lcd, int collisions)
00132 {
00133     // Collisions is input and checked when method is used:
00134     if (collisions == 2) 
00135     {
00136         lcd.drawLine(76,43,80,43,1);
00137         lcd.drawLine(77,44,79,44,1);
00138         lcd.setPixel(78,45);
00139     }
00140     else if (collisions == 3) 
00141     {
00142         lcd.drawLine(77,44,79,44,1);
00143         lcd.setPixel(78,45);
00144     }
00145     else if (collisions == 4)
00146     {
00147         lcd.setPixel(78,45);
00148     }
00149 }
00150 
00151 
00152 // Checks and draws the rockets:
00153 
00154 void Stats::check_rocket(N5110 &lcd, int ammo)
00155 {
00156     // Ammo is input and checked when method is used:
00157     if (ammo == 3) {
00158         draw_rocket1(lcd, 1);
00159         draw_rocket2(lcd, 1);
00160         draw_rocket3(lcd, 1);
00161     } else if (ammo == 2) {
00162         draw_rocket1(lcd, 1);
00163         draw_rocket2(lcd, 1);
00164         draw_rocket3(lcd, 2);
00165     } else if (ammo == 1) {
00166         draw_rocket1(lcd, 1);
00167         draw_rocket2(lcd, 2);
00168         draw_rocket3(lcd, 2);
00169     } else if (ammo == 0) {
00170         draw_rocket1(lcd, 2);
00171         draw_rocket2(lcd, 2);
00172         draw_rocket3(lcd, 2);
00173     }
00174 }
00175 
00176 
00177 // Checks and draws the star:
00178 
00179 void Stats::check_star(N5110 &lcd, bool star)
00180 {
00181     // Star is input and checked when method is used:
00182     if (star == true) 
00183     {
00184         draw_star(lcd, 1);
00185     } 
00186     else 
00187     {
00188         draw_star(lcd, 2);
00189     }
00190 }