contains my game for the embedded systems project 2645
Dependencies: mbed FXOS8700CQQQ
GameEngine/RocketRacer.cpp@40:13b8467526d0, 2019-05-07 (annotated)
- Committer:
- OmarAlebiary
- Date:
- Tue May 07 15:17:21 2019 +0000
- Revision:
- 40:13b8467526d0
- Parent:
- 33:24ef796ff2c8
Final Submission. I have read and agreed with Statement of Academic Integrity
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
OmarAlebiary | 6:958376d55d70 | 1 | #include "RocketRacer.h" |
OmarAlebiary | 6:958376d55d70 | 2 | |
OmarAlebiary | 32:e5d997d2ed79 | 3 | // create object and specifiy pins |
OmarAlebiary | 30:c5060010a1e6 | 4 | FXOS8700CQ device(I2C_SDA,I2C_SCL); |
OmarAlebiary | 25:7e3b6df93dd5 | 5 | |
OmarAlebiary | 30:c5060010a1e6 | 6 | //default constructor of the class and initializing the private variables |
OmarAlebiary | 15:8a768106c297 | 7 | RocketRacer::RocketRacer() |
OmarAlebiary | 15:8a768106c297 | 8 | :first_enemy_position(0),second_enemy_position(0),enemy_phase(0), |
OmarAlebiary | 40:13b8467526d0 | 9 | game_speed (0),score(0),pitchAngle(0.0),Init_position(2),enemy_dead(true),control(true) |
OmarAlebiary | 15:8a768106c297 | 10 | {} |
OmarAlebiary | 6:958376d55d70 | 11 | |
OmarAlebiary | 33:24ef796ff2c8 | 12 | //destructor of the class |
OmarAlebiary | 29:e660274d8222 | 13 | RocketRacer::~RocketRacer(){ |
OmarAlebiary | 29:e660274d8222 | 14 | } |
OmarAlebiary | 33:24ef796ff2c8 | 15 | |
OmarAlebiary | 33:24ef796ff2c8 | 16 | /////////setters///////////////// |
OmarAlebiary | 40:13b8467526d0 | 17 | |
OmarAlebiary | 33:24ef796ff2c8 | 18 | //sets the enemy position |
OmarAlebiary | 29:e660274d8222 | 19 | void RocketRacer::set_first_position(int first_enemy_position) { |
OmarAlebiary | 29:e660274d8222 | 20 | first_enemy_position = first_enemy_position; |
OmarAlebiary | 29:e660274d8222 | 21 | } |
OmarAlebiary | 21:5c98996d1487 | 22 | |
OmarAlebiary | 33:24ef796ff2c8 | 23 | //sets the second enemy position |
OmarAlebiary | 29:e660274d8222 | 24 | void RocketRacer::set_second_position(int second_enemy_position) { |
OmarAlebiary | 29:e660274d8222 | 25 | second_enemy_position = second_enemy_position; |
OmarAlebiary | 29:e660274d8222 | 26 | } |
OmarAlebiary | 29:e660274d8222 | 27 | |
OmarAlebiary | 33:24ef796ff2c8 | 28 | |
OmarAlebiary | 29:e660274d8222 | 29 | void RocketRacer::set_enemy_phase(int enemy_phase) { |
OmarAlebiary | 29:e660274d8222 | 30 | enemy_phase = enemy_phase; |
OmarAlebiary | 29:e660274d8222 | 31 | } |
OmarAlebiary | 29:e660274d8222 | 32 | |
OmarAlebiary | 33:24ef796ff2c8 | 33 | //sets the game speed |
OmarAlebiary | 29:e660274d8222 | 34 | void RocketRacer::set_game_speed(int game_speed) { |
OmarAlebiary | 29:e660274d8222 | 35 | game_speed = game_speed; |
OmarAlebiary | 29:e660274d8222 | 36 | } |
OmarAlebiary | 29:e660274d8222 | 37 | |
OmarAlebiary | 33:24ef796ff2c8 | 38 | //sets the game score |
OmarAlebiary | 29:e660274d8222 | 39 | void RocketRacer::set_game_score(int score) { |
OmarAlebiary | 29:e660274d8222 | 40 | score = score; |
OmarAlebiary | 29:e660274d8222 | 41 | } |
OmarAlebiary | 32:e5d997d2ed79 | 42 | |
OmarAlebiary | 33:24ef796ff2c8 | 43 | //sets the flag enemy_dead |
OmarAlebiary | 29:e660274d8222 | 44 | void RocketRacer::set_enemy_dead(bool enemy_dead) { |
OmarAlebiary | 29:e660274d8222 | 45 | enemy_dead = enemy_dead; |
OmarAlebiary | 29:e660274d8222 | 46 | } |
OmarAlebiary | 32:e5d997d2ed79 | 47 | |
OmarAlebiary | 33:24ef796ff2c8 | 48 | //sets the flag control |
OmarAlebiary | 29:e660274d8222 | 49 | void RocketRacer::set_control(bool control) { |
OmarAlebiary | 29:e660274d8222 | 50 | control = control; |
OmarAlebiary | 29:e660274d8222 | 51 | } |
OmarAlebiary | 32:e5d997d2ed79 | 52 | |
OmarAlebiary | 33:24ef796ff2c8 | 53 | //sets the initial position |
OmarAlebiary | 29:e660274d8222 | 54 | void RocketRacer::set_init_position(int Init_position) { |
OmarAlebiary | 29:e660274d8222 | 55 | Init_position = Init_position; |
OmarAlebiary | 29:e660274d8222 | 56 | } |
OmarAlebiary | 32:e5d997d2ed79 | 57 | |
OmarAlebiary | 40:13b8467526d0 | 58 | /////////Game Methods///////////////// |
OmarAlebiary | 32:e5d997d2ed79 | 59 | |
OmarAlebiary | 12:1d3b0218d8d0 | 60 | void RocketRacer::Main_Game_Display(N5110 &lcd){ |
OmarAlebiary | 40:13b8467526d0 | 61 | |
OmarAlebiary | 21:5c98996d1487 | 62 | lcd.clear(); //clears the lcd |
OmarAlebiary | 24:a049cef2cc2e | 63 | lcd.drawRect(0,0,46,47,FILL_BLACK);//draws a transparent rectangle on the lcd |
OmarAlebiary | 21:5c98996d1487 | 64 | char score_buffer[14];//buffer to store the score |
OmarAlebiary | 12:1d3b0218d8d0 | 65 | char score_buffer1[14]; |
OmarAlebiary | 21:5c98996d1487 | 66 | char level_buffer[14];//buffer to store the current level |
OmarAlebiary | 24:a049cef2cc2e | 67 | char level_buffer1[14]; |
OmarAlebiary | 21:5c98996d1487 | 68 | //display score |
OmarAlebiary | 12:1d3b0218d8d0 | 69 | sprintf(score_buffer,"score"); |
OmarAlebiary | 12:1d3b0218d8d0 | 70 | lcd.printString(score_buffer,55,0); |
OmarAlebiary | 12:1d3b0218d8d0 | 71 | sprintf(score_buffer1,"%d",score); |
OmarAlebiary | 12:1d3b0218d8d0 | 72 | lcd.printString(score_buffer1,58,1); |
OmarAlebiary | 24:a049cef2cc2e | 73 | lcd.drawLine(15, 2, 15,48,0); |
OmarAlebiary | 24:a049cef2cc2e | 74 | lcd.drawLine(30, 2, 30,48,0); |
OmarAlebiary | 21:5c98996d1487 | 75 | //display level |
OmarAlebiary | 12:1d3b0218d8d0 | 76 | sprintf(level_buffer,"Level"); |
OmarAlebiary | 12:1d3b0218d8d0 | 77 | lcd.printString(level_buffer,55,3); |
OmarAlebiary | 12:1d3b0218d8d0 | 78 | sprintf(level_buffer1,"%d",game_speed); |
OmarAlebiary | 12:1d3b0218d8d0 | 79 | lcd.printString(level_buffer1,58,4); |
OmarAlebiary | 24:a049cef2cc2e | 80 | lcd.refresh();//refreshes the lcd to render |
OmarAlebiary | 31:4d4a9d78cae5 | 81 | } |
OmarAlebiary | 7:7e50cac5e0f4 | 82 | |
OmarAlebiary | 11:d4aaa959bb20 | 83 | |
OmarAlebiary | 30:c5060010a1e6 | 84 | void RocketRacer::accelerometer_position(Gamepad &pad){ |
OmarAlebiary | 30:c5060010a1e6 | 85 | |
OmarAlebiary | 40:13b8467526d0 | 86 | pitchAngle = device.get_pitch_angle();//gets the pitch angle |
OmarAlebiary | 33:24ef796ff2c8 | 87 | //statement to check if the gamepad rolled to the right |
OmarAlebiary | 33:24ef796ff2c8 | 88 | if( (pitchAngle > 100)&& Init_position!=3 && control==true){ |
OmarAlebiary | 30:c5060010a1e6 | 89 | Init_position++;//increments the position of the player sprite |
OmarAlebiary | 30:c5060010a1e6 | 90 | control = false; //sets the flag to false |
OmarAlebiary | 32:e5d997d2ed79 | 91 | wait(0.1);// small delay to prevent previous press being detected again |
OmarAlebiary | 30:c5060010a1e6 | 92 | // printf("its Right\n"); |
OmarAlebiary | 30:c5060010a1e6 | 93 | } |
OmarAlebiary | 33:24ef796ff2c8 | 94 | //statement to check if the gamepad rolled to the left |
OmarAlebiary | 33:24ef796ff2c8 | 95 | else if( (pitchAngle < 90 )&& Init_position!=1 && control==true){ |
OmarAlebiary | 30:c5060010a1e6 | 96 | Init_position--;//decrements the position of the player sprite |
OmarAlebiary | 30:c5060010a1e6 | 97 | control = false;//sets the flag to false |
OmarAlebiary | 32:e5d997d2ed79 | 98 | wait(0.01);// small delay to prevent previous press being detected again |
OmarAlebiary | 30:c5060010a1e6 | 99 | // printf("its left\n"); |
OmarAlebiary | 30:c5060010a1e6 | 100 | } |
OmarAlebiary | 30:c5060010a1e6 | 101 | else {//statement to check if the joystick position is center |
OmarAlebiary | 30:c5060010a1e6 | 102 | control = true;//sets the flag to true |
OmarAlebiary | 32:e5d997d2ed79 | 103 | wait(0.01); |
OmarAlebiary | 30:c5060010a1e6 | 104 | // printf("its center\n"); |
OmarAlebiary | 30:c5060010a1e6 | 105 | } |
OmarAlebiary | 30:c5060010a1e6 | 106 | } |
OmarAlebiary | 30:c5060010a1e6 | 107 | |
OmarAlebiary | 30:c5060010a1e6 | 108 | |
OmarAlebiary | 11:d4aaa959bb20 | 109 | void RocketRacer::Joystick_position(Gamepad &pad){ |
OmarAlebiary | 33:24ef796ff2c8 | 110 | //assigning d to the method to get the joystick direction |
OmarAlebiary | 33:24ef796ff2c8 | 111 | Direction d=pad.get_direction(); |
OmarAlebiary | 11:d4aaa959bb20 | 112 | |
OmarAlebiary | 19:ad9dc8e418c9 | 113 | if( (d==E||pad.check_event(Gamepad::R_PRESSED) == true ) |
OmarAlebiary | 21:5c98996d1487 | 114 | && Init_position!=3 && control==true){//statement to check if the joystick moved right |
OmarAlebiary | 21:5c98996d1487 | 115 | Init_position++;//increments the position of the player sprite |
OmarAlebiary | 21:5c98996d1487 | 116 | control = false; //sets the flag to false |
OmarAlebiary | 28:39607fb67e88 | 117 | wait(0.09);// small delay to prevent previous press being detected again |
OmarAlebiary | 15:8a768106c297 | 118 | // printf("its Right\n"); |
OmarAlebiary | 8:b547037f42be | 119 | } |
OmarAlebiary | 19:ad9dc8e418c9 | 120 | else if( (d==W ||pad.check_event(Gamepad::L_PRESSED) == true ) |
OmarAlebiary | 21:5c98996d1487 | 121 | && Init_position!=1 && control==true){//statement to check if the joystick moved left |
OmarAlebiary | 21:5c98996d1487 | 122 | Init_position--;//decrements the position of the player sprite |
OmarAlebiary | 21:5c98996d1487 | 123 | control = false;//sets the flag to false |
OmarAlebiary | 23:2ca9735b16ef | 124 | wait(0.01);// small delay to prevent previous press being detected again |
OmarAlebiary | 15:8a768106c297 | 125 | // printf("its left\n"); |
OmarAlebiary | 8:b547037f42be | 126 | } |
OmarAlebiary | 21:5c98996d1487 | 127 | else if(d==CENTRE){//statement to check if the joystick position is center |
OmarAlebiary | 21:5c98996d1487 | 128 | control = true;//sets the flag to true |
OmarAlebiary | 23:2ca9735b16ef | 129 | wait(0.01); |
OmarAlebiary | 15:8a768106c297 | 130 | // printf("its center\n"); |
OmarAlebiary | 9:edb39a8334ee | 131 | } |
OmarAlebiary | 11:d4aaa959bb20 | 132 | } |
OmarAlebiary | 12:1d3b0218d8d0 | 133 | |
OmarAlebiary | 12:1d3b0218d8d0 | 134 | |
OmarAlebiary | 40:13b8467526d0 | 135 | |
OmarAlebiary | 40:13b8467526d0 | 136 | |
OmarAlebiary | 40:13b8467526d0 | 137 | |
OmarAlebiary | 11:d4aaa959bb20 | 138 | void RocketRacer::Generate_New_Enemy(){ |
OmarAlebiary | 12:1d3b0218d8d0 | 139 | |
OmarAlebiary | 21:5c98996d1487 | 140 | srand(time(NULL));//seeding the random function |
OmarAlebiary | 9:edb39a8334ee | 141 | |
OmarAlebiary | 21:5c98996d1487 | 142 | if (enemy_dead){//statement to check if the enemy crossed the player sprite |
OmarAlebiary | 21:5c98996d1487 | 143 | first_enemy_position = Init_position;//places the first enemy above the player's sprite |
OmarAlebiary | 21:5c98996d1487 | 144 | second_enemy_position = (rand() % 3)+1;//generates a random number from 1 to 3 |
OmarAlebiary | 28:39607fb67e88 | 145 | //printf("%d",second_enemy_position); |
OmarAlebiary | 12:1d3b0218d8d0 | 146 | enemy_phase = 0; |
OmarAlebiary | 12:1d3b0218d8d0 | 147 | enemy_dead = false; |
OmarAlebiary | 11:d4aaa959bb20 | 148 | } |
OmarAlebiary | 12:1d3b0218d8d0 | 149 | } |
OmarAlebiary | 28:39607fb67e88 | 150 | |
OmarAlebiary | 28:39607fb67e88 | 151 | |
OmarAlebiary | 11:d4aaa959bb20 | 152 | void RocketRacer::Check_Enemy_Dead(N5110 &lcd,Gamepad &pad){ |
OmarAlebiary | 33:24ef796ff2c8 | 153 | //statement to check if the enemies collided with the rocket |
OmarAlebiary | 19:ad9dc8e418c9 | 154 | if (enemy_phase>23 && ((first_enemy_position== Init_position) |
OmarAlebiary | 33:24ef796ff2c8 | 155 | || (second_enemy_position == Init_position)) ){ |
OmarAlebiary | 28:39607fb67e88 | 156 | End_Game(pad,lcd);//calls the end game method that displays game over screen |
OmarAlebiary | 33:24ef796ff2c8 | 157 | |
OmarAlebiary | 12:1d3b0218d8d0 | 158 | } |
OmarAlebiary | 33:24ef796ff2c8 | 159 | if (enemy_phase>39){//statement to check if the enemies crossed without colliding with the rocket |
OmarAlebiary | 12:1d3b0218d8d0 | 160 | enemy_dead = true; |
OmarAlebiary | 21:5c98996d1487 | 161 | score++;//increments the score |
OmarAlebiary | 33:24ef796ff2c8 | 162 | } |
OmarAlebiary | 33:24ef796ff2c8 | 163 | } |
OmarAlebiary | 33:24ef796ff2c8 | 164 | |
OmarAlebiary | 11:d4aaa959bb20 | 165 | |
OmarAlebiary | 30:c5060010a1e6 | 166 | void RocketRacer::Game_Loop_accelerometer(N5110 &lcd,Gamepad &pad){ |
OmarAlebiary | 30:c5060010a1e6 | 167 | |
OmarAlebiary | 40:13b8467526d0 | 168 | lcd.clear(); //clears the lcd |
OmarAlebiary | 40:13b8467526d0 | 169 | //calls the method to get the joystick direction according to the user |
OmarAlebiary | 40:13b8467526d0 | 170 | accelerometer_position(pad); |
OmarAlebiary | 40:13b8467526d0 | 171 | //calls the method to draw the sprites according to accelerometer postion |
OmarAlebiary | 40:13b8467526d0 | 172 | player_position(lcd,Init_position); |
OmarAlebiary | 40:13b8467526d0 | 173 | Generate_One_Enemy();//generate 1 new enemy |
OmarAlebiary | 40:13b8467526d0 | 174 | //places the first enemy according to the position |
OmarAlebiary | 40:13b8467526d0 | 175 | enemy_position(lcd,first_enemy_position, enemy_phase); |
OmarAlebiary | 40:13b8467526d0 | 176 | enemy_phase++;//increments the current phase of the enemy |
OmarAlebiary | 40:13b8467526d0 | 177 | //places the second enemy according to the position |
OmarAlebiary | 40:13b8467526d0 | 178 | enemy_position(lcd,second_enemy_position, enemy_phase); |
OmarAlebiary | 40:13b8467526d0 | 179 | enemy_phase++;//increments the current phase of the enemy |
OmarAlebiary | 40:13b8467526d0 | 180 | |
OmarAlebiary | 40:13b8467526d0 | 181 | Check_Enemy_Dead(lcd,pad);//checks if enemies crossed the rocket |
OmarAlebiary | 40:13b8467526d0 | 182 | |
OmarAlebiary | 40:13b8467526d0 | 183 | Game_difficulty(pad); //adds difficulty to the game |
OmarAlebiary | 40:13b8467526d0 | 184 | |
OmarAlebiary | 40:13b8467526d0 | 185 | lcd.refresh();//refreshes the screen |
OmarAlebiary | 33:24ef796ff2c8 | 186 | } |
OmarAlebiary | 40:13b8467526d0 | 187 | |
OmarAlebiary | 40:13b8467526d0 | 188 | |
OmarAlebiary | 40:13b8467526d0 | 189 | void RocketRacer::Generate_One_Enemy(){ |
OmarAlebiary | 40:13b8467526d0 | 190 | |
OmarAlebiary | 40:13b8467526d0 | 191 | srand(time(NULL));//seeding the random function |
OmarAlebiary | 40:13b8467526d0 | 192 | |
OmarAlebiary | 40:13b8467526d0 | 193 | if (enemy_dead){//statement to check if the enemy crossed the player sprite |
OmarAlebiary | 40:13b8467526d0 | 194 | second_enemy_position = (rand() % 3)+1;//generates a random number from 1 to 3 |
OmarAlebiary | 40:13b8467526d0 | 195 | //printf("%d",second_enemy_position); |
OmarAlebiary | 40:13b8467526d0 | 196 | enemy_phase = 0; |
OmarAlebiary | 40:13b8467526d0 | 197 | enemy_dead = false; |
OmarAlebiary | 40:13b8467526d0 | 198 | } |
OmarAlebiary | 40:13b8467526d0 | 199 | } |
OmarAlebiary | 40:13b8467526d0 | 200 | |
OmarAlebiary | 28:39607fb67e88 | 201 | |
OmarAlebiary | 12:1d3b0218d8d0 | 202 | void RocketRacer::Game_Loop(N5110 &lcd,Gamepad &pad){ |
OmarAlebiary | 33:24ef796ff2c8 | 203 | lcd.clear(); //clears the lcd |
OmarAlebiary | 11:d4aaa959bb20 | 204 | |
OmarAlebiary | 33:24ef796ff2c8 | 205 | Joystick_position(pad);//calls the method to get the joystick direction according to the user |
OmarAlebiary | 33:24ef796ff2c8 | 206 | player_position(lcd,Init_position);//calls the method to draw the sprites according to joystick postion |
OmarAlebiary | 33:24ef796ff2c8 | 207 | |
OmarAlebiary | 33:24ef796ff2c8 | 208 | Generate_New_Enemy();//generate 2 new enemies |
OmarAlebiary | 11:d4aaa959bb20 | 209 | |
OmarAlebiary | 33:24ef796ff2c8 | 210 | enemy_position(lcd,first_enemy_position, enemy_phase);//places the first enemy according to the position |
OmarAlebiary | 33:24ef796ff2c8 | 211 | enemy_phase++;//increments the current phase of the enemy |
OmarAlebiary | 33:24ef796ff2c8 | 212 | enemy_position(lcd,second_enemy_position, enemy_phase);//places the second enemy according to the position |
OmarAlebiary | 33:24ef796ff2c8 | 213 | enemy_phase++;//increments the current phase of the enemy |
OmarAlebiary | 33:24ef796ff2c8 | 214 | |
OmarAlebiary | 33:24ef796ff2c8 | 215 | Check_Enemy_Dead(lcd,pad);//checks if enemies crossed the rocket |
OmarAlebiary | 33:24ef796ff2c8 | 216 | |
OmarAlebiary | 33:24ef796ff2c8 | 217 | Game_difficulty(pad); //adds difficulty to the game |
OmarAlebiary | 33:24ef796ff2c8 | 218 | |
OmarAlebiary | 33:24ef796ff2c8 | 219 | lcd.refresh();//refreshes the screen |
OmarAlebiary | 33:24ef796ff2c8 | 220 | } |
OmarAlebiary | 8:b547037f42be | 221 | |
OmarAlebiary | 9:edb39a8334ee | 222 | |
OmarAlebiary | 12:1d3b0218d8d0 | 223 | //adds difficulty to the game after proceeding with each level |
OmarAlebiary | 12:1d3b0218d8d0 | 224 | void RocketRacer::Game_difficulty(Gamepad &pad){ |
OmarAlebiary | 10:7323785c071c | 225 | if (score>=0 && score<=5){ |
OmarAlebiary | 21:5c98996d1487 | 226 | pad.led(1,1.0); game_speed = 1;//first led on to indicate level 1 |
OmarAlebiary | 21:5c98996d1487 | 227 | wait(0.09);//reduces the wait on each level |
OmarAlebiary | 20:1907ef5d29bb | 228 | }if (score>5 && score<=10){ |
OmarAlebiary | 21:5c98996d1487 | 229 | pad.led(2,1.0); game_speed = 2;//first&second leds on to indicate level 2 |
OmarAlebiary | 10:7323785c071c | 230 | wait(0.07); |
OmarAlebiary | 20:1907ef5d29bb | 231 | }if (score>10 && score<=20){ |
OmarAlebiary | 21:5c98996d1487 | 232 | pad.led(3,1.0); game_speed = 3;//1,2,3 leds on to indicate level 3 |
OmarAlebiary | 10:7323785c071c | 233 | wait(0.06); |
OmarAlebiary | 21:5c98996d1487 | 234 | }if (score>20 && score<=25){//1,2,3,4 leds on to indicate level 4 |
OmarAlebiary | 20:1907ef5d29bb | 235 | pad.led(4,1.0); game_speed = 4; |
OmarAlebiary | 10:7323785c071c | 236 | wait(0.05); |
OmarAlebiary | 21:5c98996d1487 | 237 | }if (score>25 && score<=30){//1,2,3,4,5 leds on to indicate level 5 |
OmarAlebiary | 20:1907ef5d29bb | 238 | pad.led(5,1.0); game_speed = 5; |
OmarAlebiary | 15:8a768106c297 | 239 | wait(0.04); |
OmarAlebiary | 21:5c98996d1487 | 240 | }if (score>30){//all 6 leds on to indicate level 6 |
OmarAlebiary | 20:1907ef5d29bb | 241 | pad.led(6,1.0); game_speed = 6; |
OmarAlebiary | 10:7323785c071c | 242 | wait(0.03); |
OmarAlebiary | 20:1907ef5d29bb | 243 | } |
OmarAlebiary | 21:5c98996d1487 | 244 | } |
OmarAlebiary | 9:edb39a8334ee | 245 | |
OmarAlebiary | 9:edb39a8334ee | 246 | |
OmarAlebiary | 9:edb39a8334ee | 247 | void RocketRacer::enemy_position(N5110 &lcd,int place, int phase){ |
OmarAlebiary | 14:8df7e6fced07 | 248 | |
OmarAlebiary | 21:5c98996d1487 | 249 | if (place==1){//draws the enemy sprite at position 1 |
OmarAlebiary | 28:39607fb67e88 | 250 | lcd.drawSprite(3,phase,11,9,(int *)enemy); |
OmarAlebiary | 9:edb39a8334ee | 251 | } |
OmarAlebiary | 9:edb39a8334ee | 252 | |
OmarAlebiary | 21:5c98996d1487 | 253 | if (place==2){//draws the enemy sprite at position 2 |
OmarAlebiary | 28:39607fb67e88 | 254 | lcd.drawSprite(19,phase,11,9,(int *)enemy); |
OmarAlebiary | 9:edb39a8334ee | 255 | } |
OmarAlebiary | 9:edb39a8334ee | 256 | |
OmarAlebiary | 21:5c98996d1487 | 257 | if (place==3){//draws the enemy sprite at position 3 |
OmarAlebiary | 28:39607fb67e88 | 258 | lcd.drawSprite(35,phase,11,9,(int *)enemy); |
OmarAlebiary | 9:edb39a8334ee | 259 | } |
OmarAlebiary | 9:edb39a8334ee | 260 | lcd.refresh(); |
OmarAlebiary | 9:edb39a8334ee | 261 | |
OmarAlebiary | 9:edb39a8334ee | 262 | } |
OmarAlebiary | 9:edb39a8334ee | 263 | |
OmarAlebiary | 33:24ef796ff2c8 | 264 | |
OmarAlebiary | 9:edb39a8334ee | 265 | void RocketRacer::player_position(N5110 &lcd,char RocketPosition){ |
OmarAlebiary | 9:edb39a8334ee | 266 | |
OmarAlebiary | 21:5c98996d1487 | 267 | Main_Game_Display(lcd);//displays the game screen |
OmarAlebiary | 9:edb39a8334ee | 268 | |
OmarAlebiary | 21:5c98996d1487 | 269 | if (RocketPosition==1){//places the rocket at positon 1 |
OmarAlebiary | 28:39607fb67e88 | 270 | lcd.drawSprite(3,34,11,9,(int *)rocket); |
OmarAlebiary | 9:edb39a8334ee | 271 | } |
OmarAlebiary | 21:5c98996d1487 | 272 | if (RocketPosition==2){//places the rocket at positon 2 |
OmarAlebiary | 28:39607fb67e88 | 273 | lcd.drawSprite(19,34,11,9,(int *)rocket); |
OmarAlebiary | 9:edb39a8334ee | 274 | } |
OmarAlebiary | 21:5c98996d1487 | 275 | if (RocketPosition==3){//places the rocket at positon 3 |
OmarAlebiary | 28:39607fb67e88 | 276 | lcd.drawSprite(35,34,11,9,(int *)rocket); |
OmarAlebiary | 9:edb39a8334ee | 277 | } |
OmarAlebiary | 9:edb39a8334ee | 278 | lcd.refresh(); |
OmarAlebiary | 9:edb39a8334ee | 279 | } |
OmarAlebiary | 9:edb39a8334ee | 280 | |
OmarAlebiary | 9:edb39a8334ee | 281 | |
OmarAlebiary | 12:1d3b0218d8d0 | 282 | void RocketRacer::End_Game(Gamepad &pad,N5110 &lcd){ |
OmarAlebiary | 14:8df7e6fced07 | 283 | |
OmarAlebiary | 10:7323785c071c | 284 | lcd.clear(); |
OmarAlebiary | 10:7323785c071c | 285 | char buffer1[14]; |
OmarAlebiary | 21:5c98996d1487 | 286 | //prints the gameover to the lcd with the score achieved |
OmarAlebiary | 8:b547037f42be | 287 | lcd.printString("Game over!!!",5,0); |
OmarAlebiary | 10:7323785c071c | 288 | lcd.printString("Better Luck ",2,1); |
OmarAlebiary | 10:7323785c071c | 289 | lcd.printString("next time",2,2); |
OmarAlebiary | 10:7323785c071c | 290 | lcd.printString("High score:",2,3); |
OmarAlebiary | 10:7323785c071c | 291 | sprintf(buffer1,"%d",score); |
OmarAlebiary | 10:7323785c071c | 292 | lcd.printString(buffer1,20,4); |
OmarAlebiary | 14:8df7e6fced07 | 293 | |
OmarAlebiary | 25:7e3b6df93dd5 | 294 | pad.leds_on();//turns all leds on |
OmarAlebiary | 10:7323785c071c | 295 | lcd.refresh(); |
OmarAlebiary | 28:39607fb67e88 | 296 | tones.End_Game_Melody(pad); //calling tones object to play melody |
OmarAlebiary | 7:7e50cac5e0f4 | 297 | |
OmarAlebiary | 25:7e3b6df93dd5 | 298 | |
OmarAlebiary | 28:39607fb67e88 | 299 | wait(50); |
OmarAlebiary | 25:7e3b6df93dd5 | 300 | |
OmarAlebiary | 33:24ef796ff2c8 | 301 | } |
OmarAlebiary | 25:7e3b6df93dd5 | 302 |