Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: N5110 SDFileSystem gameCharacters mbed
main.cpp
00001 /** 00002 @file main.cpp 00003 @brief Revision 1.0. 00004 @author Robin Milward Cooney 00005 @date May 2015 00006 */ 00007 00008 /* ELEC2645 Game - Shooty shooty bang bang (priliminary name) 00009 00010 Week 19 - initial version, basic testing of sensor and display 00011 00012 (c) Robni Milward Cooney Uniersity of Leeds, 06/03/16 00013 00014 */ 00015 00016 #include "main.h" 00017 00018 int main() //main function, currently used to test different functions 00019 { 00020 initialize_values(); //Call the initialize_values funtion 00021 lcd.init(); //Initialize the LCD 00022 b_A.mode(PullDown); //Declare the Pull down state of the digital in b_A 00023 b_B.mode(PullDown); //Declare the Pull down state of the digital in b_B 00024 swJoy.mode(PullDown); //Declare the Pull down state of the digital in swJoy 00025 Ticker_Menu.attach(&Ticker_Menu_isr,0.15); //Set the ticker for menus to flag every 0.15 seconds 00026 Ticker_Game.attach(&Ticker_Game_isr,0.1); //Set the ticker for the game to flag every 0.1 seconds 00027 Ticker_ds.attach(&Ticker_ds_isr,0.1); //Set the ticker for the ticker_wait funtion to flag every 0.1 seconds 00028 press_b_A.fall(&press_b_A_isr); //Set interrupt to flag when buttion A pressed 00029 press_b_A.mode(PullDown); // Declare that button A is pulldown 00030 press_b_B.fall(&press_b_B_isr); //Set interrupt to flag when buttion B pressed 00031 press_b_B.mode(PullDown); // Declare that button A is pulldown 00032 calibrateJoystick(); //Initialize the joystick, allocating a defalut possition for xJoy and yJoy 00033 intro(); //Prints the name of the game before the manin menu runs 00034 main_menu(); //Funtion that runs the main menu, the game itself it called within the main_menu() funtion 00035 } 00036 00037 00038 // ----------------------------------------------------------------------------------------------------------------------------------------- 00039 00040 // Funtion that initializes all values so when the game ends and is re_played all the variables are in there initial state 00041 void initialize_values() 00042 { 00043 00044 //the movements of all the interactive elements are arranged so they start off screen and as the value _movement values increases 00045 //they begin to appear on screen 00046 rat_movement =85; 00047 hound_hMovement =90; 00048 hound_vMovement =40; 00049 hound_jump =0; 00050 bear_movement =100; 00051 bird_hMovement =95; 00052 bird_vMovement =20; 00053 cactus_movement =110; 00054 t_rex_movement =120; 00055 quick_sand_movement =85; 00056 fire_ball_hMovement =t_rex_movement -6; 00057 fire_ball_vMovement =25; 00058 heart_movement =90; 00059 ammo_movement =100; 00060 00061 //Thenu state is reset to 0 so that the first menu option is highlited when returned to the main menu 00062 menuState =0; 00063 00064 //All action flags are re-set to 0 00065 jump_flag =0; 00066 shoot_flag =0; 00067 shield_flag =0; 00068 hound_jump_flag =0; 00069 00070 00071 //All print flags are set to 0 00072 print_rat_flag =0; 00073 print_hound_flag =0; 00074 print_bear_flag =0; 00075 print_bird_flag =0; 00076 print_heart_flag =0; 00077 print_ammo_flag =0; 00078 print_speed_boost_flag =0; 00079 print_cactus_flag =0; 00080 print_t_rex_flag =0; 00081 print_quick_sand_flag =0; 00082 print_fire_ball_flag =0; 00083 fire_on_screen =0; 00084 00085 //Score and relevant score variable are set to 0 00086 score =0; 00087 kill_score =0; 00088 shield_score =0; 00089 00090 //Other miscellaneous varaivles relevent to the game are set 00091 red_led = 1; 00092 green_led=1; 00093 i =0; 00094 g_shoot_loop =0; 00095 recks_movement =2; 00096 fall =37; 00097 g_jump =36; 00098 accel =0; 00099 bullet =9; 00100 h_movement =0; 00101 ammo =24; 00102 lose_lives_delay_flag =0; 00103 lives_delay_loop =0; 00104 lives =4; 00105 bear_lives =0; 00106 shield_counter =0; 00107 00108 } 00109 00110 //Funtion that uses a ticker to create a ticker based wait() funtion, less power consumtion then normal wait() funtion 00111 //Input t in 0.1*number of seconds to wait 00112 void ticker_wait(int t) 00113 { 00114 for (int q=0; q<=t; q++) { //for loop stops when q<=t 00115 if (g_Ticker_ds_flag ) { //ticker_ds_flag flags every 0.1seconds 00116 g_Ticker_ds_flag =0; 00117 q++; //q increases every loop until q=t 00118 } 00119 sleep(); //puts mbed to sleep 00120 } 00121 } 00122 00123 //Funtion that reads the story_progress variable form the SD card 00124 void readSD_progress() 00125 { 00126 Progress=fopen("/sd/Progress.txt", "r"); //Opens the file Progress.txt (read only) 00127 if (Progress!=NULL) { //If file exists 00128 green_led=0; //Turn green led on mbed on 00129 fscanf(Progress,"%d, ",&story_progress ); //Retrive the story_progress variable 00130 fclose(Progress); //Close the file Progress.txt 00131 ticker_wait(5); //wait 0.5s 00132 green_led=1; //Turn green led on mbed off 00133 } else { //If flie doesn't exist 00134 red_led=0; //Turn red led on mebed on 00135 ticker_wait(5); //wait 0.5s 00136 red_led=1; //Turn red led on mebed off 00137 } 00138 } 00139 00140 //Funtion that reads the story_progress variable on the SD card 00141 void writeSD_progress() 00142 { 00143 Progress=fopen("/sd/Progress.txt", "w"); //Opens the file Progress.txt (write) 00144 if (Progress!=NULL) { //If file exists 00145 green_led=0; //Turn green led on mbed on 00146 fprintf(Progress,"%d, ",story_progress ); //Write the story_progress variable to the file 00147 fclose(Progress); //Close the file Progress.txt 00148 ticker_wait(5); //wait 0.5s 00149 green_led=1; //Turn red led on mebed off 00150 } else { //If the file doesn't exist 00151 red_led=0; //Turn red led on mebed on 00152 ticker_wait(5); //wait 0.5s 00153 red_led=1; //Turn red led on mebed off 00154 } 00155 } 00156 00157 //Funtion that reads and prints the g_top_score[6] array on the SD card and prints the higest 5 values 00158 //on the LCD 00159 void readSD_and_print_top_score() 00160 { 00161 Highscores=fopen("/sd/Highscores.txt", "r"); //Opens the file Highscores.txt (read only) from SD card 00162 if (Highscores!=NULL) { //If file exists 00163 green_led=0; //Turn green led on mbed on 00164 ticker_wait(3); //wait 0.3s 00165 green_led=1; //Turn green led on mbed oFF 00166 for (int j=0; j<=5; j++) { //Go through all the values of the array and reads them 00167 fscanf(Highscores,"%d, ",&g_top_scores [j]); 00168 } 00169 lcd.printString("Highscores:",0,0); //Prints Highscores 00170 for (int j=1; j<=5; j++) { //Goes through the top 5 values 00171 char buffer[14]; //Declares buffer to store the values of the g_top_score array 00172 int temp = sprintf(buffer,"%d",g_top_scores [j]); //Stores them in the buffer 00173 lcd.printString(buffer,12,j); //Prints the values on the LCD screen in order 00174 } 00175 fclose(Highscores); //Close Highscores file 00176 } else { //If the file doesn't exist 00177 red_led=0; //Turn the red led on mbed off 00178 ticker_wait(3); //wait 0.3s 00179 red_led=1; //Turn the red led on mebed off 00180 lcd.printString("NO HIGHSCORES",3,2); //Print error message on LCD 00181 lcd.printString("SET YET!!",18,3); 00182 } 00183 } 00184 00185 00186 //Funtion that writes the highscore[6] array on the SD 00187 void writeSD() 00188 { 00189 Highscores=fopen("/sd/Highscores.txt", "w"); //Opens the file Highscores.txt (write only) from SD card 00190 if (Highscores!=NULL) { //If file exists 00191 green_led=0; //Turn green led on mbed on 00192 ticker_wait(3); //wait 0.3s 00193 green_led=1; //Turn green led on mbed off 00194 for (int j=0; j<=5; j++) { //Goes through the all values 00195 fprintf(Highscores,"%d, ",g_top_scores [j]); //Retrive the g_top_score array 00196 } 00197 fclose(Highscores); //Close file 00198 } else { //If file doesn't exists 00199 red_led=0; //Turns red led on 00200 ticker_wait(3); //Waits 0.3s 00201 red_led=1; //Turns red led off 00202 } 00203 } 00204 00205 //Funtion that deletes a file 00206 void delete_file(char filename[]) 00207 { 00208 lcd.printString("Deleting file",0,1); //print deleting file 00209 ticker_wait(5); //wait 05s 00210 FILE *fp = fopen(filename, "r"); // try and open file 00211 if (fp != NULL) { // if it does open... 00212 fclose(fp); // close it 00213 remove(filename); // and then delete 00214 lcd.printString("Done!",0,5); 00215 ticker_wait(10); 00216 } 00217 // if we can't open it, it doesn't exist and so we can't delete it 00218 lcd.refresh(); 00219 } 00220 00221 void Delete_Highscores() 00222 { 00223 lcd.clear(); //Clear all the pixels on the LCD screen 00224 while (1) { 00225 if (g_Ticker_Menu_flag ) { //ticker flags every 0.15s 00226 g_Ticker_Menu_flag =0; 00227 lcd.printString("Delete all",0,2); 00228 lcd.printString("high scores?",0,3); 00229 if (b_A==1) { //if dlete highscores is selected 00230 lcd.clear(); //Clear all the pixels on the LCD screen 00231 while (1) { 00232 if (g_Ticker_Menu_flag ) { 00233 g_Ticker_Menu_flag =0; 00234 lcd.printString("Are you sure?",0,1); //Print are you sure message 00235 if (b_A==1) { //Are you sure is selected 00236 lcd.clear(); //Clear all the pixels on the LCD screen 00237 delete_file("/sd/Highscores.txt"); //deletes the file 00238 return; 00239 } else if (b_B==1) { //If it's not, returns to the main menu 00240 return; 00241 } 00242 } 00243 lcd.refresh(); 00244 sleep(); //puts mbed to sleep 00245 } 00246 } else if (b_B==1) { //If it's not, returns to the main menu 00247 return; 00248 } 00249 } 00250 lcd.refresh(); 00251 sleep(); //puts mbed to sleep 00252 } 00253 } 00254 00255 //Sorts all the top scores in descending order 00256 void sort_top_scores() 00257 { 00258 g_top_scores [5]=score ; //The 5 element is equal to the score 00259 int temp; 00260 for (int j=0; j<=5; j++) { //for each array element 00261 for (int n=1; n<=5; n++) { //for each array element+1 (except for when the array element=5 as there is no further one) 00262 if (g_top_scores [j]>g_top_scores [n]) { //if array element is greater then the next element 00263 temp = g_top_scores [j]; //store the element 00264 g_top_scores [j] = g_top_scores [n]; //make the element equal to the next element 00265 g_top_scores [n] = temp; //stores element equals the nest elememnt 00266 } 00267 } 00268 } 00269 } 00270 00271 00272 //Funtion that plays the song1 00273 void play_music() 00274 { 00275 tOut.attach(&music_tOut, (song1[0]/2)); //the note will play for the the ammount of time specified in the first 00276 //element of the song1 00277 PWM.period (1.0/1000); //sets the frequancy to 1kHz 00278 PWM.write(0.0); //Changes the time that the buzzer is on to 0 00279 if (song1[g_music_count ]!=0) { //Checks if there is a note to be played at a ceratain position in the song1 array 00280 PWM.period(1/(song1[g_music_count ])); //Sets the period to the corret frequency from the song array 00281 PWM.write(0.5); //Changes PWM to square wave 00282 } 00283 if (g_music_count <(sizeof(song1)/sizeof(song1[1]))) { //If the current count of the music is less then the array size 00284 g_music_count ++; //increases the music line by one 00285 } else { 00286 g_music_count =1; //otherwise it sets it back to one 00287 } 00288 } 00289 00290 00291 //Generates a random number between 0 and 9999 00292 void generate_random_number() 00293 { 00294 time_t seconds = time(NULL); //Get time in seconds from mbed 00295 srand(seconds); //Use time as soucre for srand() funtion 00296 random_num =rand()%10000; //create random number between 1 and 9999 00297 } 00298 00299 //Converts the socre value so it can be dysplayed as a bar 00300 void led_bar() 00301 { 00302 led=pow(2,lives )-1; //lives^2 -1 will turn all the led on thats the value of lives 00303 if (lives >5) { //the value of lives cannot exceed 5 00304 lives =5; 00305 } 00306 } 00307 00308 00309 void ground() //funtion to print the ground 00310 { 00311 for (int x = 0; x<=84 ; x++) { 00312 lcd.setPixel(x,47); //prints a line 84 pixels long at the bottom of the screen 00313 } 00314 } 00315 00316 /* 00317 ==========================EXAMPLE OF PRINTING FUNTION=========================== 00318 00319 THIS EXAMPLE CODE APPLIES FOR ALL THE "print_" FUNTIONS 00320 00321 //Prints the item on the LCD screen 00322 void print_item() 00323 { 00324 //Goes through all the columns in the g_item array 00325 for (int c=0; c<=(1-g_item number of columns in array); c++) { 00326 //Goes through all the rows in the g_item array 00327 for (int r=0; r<=(1-g_item number of rows in array);r++) { 00328 //if the element of the g_item array corresponding to row r and column c is o 00329 if (g_item[r][c]==0) { 00330 // then the pixel is checked, this is to allow arrays to overlap. If the checked pixel = 1 00331 //then the pixel is set rather then cleared, however if it's 0 then it is cleared 00332 //the location on the LCD that the item is printed is dependant on the 2 global variables 00333 //item_hMovement (contolles the horizontal possition) and item_vMovement (contolles the 00334 //vertical movemrnt). If either of those values are constants it means that the 00335 //vertical/horizontal displacement of the object is constant 00336 if (lcd.getPixel(c+item_hMovement,r+item_vMovement)!=0) { 00337 lcd.setPixel(c+item_hMovement,r+item_vMovement); 00338 } else { 00339 lcd.clearPixel(c+item_hMovement,r+item_vMovement); 00340 } 00341 //else if the array element g_item[r][c] is 1 then the pixel is set no matter what 00342 } else if (g_item[r][c]==1) { 00343 lcd.setPixel(c+item_hMovement,r+item_vMovement); 00344 } 00345 } 00346 } 00347 } 00348 ================================================================================ 00349 */ 00350 00351 //Funtion that prints the heart pickup 00352 void print_heart() 00353 { 00354 for(int c=0; c<=4; c++) { //4 beacause the the loop stats from 0 but the array size from 1 00355 for(int r=0; r<=4; r++) { 00356 if (g_heart[r][c]==0) { 00357 if (lcd.getPixel(c+heart_movement ,r+35)!=0) { 00358 lcd.setPixel(c+heart_movement ,r+35); 00359 } else { 00360 lcd.clearPixel(c+heart_movement ,r+35); 00361 } 00362 } else if (g_heart[r][c]==1) { 00363 lcd.setPixel(c+heart_movement ,r+35); 00364 } 00365 } 00366 } 00367 } 00368 00369 //Funtion that prints the ammo pickup 00370 void print_ammo_pickUp() 00371 { 00372 for(int c=0; c<=6; c++) { //6 beacause the the loop stats from 0 but the array size from 1 00373 for(int r=0; r<=7; r++) { 00374 if (g_ammo_pickUp[r][c]==0) { 00375 if (lcd.getPixel(c+ammo_movement ,r+35)!=0) { 00376 lcd.setPixel(c+ammo_movement ,r+35); 00377 } else { 00378 lcd.clearPixel(c+ammo_movement ,r+35); 00379 } 00380 } else if (g_ammo_pickUp[r][c]==1) { 00381 lcd.setPixel(c+ammo_movement ,r+35); 00382 } 00383 } 00384 } 00385 } 00386 00387 //Funtion that prints the speed boost pickup 00388 void print_speed_boost() 00389 { 00390 for (int c=0; c<=13; c++) { 00391 for (int r=0; r<=6; r++) { 00392 if (g_speed_boost[r][c]==0) { 00393 if (lcd.getPixel(c+speed_boost_movement ,r+38)!=0) { 00394 lcd.setPixel(c+speed_boost_movement ,r+38); 00395 } else { 00396 lcd.clearPixel(c+speed_boost_movement ,r+38); 00397 } 00398 } else if (g_speed_boost[r][c]==1) { 00399 lcd.setPixel(c+speed_boost_movement ,r+38); 00400 } 00401 } 00402 } 00403 } 00404 //Funtion that prints recks still 00405 void print_recks_still_gun() 00406 { 00407 00408 for(int c=0; c<=9; c++) { //9 beacause the the loop stats from 0 but the array size from 1 00409 for(int r=0; r<=9; r++) { 00410 if (g_recks_still_gun[r][c]==0) { 00411 if (lcd.getPixel(c+3,r+37)!=0) { 00412 lcd.setPixel(c+3,r+37); 00413 } else { 00414 lcd.clearPixel(c+3,r+37); 00415 } 00416 } else if (g_recks_still_gun[r][c]==1) { 00417 lcd.setPixel(c+3,r+37); 00418 } 00419 } 00420 } 00421 } 00422 00423 //Funtion that prints recks moveing 00424 void print_recks_moving_gun() 00425 { 00426 00427 for(int c=0; c<=9; c++) { //9 beacause the the loop stats from 0 but the array size from 1 00428 for(int r=0; r<=9; r++) { 00429 if (g_recks_moving_gun[r][c]==0) { 00430 if (lcd.getPixel(c+3,r+37)!=0) { 00431 lcd.setPixel(c+3,r+37); 00432 } else { 00433 lcd.clearPixel(c+3,r+37); 00434 } 00435 } else if (g_recks_moving_gun[r][c]==1) { 00436 lcd.setPixel(c+3,r+37); 00437 } 00438 } 00439 } 00440 } 00441 00442 //Funtion that prints recks crouching 00443 void print_recks_crouch_gun() 00444 { 00445 for(int c=0; c<=9; c++) { //9 beacause the the loop stats from 0 but the array size from 1 00446 for(int r=0; r<=9; r++) { 00447 if (g_recks_crouch_gun[r][c]==0) { 00448 if (lcd.getPixel(c+3,r+37)!=0) { 00449 lcd.setPixel(c+3,r+37); 00450 } else { 00451 lcd.clearPixel(c+3,r+37); 00452 } 00453 } else if (g_recks_crouch_gun[r][c]==1) { 00454 lcd.setPixel(c+3,r+37); 00455 } 00456 } 00457 } 00458 } 00459 00460 //Funtion that prints recks with the shield 00461 void print_recks_shield() 00462 { 00463 for(int c=0; c<=14; c++) { 00464 for(int r=0; r<=14; r++) { 00465 if (g_recks_shield[r][c]==0) { 00466 if (lcd.getPixel(c,r+33)!=0) { 00467 lcd.setPixel(c,r+33); 00468 } else { 00469 lcd.clearPixel(c,r+33); 00470 } 00471 } else if (g_recks_shield[r][c]==1) { 00472 lcd.setPixel(c,r+33); 00473 } 00474 } 00475 } 00476 } 00477 00478 //Funtion that prints recks in the jumping position 00479 void print_recks_jump_gun() 00480 { 00481 for(int c=0; c<=9; c++) { //9 beacause the the loop stats from 0 but the array size from 1 00482 for(int r=0; r<=9; r++) { 00483 if (g_recks_jump_gun[r][c]==0) { 00484 if (lcd.getPixel(c+3,r+g_jump )!=0) { 00485 lcd.setPixel(c+3,r+g_jump ); 00486 } else { 00487 lcd.clearPixel(c+3,r+g_jump ); 00488 } 00489 } else if (g_recks_jump_gun[r][c]==1) { 00490 lcd.setPixel(c+3,r+g_jump ); 00491 } 00492 } 00493 } 00494 } 00495 00496 //Funtion that recks falling (different to recks still because vertical movement is variable) 00497 void print_recks_falling() 00498 { 00499 for(int c=0; c<=9; c++) { //9 beacause the the loop stats from 0 but the array size from 1 00500 for(int r=0; r<=9; r++) { 00501 if (g_recks_still_gun[r][c]==0) { 00502 if (lcd.getPixel(c+3,r+fall )!=0) { 00503 lcd.setPixel(c+3,r+fall ); 00504 } else { 00505 lcd.clearPixel(c+3,r+fall ); 00506 } 00507 } else if (g_recks_still_gun[r][c]==1) { 00508 lcd.setPixel(c+3,r+fall ); 00509 } 00510 } 00511 } 00512 } 00513 00514 //Funtion that prints the rat in position 1 00515 void print_mob_rat_p1() 00516 { 00517 for(int c=0; c<=7; c++) { // 7 beacause the the loop stats from 0 but the array size from 1 00518 for(int r=0; r<=2; r++) { 00519 if (g_mob_rat_p1[r][c]==0) { 00520 if (lcd.getPixel(c+rat_movement ,r+44)!=0) { 00521 lcd.setPixel(c+rat_movement ,r+44); 00522 } else { 00523 lcd.clearPixel(c+rat_movement ,r+44); 00524 } 00525 } else if (g_mob_rat_p1[r][c]==1) { 00526 lcd.setPixel(c+rat_movement ,r+44); 00527 } 00528 } 00529 } 00530 } 00531 00532 //Funtion that prints the rat in position 2 00533 void print_mob_rat_p2() 00534 { 00535 for(int c=0; c<=7; c++) { // 7 beacause the the loop stats from 0 but the array size from 1 00536 for(int r=0; r<=2; r++) { 00537 if (g_mob_rat_p2[r][c]==0) { 00538 if (lcd.getPixel(c+rat_movement ,r+44)!=0) { 00539 lcd.setPixel(c+rat_movement ,r+44); 00540 } else { 00541 lcd.clearPixel(c+rat_movement ,r+44); 00542 } 00543 } else if (g_mob_rat_p2[r][c]==1) { 00544 lcd.setPixel(c+rat_movement ,r+44); 00545 } 00546 } 00547 } 00548 } 00549 00550 //Funtion that prints the still hound 00551 void print_mob_hound_p1() 00552 { 00553 for(int c=0; c<=12; c++) { // 12 beacause the the loop stats from 0 but the array size from 1 00554 for(int r=0; r<=7; r++) { 00555 if (g_mob_hound_p1[r][c]==0) { 00556 if (lcd.getPixel(c+hound_hMovement ,r+hound_vMovement )!=0) { 00557 lcd.setPixel(c+hound_hMovement ,r+hound_vMovement ); 00558 } else { 00559 lcd.clearPixel(c+hound_hMovement ,r+hound_vMovement ); 00560 } 00561 } else if (g_mob_hound_p1[r][c]==1) { 00562 lcd.setPixel(c+hound_hMovement ,r+hound_vMovement ); 00563 } 00564 } 00565 } 00566 } 00567 00568 //Funtion that prints the moving hound 00569 void print_mob_hound_p2() 00570 { 00571 for(int c=0; c<=12; c++) { // 12 beacause the the loop stats from 0 but the array size from 1 00572 for(int r=0; r<=7; r++) { 00573 if (g_mob_hound_p2[r][c]==0) { 00574 if (lcd.getPixel(c+hound_hMovement ,r+hound_vMovement )!=0) { 00575 lcd.setPixel(c+hound_hMovement ,r+hound_vMovement ); 00576 } else { 00577 lcd.clearPixel(c+hound_hMovement ,r+hound_vMovement ); 00578 } 00579 } else if (g_mob_hound_p2[r][c]==1) { 00580 lcd.setPixel(c+hound_hMovement ,r+hound_vMovement ); 00581 } 00582 } 00583 } 00584 } 00585 00586 //Funtion that prints the dead hound 00587 void print_mob_hound_dead() 00588 { 00589 for(int c=0; c<=12; c++) { // 12 beacause the the loop stats from 0 but the array size from 1 00590 for(int r=0; r<=7; r++) { 00591 if (g_mob_hound_dead[r][c]==0) { 00592 if (lcd.getPixel(c+hound_hMovement ,r+hound_vMovement )!=0) { 00593 lcd.setPixel(c+hound_hMovement ,r+hound_vMovement ); 00594 } else { 00595 lcd.clearPixel(c+hound_hMovement ,r+hound_vMovement ); 00596 } 00597 } else if (g_mob_hound_dead[r][c]==1) { 00598 lcd.setPixel(c+hound_hMovement ,r+hound_vMovement ); 00599 } 00600 } 00601 } 00602 } 00603 00604 //Funtion to print the still bear (position 1) on the LCD 00605 void print_mob_bear_p1() 00606 { 00607 for(int c=0; c<=18; c++) { //18 beacause the the loop stats from 0 but the array size from 1 00608 for(int r=0; r<=9; r++) { 00609 if (g_mob_bear_p1[r][c]==0) { 00610 if (lcd.getPixel(c+bear_movement ,r+37)!=0) { 00611 lcd.setPixel(c+bear_movement ,r+37); 00612 } else { 00613 lcd.clearPixel(c+bear_movement ,r+37); 00614 } 00615 } else if (g_mob_bear_p1[r][c]==1) { 00616 lcd.setPixel(c+bear_movement ,r+37); 00617 } 00618 } 00619 } 00620 } 00621 00622 //Funtion to print the moving bear (position 2) on the LCD 00623 void print_mob_bear_p2() 00624 { 00625 for(int c=0; c<=18; c++) { //18 beacause the the loop stats from 0 but the array size from 1 00626 for(int r=0; r<=9; r++) { 00627 if (g_mob_bear_p2[r][c]==0) { 00628 if (lcd.getPixel(c+bear_movement ,r+37)!=0) { 00629 lcd.setPixel(c+bear_movement ,r+37); 00630 } else { 00631 lcd.clearPixel(c+bear_movement ,r+37); 00632 } 00633 } else if (g_mob_bear_p2[r][c]==1) { 00634 lcd.setPixel(c+bear_movement ,r+37); 00635 } 00636 } 00637 } 00638 } 00639 00640 //Funtion to print the dead bear 00641 void print_mob_bear_dead() 00642 { 00643 for(int c=0; c<=18; c++) { //18 beacause the the loop stats from 0 but the array size from 1 00644 for(int r=0; r<=9; r++) { 00645 if (g_mob_bear_dead[r][c]==0) { 00646 if (lcd.getPixel(c+bear_movement ,r+37)!=0) { 00647 lcd.setPixel(c+bear_movement ,r+37); 00648 } else { 00649 lcd.clearPixel(c+bear_movement ,r+37); 00650 } 00651 } else if (g_mob_bear_dead[r][c]==1) { 00652 lcd.setPixel(c+bear_movement ,r+37); 00653 } 00654 } 00655 } 00656 } 00657 00658 //Funtion to print the moving (position 1) bird on the LCD 00659 void print_mob_bird_p1() 00660 { 00661 for(int c=0; c<=9; c++) { //9 beacause the the loop stats from 0 but the array size from 1 00662 for(int r=0; r<=9; r++) { 00663 if (g_mob_bird_p1[r][c]==0) { 00664 if (lcd.getPixel(c+bird_hMovement ,r+bird_vMovement )!=0) { 00665 lcd.setPixel(c+bird_hMovement ,r+bird_vMovement ); 00666 } else { 00667 lcd.clearPixel(c+bird_hMovement ,r+bird_vMovement ); 00668 } 00669 } else if (g_mob_bird_p1[r][c]==1) { 00670 lcd.setPixel(c+bird_hMovement ,r+bird_vMovement ); 00671 } 00672 } 00673 } 00674 } 00675 00676 //Funtion to print the moving (position 2) bird on the LCD 00677 void print_mob_bird_p2() 00678 { 00679 for(int c=0; c<=9; c++) { //9 beacause the the loop stats from 0 but the array size from 1 00680 for(int r=0; r<=9; r++) { 00681 if (g_mob_bird_p2[r][c]==0) { 00682 if (lcd.getPixel(c+bird_hMovement ,r+bird_vMovement )!=0) { 00683 lcd.setPixel(c+bird_hMovement ,r+bird_vMovement ); 00684 } else { 00685 lcd.clearPixel(c+bird_hMovement ,r+bird_vMovement ); 00686 } 00687 } else if (g_mob_bird_p2[r][c]==1) { 00688 lcd.setPixel(c+bird_hMovement ,r+bird_vMovement ); 00689 } 00690 } 00691 } 00692 } 00693 00694 //Funtion to print the dead bird on the LCD 00695 void print_mob_bird_dead() 00696 { 00697 for(int c=0; c<=9; c++) { //9 beacause the the loop stats from 0 but the array size from 1 00698 for(int r=0; r<=9; r++) { 00699 if (g_mob_bird_dead[r][c]==0) { 00700 lcd.clearPixel(c+bird_hMovement ,r+bird_vMovement ); 00701 } else if (g_mob_bird_dead[r][c]==1) { 00702 lcd.setPixel(c+bird_hMovement ,r+bird_vMovement ); 00703 } 00704 } 00705 } 00706 } 00707 00708 //Funtion to print the cactus 00709 void print_cactus() 00710 { 00711 for(int c=0; c<=4; c++) { //4 beacause the the loop stats from 0 but the array size from 1 00712 for(int r=0; r<=11; r++) { 00713 if (g_cactus[r][c]==0) { 00714 if (lcd.getPixel(c+cactus_movement ,r+35)!=0) { 00715 lcd.setPixel(c+cactus_movement ,r+35); 00716 } else { 00717 lcd.clearPixel(c+cactus_movement ,r+35); 00718 } 00719 } else if (g_cactus[r][c]==1) { 00720 lcd.setPixel(c+cactus_movement ,r+35); 00721 } 00722 } 00723 } 00724 } 00725 00726 //Funtion to print the quick sand 00727 void print_quick_sand() 00728 { 00729 for(int x=0; x<=16; x++) { 00730 lcd.setPixel(x+quick_sand_movement ,46); 00731 } 00732 } 00733 00734 //Funtion to print the T Rex still 00735 void print_t_rex() 00736 { 00737 for(int c=0; c<=24; c++) { //24 beacause the the loop stats from 0 but the array size from 1 00738 for(int r=0; r<=27; r++) { 00739 if (g_t_rex[r][c]==0) { 00740 if (lcd.getPixel(c+t_rex_movement ,r+19)!=0) { 00741 lcd.setPixel(c+t_rex_movement ,r+19); 00742 } else { 00743 lcd.clearPixel(c+t_rex_movement ,r+19); 00744 } 00745 } else if (g_t_rex[r][c]==1) { 00746 lcd.setPixel(c+t_rex_movement ,r+19); 00747 } 00748 } 00749 } 00750 } 00751 00752 //Funtion to print the T Rex moving 00753 void print_t_rex_moving() 00754 { 00755 for(int c=0; c<=24; c++) { //24 beacause the the loop stats from 0 but the array size from 1 00756 for(int r=0; r<=27; r++) { 00757 if (g_t_rex_moving[r][c]==0) { 00758 if (lcd.getPixel(c+t_rex_movement ,r+19)!=0) { 00759 lcd.setPixel(c+t_rex_movement ,r+19); 00760 } else { 00761 lcd.clearPixel(c+t_rex_movement ,r+19); 00762 } 00763 } else if (g_t_rex_moving[r][c]==1) { 00764 lcd.setPixel(c+t_rex_movement ,r+19); 00765 } 00766 } 00767 } 00768 } 00769 00770 //Funtion to print the T Rex attack 00771 void print_t_rex_attack() 00772 { 00773 for(int c=0; c<=24; c++) { //24 beacause the the loop stats from 0 but the array size from 1 00774 for(int r=0; r<=27; r++) { 00775 if (g_t_rex_attack[r][c]==0) { 00776 if (lcd.getPixel(c+t_rex_movement ,r+19)!=0) { 00777 lcd.setPixel(c+t_rex_movement ,r+19); 00778 } else { 00779 lcd.clearPixel(c+t_rex_movement ,r+19); 00780 } 00781 } else if (g_t_rex_attack[r][c]==1) { 00782 lcd.setPixel(c+t_rex_movement ,r+19); 00783 } 00784 } 00785 } 00786 } 00787 00788 //Funtion to print the fire ball (position 1) 00789 void print_fire_ball_p1() 00790 { 00791 for(int c=0; c<=8; c++) { //24 beacause the the loop stats from 0 but the array size from 1 00792 for(int r=0; r<=8; r++) { 00793 if (g_fire_ball_p1[r][c]==0) { 00794 if (lcd.getPixel(c+fire_ball_hMovement ,r+fire_ball_vMovement )!=0) { 00795 lcd.setPixel(c+fire_ball_hMovement ,r+fire_ball_vMovement ); 00796 } else { 00797 lcd.clearPixel(c+fire_ball_hMovement ,r+fire_ball_vMovement ); 00798 } 00799 } else if (g_fire_ball_p1[r][c]==1) { 00800 lcd.setPixel(c+fire_ball_hMovement ,r+fire_ball_vMovement ); 00801 } 00802 } 00803 } 00804 } 00805 00806 //Funtion to print the fire ball (position 2) 00807 void print_fire_ball_p2() 00808 { 00809 for(int c=0; c<=8; c++) { //24 beacause the loop stats from 0 but the array size from 1 00810 for(int r=0; r<=8; r++) { 00811 if (g_fire_ball_p2[r][c]==0) { 00812 if (lcd.getPixel(c+fire_ball_hMovement ,r+fire_ball_vMovement )!=0) { 00813 lcd.setPixel(c+fire_ball_hMovement ,r+fire_ball_vMovement ); 00814 } else { 00815 lcd.clearPixel(c+fire_ball_hMovement ,r+fire_ball_vMovement ); 00816 } 00817 } else if (g_fire_ball_p2[r][c]==1) { 00818 lcd.setPixel(c+fire_ball_hMovement ,r+fire_ball_vMovement ); 00819 } 00820 } 00821 } 00822 } 00823 00824 //Funtion to print the clouds 00825 void print_clouds() 00826 { 00827 //8 bit unsigned integer that loops round to 0 when the h_movement variable is > than 255 00828 //this means that the cloud array loops round when it finishes 00829 uint8_t clouds_movement=h_movement ; 00830 for(int c=clouds_movement; c<=clouds_movement+83; c++) { 00831 for(int r=0; r<=2; r++) { 00832 if (g_clouds[r][c]==0) { 00833 lcd.clearPixel(c-clouds_movement,r+6); 00834 } else if (g_clouds[r][c]==1) { 00835 lcd.setPixel(c-clouds_movement,r+6); 00836 } 00837 } 00838 } 00839 } 00840 00841 void print_locks() 00842 { 00843 //depending on the value of story_progress locked padlocks are printed or unlocked ones 00844 int sp=8*story_progress ; 00845 for(int c=0; c<=3; c++) { //24 beacause the the loop stats from 0 but the array size from 1 00846 for(int r=0; r<=5; r++) { 00847 for (int n=1; n<=33; n+=8) { 00848 if (g_padlock_p1[r][c]==0) { 00849 lcd.clearPixel(c+8,r+n); 00850 } else if (g_padlock_p1[r][c]==1) { 00851 lcd.setPixel(c+8,r+n); 00852 } 00853 } 00854 } 00855 } 00856 for(int c=0; c<=3; c++) { //24 beacause the the loop stats from 0 but the array size from 1 00857 for(int r=0; r<=5; r++) { 00858 for (int n=1; n<=sp; n+=8) { 00859 if (g_padlock_p2[r][c]==0) { 00860 lcd.clearPixel(c+8,r+n); 00861 } else if (g_padlock_p2[r][c]==1) { 00862 lcd.setPixel(c+8,r+n); 00863 } 00864 } 00865 } 00866 } 00867 } 00868 00869 00870 //Funtion that is called when the player walks or jumps on quick sand, Recks falls and 00871 //looses all lives 00872 void falling_animation() 00873 { 00874 while (fall <60) { 00875 if (g_Ticker_Game_flag ) { 00876 g_Ticker_Game_flag =0; 00877 print_recks_falling(); 00878 fall +=3; //vertical poition of recks increases (goes down) every loop 00879 } 00880 lcd.refresh(); 00881 sleep(); //puts mbed to sleep 00882 lcd.clear(); //Clear all the pixels on the LCD screen 00883 } 00884 } 00885 00886 //Funtion that is called before the main menu the start and dislplayes the name of the game 00887 void intro() 00888 { 00889 lcd.clear(); //clears all pixels on LCD 00890 lcd.printString("ROBOZOEC",18,2); 00891 lcd.printString("ERA",33,3); 00892 lcd.refresh(); 00893 ticker_wait(30); 00894 } 00895 00896 //Interrupt service routine for the menus ticker 00897 void Ticker_Menu_isr() 00898 { 00899 //sets the menu flag to 1 00900 g_Ticker_Menu_flag =1; 00901 } 00902 00903 //Interrupt service routine for the game ticker 00904 void Ticker_Game_isr() 00905 { 00906 //sets the menu flag to 1 00907 g_Ticker_Game_flag =1; 00908 } 00909 00910 //Interrupt service routine for the ticker_wait funtion ticker 00911 void Ticker_ds_isr() 00912 { 00913 //sets ds flag to 1 00914 g_Ticker_ds_flag =1; 00915 } 00916 00917 //Funtion that is called when the time out is timed out 00918 void music_tOut() 00919 { 00920 //Turns the note off 00921 PWM.write(0.0); 00922 } 00923 00924 //Interrupt service routine for the press_b_A interrupt 00925 void press_b_A_isr() 00926 { 00927 //sets the g_press_b_A_flag to 1 00928 g_press_b_A_flag =1; 00929 } 00930 00931 //Interrupt service routine for the press_b_B interrupt 00932 void press_b_B_isr() 00933 { 00934 //sets the g_press_b_B_flag to 1 00935 g_press_b_B_flag =1; 00936 } 00937 00938 // read default positions of the joystick to calibrate later readings 00939 void calibrateJoystick() 00940 { 00941 swJoy.mode(PullDown); 00942 // must not move during calibration 00943 joystick.x0 = xPot; // initial positions in the range 0.0 to 1.0 (0.5 if centred exactly) 00944 joystick.y0 = yPot; 00945 } 00946 void updateJoystick() 00947 { 00948 // read current joystick values relative to calibrated values (in range -0.5 to 0.5, 0.0 is centred) 00949 joystick.x = xPot - joystick.x0; 00950 joystick.y = yPot - joystick.y0; 00951 // read button state 00952 joystick.swJoy = swJoy; 00953 00954 // calculate direction depending on x,y values 00955 // tolerance allows a little lee-way in case joystick not exactly in the stated direction 00956 if ( fabs(joystick.y) < joystickTolerance && fabs(joystick.x) < joystickTolerance) { 00957 joystick.direction = CENTRE; 00958 } else if ( joystick.y > joystickTolerance && fabs(joystick.x) < joystickTolerance) { 00959 joystick.direction = UP; 00960 } else if ( joystick.y < joystickTolerance && fabs(joystick.x) < joystickTolerance) { 00961 joystick.direction = DOWN; 00962 } else if ( joystick.x > joystickTolerance && fabs(joystick.y) < joystickTolerance) { 00963 joystick.direction = LEFT; 00964 } else if ( joystick.x < joystickTolerance && fabs(joystick.y) < joystickTolerance) { 00965 joystick.direction = RIGHT; 00966 } 00967 } 00968 00969 //Funtion that prints the main menu and all other funtions are called from it 00970 void main_menu() 00971 { 00972 menuState =0; 00973 while(1) { 00974 g_press_b_A_flag =0; 00975 g_press_b_A_flag =0; 00976 if (g_Ticker_Menu_flag ) { 00977 g_Ticker_Menu_flag =0; 00978 updateJoystick(); 00979 lcd.setBrightness(brightness ); 00980 menu_select = fsm_main_menu[menuState ].menu_select; // set ouput depending on current state 00981 menuState = fsm_main_menu[menuState ].nextState[joystick.direction]; // when joystick.direction has a vaule of CENTRE/RIGHT/LEFT the state machine input is 0 when it has a value of DOWN it is 0b01 when it has a value of UP is is 0b10 00982 lcd.clear(); //Clear all the pixels on the LCD screen 00983 //Print the options on the main menu 00984 lcd.printString("Story mode",13,0); 00985 lcd.printString("Minigame",18,1); 00986 lcd.printString("Settings",18,2); 00987 lcd.printString("Leaderboard",9,3); 00988 lcd.printString("Credits",21,4); 00989 //inverts the pixels to highlight the option that would be selected if the buttion A is pressed 00990 for (int i =0; i <85; i ++) { //go through every pixel on the x axis 00991 for (int j=menu_select ; j<(menu_select +8); j++) { // go through relevant pixels on the y axis 00992 if (lcd.getPixel(i ,j)== 0) { //if the pixel is on trun it off 00993 lcd.setPixel(i ,j); 00994 } else { 00995 lcd.clearPixel(i ,j); //if the pixel is off turn it on 00996 } 00997 } 00998 } 00999 lcd.refresh(); 01000 //if the butto A is pressed with and the output of the menu fsm is 0, 8, 16, 24, 32 01001 if (b_A & menu_select ==0) { 01002 //calls story mode function 01003 Story_Mode(); 01004 } else if (b_A & menu_select ==8) { 01005 //calls game function 01006 Game(); 01007 } else if (b_A & menu_select ==16) { 01008 //calls settings function 01009 Settings(); 01010 } else if (b_A & menu_select ==24) { 01011 //calls leaderboard function and after it turns the mbes leds off 01012 Leaderboard(); 01013 red_led=1; 01014 green_led=1; 01015 } else if (b_A & menu_select ==32) { 01016 //calls the credits funtion 01017 Credits(); 01018 } 01019 //CHEAT CODE that unlocks all the story mode chapters 01020 //CODE: joystick LEFT, button swJoy and button b_B at the same time 01021 if (joystick.direction==LEFT&swJoy==1&b_B==1) { 01022 story_progress =5; 01023 writeSD_progress(); 01024 //Led turns on and off to show that the code was sucessfull 01025 green_led=0; 01026 ticker_wait(5); 01027 green_led=1; 01028 } 01029 } 01030 sleep(); //puts mbed to sleep 01031 } 01032 } 01033 01034 //Function that runs the game, when this funtion runs the game has no end 01035 void Minigame() 01036 { 01037 ticker_wait(5); //wait 0.5s 01038 while (1) { 01039 if (g_Ticker_Game_flag ) { 01040 g_Ticker_Game_flag =0; 01041 lcd.clear(); //Clear all the pixels on the LCD screen 01042 updateJoystick(); 01043 Game(); //run the came 01044 01045 } 01046 lcd.refresh(); 01047 sleep(); //puts mbed to sleep 01048 } 01049 } 01050 01051 //Function that runs story mode menu 01052 void Story_Mode() 01053 { 01054 menuState =0; 01055 story_mode_flag =1; //if this =1 the game funtion will end at different score levels depending on chapter 01056 led=0; 01057 readSD_progress(); 01058 while(1) { 01059 if (g_Ticker_Menu_flag ) { 01060 g_Ticker_Menu_flag =0; 01061 updateJoystick(); 01062 lcd.setBrightness(brightness ); 01063 menu_select = fsm_main_menu[menuState ].menu_select; // set ouput depending on current state 01064 menuState = fsm_main_menu[menuState ].nextState[joystick.direction]; // when joystick.direction has a vaule of CENTRE/RIGHT/LEFT the state machine input is 0 when it has a value of DOWN it is 0b01 when it has a value of UP is is 0b10 01065 lcd.clear(); //Clear all the pixels on the LCD screen 01066 //prints the locks displaying what chapters are unlocked 01067 print_locks(); 01068 //prints the chapters 01069 lcd.printString("Tutorial",20,0); 01070 lcd.printString("Chapter 1",20,1); 01071 lcd.printString("Chapter 2",20,2); 01072 lcd.printString("Chapter 3",20,3); 01073 lcd.printString("Chapter 4",20,4); 01074 for (int i =0; i <85; i ++) { //go through every pixel on the x axis 01075 for (int j=menu_select ; j<(menu_select +8); j++) { // go through relevant pixels on the y axis 01076 if (lcd.getPixel(i ,j)== 0) { //if the pixel is on trun it off 01077 lcd.setPixel(i ,j); 01078 } else { 01079 lcd.clearPixel(i ,j); //if the pixel is off turn it on 01080 } 01081 } 01082 } 01083 lcd.refresh(); 01084 //selects chapter depending on the button A, the output of the menu fst and whether it is unlocked 01085 if (b_A & menu_select ==0&story_progress >=1) { 01086 Tutorial(); 01087 } else if (b_A & menu_select ==8&story_progress >=2) { 01088 Chapter1(); 01089 } else if (b_A & menu_select ==16&story_progress >=3) { 01090 Chapter2(); 01091 } else if (b_A & menu_select ==24&story_progress >=4) { 01092 Chapter3(); 01093 } else if (b_A & menu_select ==32&story_progress >=5) { 01094 Chapter4(); 01095 } 01096 //if button b_B is presses it returns to the main menu clearing the story mode flag 01097 if (b_B) { 01098 menuState =0; 01099 story_mode_flag =0; 01100 return; 01101 } 01102 } 01103 sleep(); //puts mbed to sleep 01104 } 01105 } 01106 01107 01108 //Funtion that introduces the game and the controls to the user 01109 void Tutorial() 01110 { 01111 //prints message 01112 lcd.clear(); //Clear all the pixels on the LCD screen 01113 lcd.printString("Welcome to",0,0); 01114 lcd.printString("boot camp",0,1); 01115 lcd.printString("soldier",0,2); 01116 lcd.printString("Press A >>",24,5); 01117 lcd.refresh(); 01118 ticker_wait(10); 01119 g_press_b_A_flag =0; 01120 //when b_A is pressed it exits the while loop continueing to the next printed message 01121 while (1) { 01122 if (g_press_b_A_flag ) { 01123 g_press_b_A_flag =0; 01124 break; 01125 } 01126 sleep(); //puts mbed to sleep 01127 } 01128 //print message 01129 lcd.clear(); //Clear all the pixels on the LCD screen 01130 lcd.printString("Are you ready",0,0); 01131 lcd.printString("to begin your",0,1); 01132 lcd.printString("training?",0,2); 01133 lcd.printString("Press A >>",24,5); 01134 lcd.refresh(); 01135 ticker_wait(10); 01136 g_press_b_A_flag =0; 01137 while (1) { 01138 if (g_press_b_A_flag ) { 01139 g_press_b_A_flag =0; 01140 break; 01141 } 01142 sleep(); //puts mbed to sleep 01143 } 01144 lcd.clear(); //Clear all the pixels on the LCD screen 01145 lcd.printString("Okay use",0,0); 01146 lcd.printString("joysick to",0,1); 01147 lcd.printString("move right and",0,2); 01148 lcd.printString("left to...",0,3); 01149 lcd.printString("Press A >>",24,5); 01150 lcd.refresh(); 01151 ticker_wait(10); 01152 g_press_b_A_flag =0; 01153 while (1) { 01154 if (g_press_b_A_flag ) { 01155 g_press_b_A_flag =0; 01156 break; 01157 } 01158 sleep(); //puts mbed to sleep 01159 } 01160 lcd.clear(); //Clear all the pixels on the LCD screen 01161 lcd.printString("... move",0,0); 01162 lcd.printString("forwards and",0,1); 01163 lcd.printString("backwards.",0,2); 01164 lcd.printString("Understand?",0,3); 01165 lcd.printString("Yes Sir!>>",22,5); 01166 lcd.refresh(); 01167 ticker_wait(10); 01168 g_press_b_A_flag =0; 01169 while (1) { 01170 if (g_press_b_A_flag ) { 01171 g_press_b_A_flag =0; 01172 break; 01173 } 01174 sleep(); //puts mbed to sleep 01175 } 01176 lcd.clear(); //Clear all the pixels on the LCD screen 01177 lcd.printString("Now you try...",0,0); 01178 lcd.printString("Okay!>>",30,5); 01179 lcd.refresh(); 01180 ticker_wait(10); 01181 g_press_b_A_flag =0; 01182 while (1) { 01183 if (g_press_b_A_flag ) { 01184 g_press_b_A_flag =0; 01185 break; 01186 } 01187 sleep(); //puts mbed to sleep 01188 } 01189 //sets the difficulty to -1, no interactive elements in the game 01190 //this allows the player to try the game contolls 01191 difficulty =-1; 01192 Game(); 01193 lcd.clear(); //Clear all the pixels on the LCD screen 01194 lcd.printString("Good!!!",0,0); 01195 lcd.printString("Now lets try",0,1); 01196 lcd.printString("jumping. To",0,2); 01197 lcd.printString("jump press B",0,3); 01198 lcd.printString("Press A>>",24,5); 01199 lcd.refresh(); 01200 ticker_wait(10); 01201 g_press_b_A_flag =0; 01202 while (1) { 01203 if (g_press_b_A_flag ) { 01204 g_press_b_A_flag =0; 01205 break; 01206 } 01207 sleep(); //puts mbed to sleep 01208 } 01209 //sets the difficulty to -1, no interactive elements in the game 01210 //this allows the player to try the game contolls 01211 difficulty =-1; 01212 Game(); 01213 lcd.clear(); //Clear all the pixels on the LCD screen 01214 lcd.printString("You can also",0,0); 01215 lcd.printString("crouch if you",0,1); 01216 lcd.printString("move your",0,2); 01217 lcd.printString("joystick down",0,3); 01218 lcd.printString("Press A>>",24,5); 01219 lcd.refresh(); 01220 ticker_wait(10); 01221 g_press_b_A_flag =0; 01222 while (1) { 01223 if (g_press_b_A_flag ) { 01224 g_press_b_A_flag =0; 01225 break; 01226 } 01227 sleep(); //puts mbed to sleep 01228 } 01229 lcd.clear(); //Clear all the pixels on the LCD screen 01230 lcd.printString("And if you",0,0); 01231 lcd.printString("move the joy-",0,1); 01232 lcd.printString("stick up you",0,2); 01233 lcd.printString("will activate",0,3); 01234 lcd.printString("Press A>>",24,5); 01235 lcd.refresh(); 01236 ticker_wait(10); 01237 g_press_b_A_flag =0; 01238 while (1) { 01239 if (g_press_b_A_flag ) { 01240 g_press_b_A_flag =0; 01241 break; 01242 } 01243 sleep(); //puts mbed to sleep 01244 } 01245 lcd.clear(); //Clear all the pixels on the LCD screen 01246 lcd.printString("your shield,",0,0); 01247 lcd.printString("this will",0,1); 01248 lcd.printString("protect you",0,2); 01249 lcd.printString("for 1 sec but",0,3); 01250 lcd.printString("Press A>>",24,5); 01251 lcd.refresh(); 01252 ticker_wait(10); 01253 g_press_b_A_flag =0; 01254 while (1) { 01255 if (g_press_b_A_flag ) { 01256 g_press_b_A_flag =0; 01257 break; 01258 } 01259 sleep(); //puts mbed to sleep 01260 } 01261 lcd.clear(); //Clear all the pixels on the LCD screen 01262 lcd.printString("it'll cost",0,0); 01263 lcd.printString("you 10 score",0,1); 01264 lcd.printString("points.",0,2); 01265 lcd.printString("Press A>>",24,5); 01266 lcd.refresh(); 01267 ticker_wait(10); 01268 g_press_b_A_flag =0; 01269 while (1) { 01270 if (g_press_b_A_flag ) { 01271 g_press_b_A_flag =0; 01272 break; 01273 } 01274 sleep(); //puts mbed to sleep 01275 } 01276 lcd.clear(); //Clear all the pixels on the LCD screen 01277 lcd.printString("Try it...",0,0); 01278 lcd.printString("Okay>>",30,5); 01279 lcd.refresh(); 01280 ticker_wait(10); 01281 g_press_b_A_flag =0; 01282 while (1) { 01283 if (g_press_b_A_flag ) { 01284 g_press_b_A_flag =0; 01285 break; 01286 } 01287 sleep(); //puts mbed to sleep 01288 } 01289 //sets the difficulty to -1, no interactive elements in the game 01290 //this allows the player to try the game contolls 01291 //Also increases the score to 30 so player can test using the shield 01292 difficulty =-1; 01293 score =30; 01294 Game(); 01295 lcd.clear(); //Clear all the pixels on the LCD screen 01296 lcd.printString("Great!!!",0,0); 01297 lcd.printString("To shoot press",0,1); 01298 lcd.printString("A, but watch",0,2); 01299 lcd.printString("out you...",0,3); 01300 lcd.printString("Press A>>",24,5); 01301 lcd.refresh(); 01302 ticker_wait(10); 01303 g_press_b_A_flag =0; 01304 while (1) { 01305 if (g_press_b_A_flag ) { 01306 g_press_b_A_flag =0; 01307 break; 01308 } 01309 sleep(); //puts mbed to sleep 01310 } 01311 lcd.clear(); //Clear all the pixels on the LCD screen 01312 lcd.printString("... might use",0,0); 01313 lcd.printString("all your ammo",0,1); 01314 lcd.printString("Give it a go!",0,3); 01315 lcd.printString("Okay>>",30,5); 01316 lcd.refresh(); 01317 ticker_wait(10); 01318 g_press_b_A_flag =0; 01319 while (1) { 01320 if (g_press_b_A_flag ) { 01321 g_press_b_A_flag =0; 01322 break; 01323 } 01324 sleep(); //puts mbed to sleep 01325 } 01326 //sets the difficulty to -1, no interactive elements in the game 01327 //this allows the player to try the game contolls 01328 difficulty =-1; 01329 Game(); 01330 lcd.clear(); //Clear all the pixels on the LCD screen 01331 lcd.printString("Remember you",0,0); 01332 lcd.printString("can also shoot",0,1); 01333 lcd.printString("while jumping",0,2); 01334 lcd.printString("and crouching",0,3); 01335 lcd.printString("Press A>>",24,5); 01336 lcd.refresh(); 01337 ticker_wait(10); 01338 g_press_b_A_flag =0; 01339 while (1) { 01340 if (g_press_b_A_flag ) { 01341 g_press_b_A_flag =0; 01342 break; 01343 } 01344 sleep(); //puts mbed to sleep 01345 } 01346 lcd.clear(); //Clear all the pixels on the LCD screen 01347 lcd.printString("Information",0,0); 01348 lcd.printString("about your",0,1); 01349 lcd.printString("status (ammo",0,2); 01350 lcd.printString("and score) ...",0,3); 01351 lcd.printString("Press A>>",24,5); 01352 lcd.refresh(); 01353 ticker_wait(10);; 01354 g_press_b_A_flag =0; 01355 while (1) { 01356 if (g_press_b_A_flag ) { 01357 g_press_b_A_flag =0; 01358 break; 01359 } 01360 sleep(); //puts mbed to sleep 01361 } 01362 lcd.clear(); //Clear all the pixels on the LCD screen 01363 lcd.printString("... is shown",0,0); 01364 lcd.printString("above, and the",0,1); 01365 lcd.printString("number",0,2); 01366 lcd.printString("lives you ...",0,3); 01367 lcd.printString("Press A>>",24,5); 01368 lcd.refresh(); 01369 ticker_wait(10); 01370 g_press_b_A_flag =0; 01371 while (1) { 01372 if (g_press_b_A_flag ) { 01373 g_press_b_A_flag =0; 01374 break; 01375 } 01376 sleep(); //puts mbed to sleep 01377 } 01378 lcd.clear(); //Clear all the pixels on the LCD screen 01379 lcd.printString("... have is",0,0); 01380 lcd.printString("displayed on",0,1); 01381 lcd.printString("the LED bar,",0,2); 01382 lcd.printString("when they...",0,3); 01383 lcd.printString("Press A>>",24,5); 01384 lcd.refresh(); 01385 ticker_wait(10); 01386 g_press_b_A_flag =0; 01387 while (1) { 01388 if (g_press_b_A_flag ) { 01389 g_press_b_A_flag =0; 01390 break; 01391 } 01392 sleep(); //puts mbed to sleep 01393 } 01394 lcd.clear(); //Clear all the pixels on the LCD screen 01395 lcd.printString("... all turn",0,0); 01396 lcd.printString("off you will",0,1); 01397 lcd.printString("die, so make",0,2); 01398 lcd.printString("sure that...",0,3); 01399 lcd.printString("Press A>>",24,5); 01400 lcd.refresh(); 01401 ticker_wait(10); 01402 g_press_b_A_flag =0; 01403 while (1) { 01404 if (g_press_b_A_flag ) { 01405 g_press_b_A_flag =0; 01406 break; 01407 } 01408 sleep(); //puts mbed to sleep 01409 } 01410 lcd.clear(); //Clear all the pixels on the LCD screen 01411 lcd.printString("... it doesn't",0,0); 01412 lcd.printString("happen!!!",0,1); 01413 lcd.printString("Press A>>",24,5); 01414 lcd.refresh(); 01415 ticker_wait(10); 01416 g_press_b_A_flag =0; 01417 while (1) { 01418 if (g_press_b_A_flag ) { 01419 g_press_b_A_flag =0; 01420 break; 01421 } 01422 sleep(); //puts mbed to sleep 01423 } 01424 lcd.clear(); //Clear all the pixels on the LCD screen 01425 lcd.printString("Excellent!!!",0,0); 01426 lcd.printString("Your training",0,1); 01427 lcd.printString("is over",0,2); 01428 lcd.printString("Press A>>",24,5); 01429 lcd.refresh(); 01430 ticker_wait(10); 01431 g_press_b_A_flag =0; 01432 while (1) { 01433 if (g_press_b_A_flag ) { 01434 g_press_b_A_flag =0; 01435 break; 01436 } 01437 sleep(); //puts mbed to sleep 01438 } 01439 lcd.clear(); //Clear all the pixels on the LCD screen 01440 lcd.printString("Are you ready",0,0); 01441 lcd.printString("for your first",0,1); 01442 lcd.printString("mission?",0,2); 01443 lcd.printString("Yes!!!>>",24,5); 01444 lcd.refresh(); 01445 ticker_wait(10); 01446 g_press_b_A_flag =0; 01447 while (1) { 01448 if (g_press_b_A_flag ) { 01449 g_press_b_A_flag =0; 01450 //Increses story_pregress 01451 story_progress =2; 01452 //autosaves progress 01453 writeSD_progress(); 01454 break; 01455 } 01456 sleep(); //puts mbed to sleep 01457 } 01458 } 01459 01460 void Chapter1() 01461 { 01462 //Introduce story 01463 lcd.clear(); //Clear all the pixels on the LCD screen 01464 lcd.printString("150+ MISSIONS",0,1); 01465 lcd.printString("LATER",18,2); 01466 lcd.refresh(); 01467 ticker_wait(20); 01468 lcd.clear(); //Clear all the pixels on the LCD screen 01469 lcd.printString("MISSION #158:",0,0); 01470 lcd.printString("We have intel",0,1); 01471 lcd.printString("of a new range",0,2); 01472 lcd.printString("of high tech",0,3); 01473 lcd.printString("military grade",0,4); 01474 lcd.printString("Press A>>",24,5); 01475 lcd.refresh(); 01476 ticker_wait(10); 01477 g_press_b_A_flag =0; 01478 while (1) { 01479 if (g_press_b_A_flag ) { 01480 g_press_b_A_flag =0; 01481 break; 01482 } 01483 sleep(); //puts mbed to sleep 01484 } 01485 lcd.clear(); //Clear all the pixels on the LCD screen 01486 lcd.printString("weapons being",0,0); 01487 lcd.printString("developed in",0,1); 01488 lcd.printString("a remote",0,2); 01489 lcd.printString("island in the",0,3); 01490 lcd.printString("South...",0,4); 01491 lcd.printString("Press A>>",24,5); 01492 lcd.refresh(); 01493 ticker_wait(10); 01494 g_press_b_A_flag =0; 01495 while (1) { 01496 if (g_press_b_A_flag ) { 01497 g_press_b_A_flag =0; 01498 break; 01499 } 01500 sleep(); //puts mbed to sleep 01501 } 01502 ticker_wait(10); 01503 lcd.clear(); //Clear all the pixels on the LCD screen 01504 lcd.printString("... Pacific.",0,0); 01505 lcd.printString("Your mission",0,1); 01506 lcd.printString("is to",0,2); 01507 lcd.printString("infiltrate the",0,3); 01508 lcd.printString("island and...",0,4); 01509 lcd.printString("Press A>>",24,5); 01510 lcd.refresh(); 01511 g_press_b_A_flag =0; 01512 while (1) { 01513 if (g_press_b_A_flag ) { 01514 g_press_b_A_flag =0; 01515 break; 01516 } 01517 sleep(); //puts mbed to sleep 01518 } 01519 ticker_wait(10); 01520 lcd.clear(); //Clear all the pixels on the LCD screen 01521 lcd.printString("... destroy",0,0); 01522 lcd.printString("as many of",0,1); 01523 lcd.printString("the weapons as",0,2); 01524 lcd.printString("you can. Are",0,3); 01525 lcd.printString("you ready?",0,4); 01526 lcd.printString("Yes!!>>",24,5); 01527 lcd.refresh(); 01528 ticker_wait(10); 01529 g_press_b_A_flag =0; 01530 while (1) { 01531 if (g_press_b_A_flag ) { 01532 g_press_b_A_flag =0; 01533 break; 01534 } 01535 sleep(); //puts mbed to sleep 01536 } 01537 ticker_wait(10); 01538 lcd.clear(); //Clear all the pixels on the LCD screen 01539 lcd.printString("Excellent, you",0,0); 01540 lcd.printString("will land on",0,1); 01541 lcd.printString("the farside of",0,2); 01542 lcd.printString("the island and",0,3); 01543 lcd.printString("work your...",0,4); 01544 lcd.printString("Press A>>",24,5); 01545 lcd.refresh(); 01546 ticker_wait(10); 01547 g_press_b_A_flag =0; 01548 while (1) { 01549 if (g_press_b_A_flag ) { 01550 g_press_b_A_flag =0; 01551 break; 01552 } 01553 sleep(); //puts mbed to sleep 01554 } 01555 ticker_wait(10); 01556 lcd.clear(); //Clear all the pixels on the LCD screen 01557 lcd.printString("...way towards",0,0); 01558 lcd.printString("the centre the",0,1); 01559 lcd.printString("closer you get",0,2); 01560 lcd.printString("the more",0,3); 01561 lcd.printString("defences...",0,4); 01562 lcd.printString("Press A>>",24,5); 01563 lcd.refresh(); 01564 ticker_wait(10); 01565 g_press_b_A_flag =0; 01566 while (1) { 01567 if (g_press_b_A_flag ) { 01568 g_press_b_A_flag =0; 01569 break; 01570 } 01571 sleep(); //puts mbed to sleep 01572 } 01573 ticker_wait(20); 01574 lcd.clear(); //Clear all the pixels on the LCD screen 01575 lcd.printString("they'll have.",0,0); 01576 lcd.printString("For now you",0,1); 01577 lcd.printString("need to look",0,2); 01578 lcd.printString("out for the",0,3); 01579 lcd.printString("cacti they...",0,4); 01580 lcd.printString("Press A>>",24,5); 01581 lcd.refresh(); 01582 ticker_wait(10); 01583 g_press_b_A_flag =0; 01584 while (1) { 01585 if (g_press_b_A_flag ) { 01586 g_press_b_A_flag =0; 01587 break; 01588 } 01589 sleep(); //puts mbed to sleep 01590 } 01591 01592 ticker_wait(20); 01593 lcd.clear(); //Clear all the pixels on the LCD screen 01594 lcd.printString("if you touch",0,0); 01595 lcd.printString("one you'll",0,1); 01596 lcd.printString("lose a life so",0,2); 01597 lcd.printString("jump over...",0,3); 01598 lcd.printString("Press A>>",24,5); 01599 lcd.refresh(); 01600 ticker_wait(10); 01601 g_press_b_A_flag =0; 01602 while (1) { 01603 if (g_press_b_A_flag ) { 01604 g_press_b_A_flag =0; 01605 break; 01606 } 01607 sleep(); //puts mbed to sleep 01608 } 01609 ticker_wait(20); 01610 lcd.clear(); //Clear all the pixels on the LCD screen 01611 lcd.printString("...them, also,",0,0); 01612 lcd.printString("watch out for",0,1); 01613 lcd.printString("low tech cyber",0,2); 01614 lcd.printString("rats running",0,3); 01615 lcd.printString("around, you'll...",0,4); 01616 lcd.printString("Press A>>",24,5); 01617 lcd.refresh(); 01618 ticker_wait(10); 01619 g_press_b_A_flag =0; 01620 while (1) { 01621 if (g_press_b_A_flag ) { 01622 g_press_b_A_flag =0; 01623 break; 01624 } 01625 sleep(); //puts mbed to sleep 01626 } 01627 ticker_wait(20); 01628 lcd.clear(); //Clear all the pixels on the LCD screen 01629 lcd.printString("have to jump",0,0); 01630 lcd.printString("them aswell",0,1); 01631 lcd.printString("as you cannot",0,2); 01632 lcd.printString("destroy them.",0,3); 01633 lcd.printString("Press A>>",24,5); 01634 lcd.refresh(); 01635 ticker_wait(10); 01636 g_press_b_A_flag =0; 01637 while (1) { 01638 if (g_press_b_A_flag ) { 01639 g_press_b_A_flag =0; 01640 break; 01641 } 01642 sleep(); //puts mbed to sleep 01643 } 01644 ticker_wait(20); 01645 lcd.clear(); //Clear all the pixels on the LCD screen 01646 lcd.printString("That's all you",0,0); 01647 lcd.printString("need to know ",0,1); 01648 lcd.printString("for now. Get",0,2); 01649 lcd.printString("to work and",0,3); 01650 lcd.printString("Good Luck!!!",0,4); 01651 lcd.printString("Press A>>",24,5); 01652 lcd.refresh(); 01653 ticker_wait(10); 01654 g_press_b_A_flag =0; 01655 while (1) { 01656 if (g_press_b_A_flag ) { 01657 g_press_b_A_flag =0; 01658 break; 01659 } 01660 sleep(); //puts mbed to sleep 01661 } 01662 //sets the difficulty to 0, only cactus and rats 01663 //this allows the player to try the game contolls 01664 difficulty =0; 01665 Game(); 01666 //innreases the story progress to 3 01667 story_progress =3; 01668 //autosaves progress 01669 writeSD_progress(); 01670 //prints post game message 01671 lcd.clear(); //Clear all the pixels on the LCD screen 01672 lcd.printString("Well done!!!",0,0); 01673 lcd.printString("Oh no...",0,1); 01674 lcd.printString("It looks like",0,2); 01675 lcd.printString("things are",0,3); 01676 lcd.printString("steping up",0,4); 01677 lcd.printString("Press A>>",24,5); 01678 lcd.refresh(); 01679 ticker_wait(10); 01680 g_press_b_A_flag =0; 01681 while (1) { 01682 if (g_press_b_A_flag ) { 01683 g_press_b_A_flag =0; 01684 break; 01685 } 01686 sleep(); //puts mbed to sleep 01687 } 01688 } 01689 01690 void Chapter2() 01691 { 01692 //Continuing the story, indroducing more mobs 01693 lcd.clear(); //Clear all the pixels on the LCD screen 01694 lcd.printString("Now you'll",0,0); 01695 lcd.printString("encounter",0,1); 01696 lcd.printString("robotic birds",0,2); 01697 lcd.printString("and robotic",0,3); 01698 lcd.printString("hounds aswell.",0,4); 01699 lcd.printString("Press A>>",24,5); 01700 lcd.refresh(); 01701 ticker_wait(10); 01702 g_press_b_A_flag =0; 01703 while (1) { 01704 if (g_press_b_A_flag ) { 01705 g_press_b_A_flag =0; 01706 break; 01707 } 01708 sleep(); //puts mbed to sleep 01709 } 01710 lcd.clear(); //Clear all the pixels on the LCD screen 01711 lcd.printString("Watch out for",0,0); 01712 lcd.printString("the birds as",0,1); 01713 lcd.printString("they may swoop",0,2); 01714 lcd.printString("and the hounds",0,3); 01715 lcd.printString("will pounce",0,4); 01716 lcd.printString("Press A>>",24,5); 01717 lcd.refresh(); 01718 ticker_wait(10); 01719 g_press_b_A_flag =0; 01720 while (1) { 01721 if (g_press_b_A_flag ) { 01722 g_press_b_A_flag =0; 01723 break; 01724 } 01725 sleep(); //puts mbed to sleep 01726 } 01727 //Set difficulty to 1. Hounds and birds also appear 01728 difficulty =1; 01729 Game(); 01730 //When compleated it increases story_progress to 4 01731 story_progress =4; 01732 //autosaves progress 01733 writeSD_progress(); 01734 lcd.clear(); //Clear all the pixels on the LCD screen 01735 lcd.printString("Oh dear...",0,0); 01736 lcd.printString("There is more",0,1); 01737 lcd.printString("trouble ahead",0,2); 01738 lcd.printString("Press A>>",24,5); 01739 lcd.refresh(); 01740 ticker_wait(10); 01741 g_press_b_A_flag =0; 01742 while (1) { 01743 if (g_press_b_A_flag ) { 01744 g_press_b_A_flag =0; 01745 break; 01746 } 01747 sleep(); //puts mbed to sleep 01748 } 01749 } 01750 01751 void Chapter3() 01752 { 01753 //Continuing the story, indroducing more mobs 01754 lcd.clear(); //Clear all the pixels on the LCD screen 01755 lcd.printString("It looks like",0,0); 01756 lcd.printString("there is some",0,1); 01757 lcd.printString("sort of",0,2); 01758 lcd.printString("bionic bear!!",0,3); 01759 lcd.printString("You better...",0,4); 01760 lcd.printString("Press A>>",24,5); 01761 lcd.refresh(); 01762 ticker_wait(10); 01763 g_press_b_A_flag =0; 01764 while (1) { 01765 if (g_press_b_A_flag ) { 01766 g_press_b_A_flag =0; 01767 break; 01768 } 01769 sleep(); //puts mbed to sleep 01770 } 01771 lcd.clear(); //Clear all the pixels on the LCD screen 01772 lcd.printString("... watch out",0,0); 01773 lcd.printString("it looks like",0,1); 01774 lcd.printString("it will be",0,2); 01775 lcd.printString("able to",0,3); 01776 lcd.printString("withstand...",0,4); 01777 lcd.printString("Press A>>",24,5); 01778 lcd.refresh(); 01779 ticker_wait(10); 01780 g_press_b_A_flag =0; 01781 while (1) { 01782 if (g_press_b_A_flag ) { 01783 g_press_b_A_flag =0; 01784 break; 01785 } 01786 sleep(); //puts mbed to sleep 01787 } 01788 lcd.clear(); //Clear all the pixels on the LCD screen 01789 lcd.printString("a few shots",0,0); 01790 lcd.printString("before",0,1); 01791 lcd.printString("destroying it",0,2); 01792 lcd.printString("4 hits should",0,3); 01793 lcd.printString("do it. GO!",0,4); 01794 lcd.printString("Press A>>",24,5); 01795 lcd.refresh(); 01796 ticker_wait(10); 01797 g_press_b_A_flag =0; 01798 while (1) { 01799 if (g_press_b_A_flag ) { 01800 g_press_b_A_flag =0; 01801 break; 01802 } 01803 sleep(); //puts mbed to sleep 01804 } 01805 //Set difficulty to 2. Bears will appear 01806 difficulty =2; 01807 Game(); 01808 //Increases story progress 01809 story_progress =5; 01810 //Autosaves game 01811 writeSD_progress(); 01812 //Post game message 01813 lcd.clear(); //Clear all the pixels on the LCD screen 01814 lcd.printString("OH DEAR",0,0); 01815 lcd.printString("LORD...",0,1); 01816 lcd.printString("Press A>>",24,5); 01817 lcd.refresh(); 01818 ticker_wait(10); 01819 g_press_b_A_flag =0; 01820 while (1) { 01821 if (g_press_b_A_flag ) { 01822 g_press_b_A_flag =0; 01823 break; 01824 } 01825 sleep(); //puts mbed to sleep 01826 } 01827 } 01828 01829 void Chapter4() 01830 { 01831 ////Continuing the story, indroducing final boss 01832 g_press_b_A_flag =0; 01833 lcd.clear(); //Clear all the pixels on the LCD screen 01834 lcd.printString("You won't",0,0); 01835 lcd.printString("beleve this",0,1); 01836 lcd.printString("it's it's...",0,2); 01837 lcd.printString("it can't be",0,3); 01838 lcd.printString("it's not...",0,4); 01839 lcd.printString("Press A>>",24,5); 01840 lcd.refresh(); 01841 ticker_wait(10); 01842 g_press_b_A_flag =0; 01843 while (1) { 01844 if (g_press_b_A_flag ) { 01845 g_press_b_A_flag =0; 01846 break; 01847 } 01848 sleep(); //puts mbed to sleep 01849 } 01850 lcd.clear(); //Clear all the pixels on the LCD screen 01851 lcd.printString("it's not",0,0); 01852 lcd.printString("possible...",0,1); 01853 lcd.printString("It's a T Rex,",0,2); 01854 lcd.printString("a robotic",0,3); 01855 lcd.printString("T Rex!!!!",0,4); 01856 lcd.printString("Press A>>",24,5); 01857 lcd.refresh(); 01858 ticker_wait(10); 01859 g_press_b_A_flag =0; 01860 while (1) { 01861 if (g_press_b_A_flag ) { 01862 g_press_b_A_flag =0; 01863 break; 01864 } 01865 sleep(); //puts mbed to sleep 01866 } 01867 lcd.clear(); //Clear all the pixels on the LCD screen 01868 lcd.printString("It's it's...",0,0); 01869 lcd.printString("it's",0,1); 01870 lcd.printString("breathing",0,2); 01871 lcd.printString("fire!!!",0,3); 01872 lcd.printString("It looks...",0,4); 01873 lcd.printString("Press A>>",24,5); 01874 lcd.refresh(); 01875 ticker_wait(10); 01876 g_press_b_A_flag =0; 01877 while (1) { 01878 if (g_press_b_A_flag ) { 01879 g_press_b_A_flag =0; 01880 break; 01881 } 01882 sleep(); //puts mbed to sleep 01883 } 01884 lcd.clear(); //Clear all the pixels on the LCD screen 01885 lcd.printString("... like it",0,0); 01886 lcd.printString("will only",0,1); 01887 lcd.printString("take damage",0,2); 01888 lcd.printString("when it's",0,3); 01889 lcd.printString("attacking...",0,4); 01890 lcd.printString("Press A>>",24,5); 01891 lcd.refresh(); 01892 ticker_wait(10); 01893 g_press_b_A_flag =0; 01894 while (1) { 01895 if (g_press_b_A_flag ) { 01896 g_press_b_A_flag =0; 01897 break; 01898 } 01899 sleep(); //puts mbed to sleep 01900 } 01901 lcd.clear(); //Clear all the pixels on the LCD screen 01902 lcd.printString("and I think",0,0); 01903 lcd.printString("you'll have",0,1); 01904 lcd.printString("to shoot it",0,2); 01905 lcd.printString("at least 8",0,3); 01906 lcd.printString("times to...",0,4); 01907 lcd.printString("Press A>>",24,5); 01908 lcd.refresh(); 01909 ticker_wait(10); 01910 g_press_b_A_flag =0; 01911 while (1) { 01912 if (g_press_b_A_flag ) { 01913 g_press_b_A_flag =0; 01914 break; 01915 } 01916 sleep(); //puts mbed to sleep 01917 } 01918 lcd.clear(); //Clear all the pixels on the LCD screen 01919 lcd.printString("...destroy it",0,0); 01920 lcd.printString("I'll drop",0,1); 01921 lcd.printString("some ammo",0,2); 01922 lcd.printString("for you.",0,3); 01923 lcd.printString("Press A>>",24,5); 01924 lcd.refresh(); 01925 ticker_wait(10); 01926 g_press_b_A_flag =0; 01927 while (1) { 01928 if (g_press_b_A_flag ) { 01929 g_press_b_A_flag =0; 01930 break; 01931 } 01932 sleep(); //puts mbed to sleep 01933 } 01934 lcd.clear(); //Clear all the pixels on the LCD screen 01935 lcd.printString("Good Luck",0,0); 01936 lcd.printString("You'll need",0,1); 01937 lcd.printString("it",0,2); 01938 lcd.printString("Press A>>",24,5); 01939 lcd.refresh(); 01940 ticker_wait(10); 01941 g_press_b_A_flag =0; 01942 while (1) { 01943 if (g_press_b_A_flag ) { 01944 g_press_b_A_flag =0; 01945 break; 01946 } 01947 sleep(); //puts mbed to sleep 01948 } 01949 difficulty =3; 01950 Game(); 01951 initialize_values(); 01952 if (g_story_mode_win ) { 01953 lcd.clear(); //Clear all the pixels on the LCD screen 01954 lcd.printString("Well done",0,0); 01955 lcd.printString("Recks",0,1); 01956 lcd.printString("Lets clear",0,2); 01957 lcd.printString("get you home",0,3); 01958 lcd.printString("Press A>>",24,5); 01959 lcd.refresh(); 01960 ticker_wait(30); 01961 } 01962 g_press_b_A_flag =0; 01963 while (1) { 01964 if (g_press_b_A_flag ) { 01965 g_press_b_A_flag =0; 01966 break; 01967 } 01968 sleep(); //puts mbed to sleep 01969 } 01970 } 01971 01972 //Funtion that inverst the pixels and stops the game for 0.5s when a life is lost 01973 void freeze() 01974 { 01975 lcd.inverseMode(); //invert pixels 01976 lcd.refresh(); 01977 ticker_wait(5); 01978 lcd.normalMode(); 01979 } 01980 01981 //Print the settings menu 01982 void Settings() 01983 { 01984 menuState =0; 01985 while (1) { 01986 if (g_Ticker_Menu_flag ) { 01987 g_Ticker_Menu_flag =0; 01988 updateJoystick(); 01989 menu_select = fsm_settings_menu[menuState ].menu_select; // set ouput depending on current state 01990 menuState = fsm_settings_menu[menuState ].nextState[joystick.direction]; // when joystick.direction has a vaule of CENTRE/RIGHT/LEFT the state machine input is 0 when it has a value of DOWN it is 0b01 when it has a value of UP is is 0b10 01991 lcd.clear(); //Clear all the pixels on the LCD screen 01992 //print the options 01993 lcd.printString("Brightness",13,0); 01994 lcd.printString("Difficulty",13,1); 01995 lcd.printString("SD card",13,2); 01996 lcd.printString("Guns",13,3); 01997 for (int i =0; i <85; i ++) { //go through every pixel on the x axis 01998 for (int j=menu_select ; j<(menu_select +8); j++) { // go through relevant pixels on the y axis 01999 if (lcd.getPixel(i ,j)== 0) { //if the pixel is on trun it off 02000 lcd.setPixel(i ,j); 02001 } else { 02002 lcd.clearPixel(i ,j); //if the pixel is off turn it on 02003 } 02004 } 02005 } 02006 //Depending of the selected option, call the respective funtion 02007 lcd.refresh(); 02008 if (b_A & menu_select ==0) { 02009 Brightness(); 02010 return; 02011 } else if (b_A & menu_select ==8) { 02012 Difficulty(); 02013 return; 02014 } else if (b_A & menu_select ==16) { 02015 Delete_Highscores(); 02016 return; 02017 } else if (b_A & menu_select ==24) { 02018 guns(); 02019 return; 02020 } 02021 if (b_B) { 02022 menuState =0; 02023 return; 02024 } 02025 } 02026 } 02027 } 02028 02029 //Funtion to choose the difficulty of the game 02030 void Difficulty() 02031 { 02032 menuState =0; 02033 while(1) { 02034 if (g_Ticker_Menu_flag ) { 02035 g_Ticker_Menu_flag =0; 02036 updateJoystick(); 02037 menu_select = fsm_main_menu[menuState ].menu_select; // set ouput depending on current state 02038 menuState = fsm_main_menu[menuState ].nextState[joystick.direction]; // when joystick.direction has a vaule of CENTRE/RIGHT/LEFT the state machine input is 0 when it has a value of DOWN it is 0b01 when it has a value of UP is is 0b10 02039 lcd.clear(); //Clear all the pixels on the LCD screen 02040 //print all dificulty options 02041 lcd.printString("Piece of Cake",3,0); 02042 lcd.printString("Easy",30,1); 02043 lcd.printString("Regular",23,2); 02044 lcd.printString("Hard",30,3); 02045 lcd.printString("Legendary",15,4); 02046 for (int i =0; i <85; i ++) { //go through every pixel on the x axis 02047 for (int j=menu_select ; j<(menu_select +8); j++) { // go through relevant pixels on the y axis 02048 if (lcd.getPixel(i ,j)== 0) { //if the pixel is on trun it off 02049 lcd.setPixel(i ,j); 02050 } else { 02051 lcd.clearPixel(i ,j); //if the pixel is off turn it on 02052 } 02053 } 02054 } 02055 //Depending on the option chosen set the difficulty to a certain value, the higher the value the higher the dificulty and return to main menu 02056 lcd.refresh(); 02057 if (b_A & menu_select ==0) { 02058 difficulty =0; 02059 return; 02060 } else if (b_A & menu_select ==8) { 02061 difficulty =1; 02062 return; 02063 } else if (b_A & menu_select ==16) { 02064 difficulty =2; 02065 return; 02066 } else if (b_A & menu_select ==24) { 02067 difficulty =3; 02068 return; 02069 } else if (b_A & menu_select ==32) { 02070 difficulty =4; 02071 return; 02072 } 02073 if (b_B) { 02074 menuState =0; 02075 return; 02076 } 02077 } 02078 sleep(); //puts mbed to sleep 02079 } 02080 } 02081 02082 //Menu to chose brightness 02083 void Brightness() 02084 { 02085 menuState =0; 02086 while(1) { 02087 if (g_Ticker_Menu_flag ) { 02088 g_Ticker_Menu_flag =0; 02089 updateJoystick(); 02090 menu_select = fsm_main_menu[menuState ].menu_select; // set ouput depending on current state 02091 menuState = fsm_main_menu[menuState ].nextState[joystick.direction]; // when joystick.direction has a vaule of CENTRE/RIGHT/LEFT the state machine input is 0 when it has a value of DOWN it is 0b01 when it has a value of UP is is 0b10 02092 lcd.clear(); //Clear all the pixels on the LCD screen 02093 //Print brightness options 02094 lcd.printString("Dark",30,0); 02095 lcd.printString("Eco",33,1); 02096 lcd.printString("Regular",23,2); 02097 lcd.printString("Bright",26,3); 02098 lcd.printString("Blinding",20,4); 02099 for (int i =0; i <85; i ++) { //go through every pixel on the x axis 02100 for (int j=menu_select ; j<(menu_select +8); j++) { // go through relevant pixels on the y axis 02101 if (lcd.getPixel(i ,j)== 0) { //if the pixel is on trun it off 02102 lcd.setPixel(i ,j); 02103 } else { 02104 lcd.clearPixel(i ,j); //if the pixel is off turn it on 02105 } 02106 } 02107 } 02108 //Depending on chosen option, set the brightness between 0 anf 1 and return to main menu 02109 lcd.refresh(); 02110 if (b_A & menu_select ==0) { 02111 brightness =0; 02112 return; 02113 } else if (b_A & menu_select ==8) { 02114 brightness =0.3; 02115 return; 02116 } else if (b_A & menu_select ==16) { 02117 brightness =0.5; 02118 return; 02119 } else if (b_A & menu_select ==24) { 02120 brightness =0.7; 02121 return; 02122 } else if (b_A & menu_select ==32) { 02123 brightness =1; 02124 return; 02125 } 02126 if (b_B) { 02127 menuState =0; 02128 return; 02129 } 02130 } 02131 sleep(); //puts mbed to sleep 02132 } 02133 } 02134 02135 //Prints the leaderboard 02136 void Leaderboard() 02137 { 02138 lcd.clear(); //Clear all the pixels on the LCD screen 02139 //reads and prints the leaderboard 02140 readSD_and_print_top_score(); 02141 g_press_b_B_flag =0; 02142 //if the b_B button is presses return to menu 02143 while(1) { 02144 if (g_press_b_B_flag ) { 02145 g_press_b_B_flag =0; 02146 return; 02147 } 02148 lcd.refresh(); 02149 sleep(); //puts mbed to sleep 02150 } 02151 } 02152 02153 //Print the guns options 02154 void guns() 02155 { 02156 menuState =0; 02157 while(1) { 02158 if (g_Ticker_Menu_flag ) { 02159 g_Ticker_Menu_flag =0; 02160 updateJoystick(); 02161 menu_select = fsm_settings_menu[menuState ].menu_select; // set ouput depending on current state 02162 menuState = fsm_settings_menu[menuState ].nextState[joystick.direction]; // when joystick.direction has a vaule of CENTRE/RIGHT/LEFT the state machine input is 0 when it has a value of DOWN it is 0b01 when it has a value of UP is is 0b10 02163 lcd.clear(); //Clear all the pixels on the LCD screen 02164 //Print the guns options 02165 lcd.printString("Pistol",10,0); 02166 lcd.printString("Revolver",10,1); 02167 lcd.printString("Rifle",10,2); 02168 lcd.printString("Random",10,3); 02169 for (int i =0; i <85; i ++) { //go through every pixel on the x axis 02170 for (int j=menu_select ; j<(menu_select +8); j++) { // go through relevant pixels on the y axis 02171 if (lcd.getPixel(i ,j)== 0) { //if the pixel is on trun it off 02172 lcd.setPixel(i ,j); 02173 } else { 02174 lcd.clearPixel(i ,j); //if the pixel is off turn it on 02175 } 02176 } 02177 } 02178 lcd.refresh(); 02179 //Depending on the options selected g_g1, g_g2 set to one 02180 //if g_g1=1 and g_g2=1 it increases the dmage taken by certain mobs 02181 if (b_A & menu_select ==0) { 02182 g_g1 =0; 02183 g_g2 =0; 02184 return; 02185 } else if (b_A & menu_select ==8) { 02186 g_g1 =1; 02187 g_g2 =0; 02188 return; 02189 } else if (b_A & menu_select ==16) { 02190 g_g1 =1; 02191 g_g2 =1; 02192 return; 02193 } else if (b_A & menu_select ==24) { 02194 if (rand()%3==0) { 02195 g_g1 =0; 02196 g_g2 =0; 02197 } else if (rand()%3==1) { 02198 g_g1 =1; 02199 g_g2 =0; 02200 } else if (rand()%3==2) { 02201 g_g1 =1; 02202 g_g2 =1; 02203 } 02204 return; 02205 } 02206 if (b_B) { 02207 menuState =0; 02208 return; 02209 } 02210 } 02211 sleep(); //puts mbed to sleep 02212 } 02213 } 02214 02215 //prints the credits 02216 void Credits() 02217 { 02218 lcd.clear(); 02219 lcd.printString("Game made by",6,2); 02220 lcd.refresh(); 02221 ticker_wait(30); 02222 lcd.clear(); 02223 lcd.printString("ROBIN",6,1); 02224 lcd.printString("MILWARD",6,2); 02225 lcd.printString("COONEY",6,3); 02226 lcd.refresh(); 02227 ticker_wait(30); 02228 lcd.clear(); 02229 lcd.printString("Game made for",0,2); 02230 lcd.refresh(); 02231 ticker_wait(30); 02232 lcd.clear(); 02233 lcd.printString("ELEC2645",6,2); 02234 lcd.refresh(); 02235 ticker_wait(30); 02236 } 02237 02238 02239 //Physics related to Recks 02240 void Recks() 02241 { 02242 //if the joystick is centred recks is still 02243 if (joystick.direction==CENTRE&jump_flag !=1&shield_flag !=1) { 02244 lcd.setPixel(bullet ,bullet_height ); 02245 lcd.setPixel(bullet +1,bullet_height ); 02246 print_recks_still_gun(); 02247 if (shoot_flag ==1) { 02248 bullet +=20; 02249 if (bullet >=84) { 02250 shoot_flag =0; 02251 g_shoot_loop =0; 02252 } 02253 } 02254 //if the joystick is left then everything except recks moves to the left 02255 } else if (joystick.direction==LEFT&jump_flag !=1&shield_flag !=1) { 02256 if ( i %4>=2) { 02257 print_recks_still_gun(); 02258 } else if ( i %4<2) { 02259 print_recks_moving_gun(); 02260 } 02261 lcd.setPixel(bullet ,bullet_height ); 02262 lcd.setPixel(bullet +1,bullet_height ); 02263 if (shoot_flag ==1) { 02264 bullet +=21; 02265 if (bullet >=84) { 02266 shoot_flag =0; 02267 g_shoot_loop =0; 02268 } 02269 } 02270 h_movement --; 02271 //if the joystick is right then everything except recks moves to the right 02272 } else if (joystick.direction==RIGHT&jump_flag !=1&shield_flag !=1) { 02273 if ( i %4>=2) { 02274 print_recks_still_gun(); 02275 } else if ( i %4<2) { 02276 print_recks_moving_gun(); 02277 } 02278 lcd.setPixel(bullet ,bullet_height ); 02279 lcd.setPixel(bullet +1,bullet_height ); 02280 if (shoot_flag ==1) { 02281 bullet +=19; 02282 if (bullet >=84) { 02283 shoot_flag =0; 02284 g_shoot_loop =0; 02285 } 02286 } 02287 h_movement ++; 02288 //If joystick is down recks crouches 02289 } else if (joystick.direction==DOWN&jump_flag !=1&shield_flag !=1) { 02290 lcd.setPixel(bullet ,bullet_height ); 02291 lcd.setPixel(bullet +1,bullet_height ); 02292 print_recks_crouch_gun(); 02293 bullet_height =42; 02294 if (shoot_flag ==1) { 02295 bullet +=20; 02296 if (bullet >=84) { 02297 shoot_flag =0; 02298 g_shoot_loop =0; 02299 } 02300 } 02301 //If the jump_flag is 1 (then teh jump button has been pressed) Recks jumps 02302 //If the joystick moves while the jump_flag is 1 then Recks moves left or right 02303 } else if (jump_flag ==1&shield_flag !=1) { 02304 if (joystick.direction==LEFT) { 02305 if (shoot_flag ==1) { 02306 bullet +=21; 02307 if (bullet >=84) { 02308 shoot_flag =0; 02309 g_shoot_loop =0; 02310 } 02311 } 02312 h_movement --; 02313 } else if (joystick.direction==RIGHT) { 02314 if (shoot_flag ==1) { 02315 bullet +=19; 02316 if (bullet >=84) { 02317 shoot_flag =0; 02318 g_shoot_loop =0; 02319 } 02320 } 02321 h_movement ++; 02322 } else if (joystick.direction==CENTRE) { 02323 if (shoot_flag ==1) { 02324 bullet +=20; 02325 if (bullet >=84) { 02326 shoot_flag =0; 02327 g_shoot_loop =0; 02328 } 02329 } 02330 } 02331 if (g_jump <=36&jumpUp ==0&g_jump !=15) { 02332 lcd.setPixel(bullet ,bullet_height ); 02333 lcd.setPixel(bullet +1,bullet_height ); 02334 if (bullet >=84) { 02335 shoot_flag =0; 02336 g_shoot_loop =0; 02337 } 02338 print_recks_jump_gun(); 02339 g_jump -=6-accel ; 02340 accel ++; 02341 } else if (g_jump >=15&g_jump !=36) { 02342 lcd.setPixel(bullet ,bullet_height ); 02343 lcd.setPixel(bullet +1,bullet_height ); 02344 if (bullet >=84) { 02345 shoot_flag =0; 02346 g_shoot_loop =0; 02347 } 02348 print_recks_jump_gun(); 02349 g_jump +=6-accel ; 02350 accel --; 02351 jumpUp =1; 02352 } else if (g_jump ==36&jumpUp ==1) { 02353 lcd.setPixel(bullet ,bullet_height ); 02354 lcd.setPixel(bullet +1,bullet_height ); 02355 if (bullet >=84) { 02356 shoot_flag =0; 02357 g_shoot_loop =0; 02358 } 02359 print_recks_still_gun(); 02360 jump_flag =0; 02361 jumpUp =0; 02362 g_jump =36; 02363 accel =0; 02364 } 02365 } 02366 } 02367 02368 //Physics for rat 02369 void rat() 02370 { 02371 //rat array p1 or p2 changes every 2 itterations 02372 if (i %4>=2) { 02373 print_mob_rat_p1(); 02374 } else if (i %4<2) { 02375 print_mob_rat_p2(); 02376 } 02377 if (joystick.direction==LEFT) { 02378 rat_movement +=recks_movement ; 02379 } else if (joystick.direction==RIGHT) { 02380 rat_movement -=recks_movement ; 02381 } 02382 //rat velocity is 3 pixels per itteration 02383 rat_movement -=3; 02384 if (rat_movement <=-15) { 02385 rat_movement =100; 02386 print_rat_flag =0; 02387 } 02388 //when rat is in same vertical and horizontal position as Recks, Recks loses a life and the freeze duntion runs 02389 if (rat_movement<=5&rat_movement>=-3&g_jump >32&lose_lives_delay_flag ==0&shield_flag !=1) { //a life is lost if recks has an vertical and horizontal position equal to one of the pixels corresponding to the bears position 02390 lives --; 02391 freeze(); 02392 lose_lives_delay_flag =1; 02393 } 02394 02395 } 02396 02397 void hound() 02398 { 02399 //hound array p1 or p2 changes every 2 itterations 02400 if (i %4>=2&hound_jump_flag !=1) { 02401 print_mob_hound_p1(); 02402 } else if (i %4<2&hound_jump_flag !=1) { 02403 print_mob_hound_p2(); 02404 } 02405 if (joystick.direction==LEFT) { 02406 hound_hMovement +=recks_movement ; 02407 } else if (joystick.direction==RIGHT) { 02408 hound_hMovement -=recks_movement ; 02409 } 02410 //hound velocity is 2 pixels per itteration 02411 hound_hMovement -=2; 02412 if (hound_hMovement <=-15) { 02413 hound_hMovement =100; 02414 print_hound_flag =0; 02415 } 02416 if (random_num %10==0) { 02417 hound_jump_flag =1; 02418 } 02419 //if the hound_jump_flag is one the houd jumps and increases it's horizontal velocity to 3 pixels per itteration 02420 if (hound_jump_flag ==1) { 02421 hound_jump ++; 02422 hound_hMovement --; 02423 if (hound_jump ==1) { 02424 hound_vMovement -=3; 02425 } else if (hound_jump ==2) { 02426 hound_vMovement -=2; 02427 } else if (hound_jump ==3) { 02428 hound_vMovement -=1; 02429 } else if (hound_jump ==4) { 02430 hound_vMovement +=1; 02431 } else if (hound_jump ==5) { 02432 hound_vMovement +=2; 02433 } else if (hound_jump ==6) { 02434 hound_vMovement +=3; 02435 } else if (hound_jump ==7) { 02436 hound_jump_flag =0; 02437 hound_jump =0; 02438 } 02439 print_mob_hound_p2(); 02440 02441 } 02442 //if hound possiton = recks possition, lives decrease by one 02443 if ((hound_hMovement<=8&hound_hMovement>=-5&g_jump >30&lose_lives_delay_flag ==0&hound_jump_flag !=1&shield_flag !=1)|(hound_hMovement<=8&hound_hMovement>=-5&g_jump >26&lose_lives_delay_flag ==0&hound_jump_flag ==1&shield_flag !=1)) { //a life is lost if recks has an vertical and horizontal position equal to one of the pixels corresponding to the hounds position 02444 lives --; 02445 freeze(); 02446 lose_lives_delay_flag =1; 02447 } 02448 //if bullet is the same hight as hound then hound dies 02449 if (shoot_flag ==1&bullet_height >hound_vMovement &bullet_height <hound_vMovement +8) { 02450 print_mob_hound_dead(); 02451 print_hound_flag =0; 02452 hound_hMovement =90; 02453 kill_score +=5; 02454 } 02455 } 02456 02457 //Prints bear physics 02458 void bear() 02459 { 02460 if (i %4>=2) { 02461 print_mob_bear_p1(); 02462 } else if (i %4<2) { 02463 print_mob_bear_p2(); 02464 } 02465 if (joystick.direction==LEFT) { 02466 bear_movement +=recks_movement ; 02467 } else if (joystick.direction==RIGHT) { 02468 bear_movement -=recks_movement ; 02469 } 02470 bear_movement -=2; 02471 if (bear_movement <=-15) { 02472 bear_movement =100; 02473 print_bear_flag =0; 02474 } 02475 if (bear_movement<=8&bear_movement>=-5&g_jump >26&lose_lives_delay_flag ==0&shield_flag !=1) { //a life is lost if recks has an vertical and horizontal position equal to one of the pixels corresponding to the bears position 02476 lives --; 02477 freeze(); 02478 lose_lives_delay_flag =1; 02479 } 02480 if (shoot_flag ==1&bullet_height >38) { 02481 bear_lives ++; 02482 //if bullet hits bear 4 (or 3 or 2 depending on g_g1 and g_g2) bear dies 02483 if (bear_lives ==12-3*g_g1 -3*g_g2 ) { 02484 print_mob_bear_dead(); 02485 print_bear_flag =0; 02486 bear_movement =100; 02487 kill_score +=7; 02488 bear_lives =0; 02489 } 02490 } 02491 } 02492 02493 //Bird physins, has a constant horizontal velocity and the vertical one changes randomly 02494 void bird() 02495 { 02496 if (i %8>=4) { 02497 print_mob_bird_p1(); 02498 } else if (i %8<4) { 02499 print_mob_bird_p2(); 02500 } 02501 bird_hMovement -=2; 02502 if (joystick.direction==LEFT) { 02503 bird_hMovement +=recks_movement ; 02504 } else if (joystick.direction==RIGHT) { 02505 bird_hMovement -=recks_movement ; 02506 } 02507 if (random_num %6==0) { 02508 bird_vMovement --; 02509 } else if (random_num %6>=4) { 02510 bird_vMovement ++; 02511 } 02512 if (bird_vMovement >=37) { 02513 bird_vMovement =37; 02514 } else if (bird_vMovement <=10) { 02515 bird_vMovement =10; 02516 } 02517 if (bird_hMovement <=-10) { 02518 print_bird_flag =0; 02519 bird_hMovement =100; 02520 bird_vMovement =20; 02521 bear_lives =0; 02522 } 02523 if ((bird_hMovement >=0&bird_hMovement <=10)&(bird_vMovement +5>=g_jump &bird_vMovement +5<=g_jump +10&lose_lives_delay_flag ==0)&shield_flag !=1) { 02524 lives --; 02525 freeze(); 02526 lose_lives_delay_flag =1; 02527 } 02528 if (shoot_flag ==1&(bullet_height ==bird_vMovement +5|bullet_height ==bird_vMovement +4)) { 02529 print_mob_bird_dead(); 02530 print_bird_flag =0; 02531 bird_hMovement =100; 02532 bird_vMovement =20; 02533 kill_score +=5; 02534 } 02535 } 02536 02537 //Cactus physics 02538 void cactus() 02539 { 02540 print_cactus(); 02541 if (joystick.direction==LEFT) { 02542 cactus_movement +=recks_movement ; 02543 } else if (joystick.direction==RIGHT) { 02544 cactus_movement -=recks_movement ; 02545 } 02546 if (cactus_movement <=-10) { 02547 cactus_movement =110; 02548 print_cactus_flag =0; 02549 } 02550 if (cactus_movement<=10&cactus_movement>=2&g_jump >32&lose_lives_delay_flag ==0&shield_flag !=1) { 02551 lives --; 02552 freeze(); 02553 lose_lives_delay_flag =1; 02554 } 02555 } 02556 02557 //T Rex physics 02558 void t_rex() 02559 { 02560 if (joystick.direction==LEFT) { 02561 t_rex_movement +=recks_movement ; 02562 } else if (joystick.direction==RIGHT) { 02563 t_rex_movement -=recks_movement ; 02564 } 02565 if (random_num %4==0&print_fire_ball_flag !=1) { 02566 t_rex_movement +=3; 02567 print_t_rex_moving(); 02568 } else if (random_num %4==1&print_fire_ball_flag !=1) { 02569 t_rex_movement -=3; 02570 print_t_rex_moving(); 02571 } else if (random_num %4>1&print_fire_ball_flag !=1) { 02572 print_t_rex(); 02573 } 02574 if (t_rex_movement <=-100) { 02575 t_rex_movement =120; 02576 print_t_rex_flag =0; 02577 } 02578 if (t_rex_movement<=6&t_rex_movement>=2&lose_lives_delay_flag ==0&shield_flag !=1) { 02579 lives --; 02580 freeze(); 02581 lose_lives_delay_flag =1; 02582 } 02583 if (print_t_rex_flag ==1&random_num %10==0&fire_on_screen ==0) { 02584 fire_on_screen =1; 02585 print_fire_ball_flag =1; 02586 fire_ball_hMovement =t_rex_movement -6; 02587 fire_ball_vMovement =25; 02588 } 02589 } 02590 02591 //Fire ball physics, T Rex only loses lives when fire ball flag is on 02592 void fire_ball() 02593 { 02594 print_t_rex_attack(); 02595 fire_ball_hMovement -=4; 02596 if (joystick.direction==LEFT) { 02597 fire_ball_hMovement +=recks_movement ; 02598 } else if (joystick.direction==RIGHT) { 02599 fire_ball_hMovement -=recks_movement ; 02600 } 02601 if (i %4>=2) { 02602 print_fire_ball_p1(); 02603 } else { 02604 print_fire_ball_p2(); 02605 } 02606 if (fire_ball_vMovement >=37) { 02607 fire_ball_vMovement =37; 02608 } 02609 if (random_num %3==0) { 02610 fire_ball_vMovement ++; 02611 } else if (random_num %3==1) { 02612 fire_ball_vMovement +=2; 02613 } 02614 if (fire_ball_hMovement <=-10) { 02615 fire_ball_vMovement =27; 02616 fire_ball_hMovement =t_rex_movement -6; 02617 print_fire_ball_flag =0; 02618 fire_on_screen =0; 02619 } 02620 if (fire_ball_hMovement >=3&fire_ball_hMovement<=8&fire_ball_vMovement>g_jump -5&fire_ball_vMovement <g_jump +10&lose_lives_delay_flag ==0&shield_flag !=1) { 02621 lives --; 02622 freeze(); 02623 lose_lives_delay_flag =1; 02624 } 02625 if (shoot_flag ==1) { 02626 t_rex_lives ++; 02627 if (t_rex_lives >=27-3*g_g1 -3*g_g2 ) { 02628 print_t_rex_flag =0; 02629 t_rex_movement =120; 02630 kill_score +=20; 02631 t_rex_lives =0; 02632 } 02633 } 02634 } 02635 02636 //Physics for quicksand 02637 void quick_sand() 02638 { 02639 print_quick_sand(); 02640 if (joystick.direction==LEFT) { 02641 quick_sand_movement +=recks_movement ; 02642 } else if (joystick.direction==RIGHT) { 02643 quick_sand_movement -=recks_movement ; 02644 } 02645 if (quick_sand_movement<7&quick_sand_movement>-5&jump_flag !=1) { 02646 lives -=5; 02647 falling_animation(); 02648 quick_sand_movement =85; 02649 if (quick_sand_movement <-8) { 02650 print_quick_sand_flag =0; 02651 } 02652 } 02653 } 02654 02655 //Heart physics 02656 void heart() 02657 { 02658 print_heart(); 02659 if (joystick.direction==LEFT) { 02660 heart_movement +=recks_movement ; 02661 } else if (joystick.direction==RIGHT) { 02662 heart_movement -=recks_movement ; 02663 } 02664 if (heart_movement<=7&g_jump>26) { 02665 heart_movement =90; 02666 print_heart_flag =0; 02667 lives ++; 02668 } 02669 } 02670 02671 //Ammo pickup physics 02672 void pickUp_ammo() 02673 { 02674 print_ammo_pickUp(); 02675 if (joystick.direction==LEFT) { 02676 ammo_movement +=recks_movement ; 02677 } else if (joystick.direction==RIGHT) { 02678 ammo_movement -=recks_movement ; 02679 } 02680 if (ammo_movement<=7&g_jump>26) { 02681 ammo_movement =90; 02682 print_ammo_flag =0; 02683 ammo +=5; 02684 ammo +=rand()%7; 02685 } 02686 } 02687 02688 //Speedboost physcis. Recks speed increases by one when pucked up 02689 void speed_boost() 02690 { 02691 print_speed_boost(); 02692 if (joystick.direction==LEFT) { 02693 speed_boost_movement +=recks_movement ; 02694 } else if (joystick.direction==RIGHT) { 02695 speed_boost_movement -=recks_movement ; 02696 } 02697 if (speed_boost_movement<=5&g_jump>26) { 02698 speed_boost_movement =120; 02699 print_speed_boost_flag =0; 02700 recks_movement ++; 02701 } 02702 } 02703 02704 //Shield physics 02705 void shield() 02706 { 02707 print_recks_shield(); 02708 recks_movement =0; 02709 jump_flag =0; 02710 shoot_flag =0; 02711 shield_counter ++; 02712 if (shield_counter >=10) { 02713 shield_counter =0; 02714 recks_movement =2; 02715 shield_score +=10; 02716 shield_flag =0; 02717 } 02718 } 02719 02720 02721 //Game funtion 02722 //Combines all the privious physics funtions 02723 //if the story mode is on then it ends after certain tasks are complete 02724 void Game() 02725 { 02726 int run_game=1; 02727 g_music_count =1; 02728 while (run_game==1) { 02729 ground(); 02730 set_difficulty(); 02731 if (g_Ticker_Game_flag ) { 02732 play_music(); 02733 g_Ticker_Game_flag =0; 02734 lcd.clear(); //Clear all the pixels on the LCD screen 02735 updateJoystick(); 02736 led_bar(); 02737 print_score(); 02738 generate_random_number(); 02739 if (lose_lives_delay_flag ==1) { 02740 lives_delay_loop ++; 02741 if (lives_delay_loop >=10) { //means that the delay between one life beeing lost and another one beeing lost is at least 1s 02742 lives_delay_loop =0; 02743 lose_lives_delay_flag =0; 02744 } 02745 02746 } 02747 if (ammo <=5) { 02748 if (i %8>=4) { 02749 print_ammo(); 02750 } 02751 } else { 02752 print_ammo(); 02753 } 02754 if (b_B) { 02755 jump_flag =1; 02756 } 02757 if (shoot_flag ==0) { 02758 bullet =9; 02759 if (joystick.direction==DOWN&jump_flag !=1) { 02760 bullet_height =42; 02761 } else { 02762 bullet_height =g_jump +4; 02763 } 02764 } else if (shoot_flag ==1&g_shoot_loop ==0) { 02765 g_shoot_loop ++; 02766 ammo --; 02767 if (joystick.direction==DOWN&jump_flag !=1) { 02768 bullet_height =42; 02769 } else { 02770 bullet_height =g_jump +4; 02771 } 02772 } 02773 if (b_A) { 02774 if (ammo <=0) { 02775 shoot_flag =0; 02776 } else { 02777 shoot_flag =1; 02778 } 02779 } 02780 if (joystick.direction==UP&score >=10&jump_flag !=1) { 02781 shield_flag =1; 02782 } else if (joystick.direction==UP&score <10&jump_flag !=1) { 02783 print_recks_still_gun(); 02784 } 02785 02786 Recks(); 02787 if (shield_flag ==1) { 02788 shield(); 02789 } 02790 if (print_rat_flag ==1) { 02791 rat(); 02792 } 02793 if (print_hound_flag ==1) { 02794 hound(); 02795 } 02796 if (print_bear_flag ==1) { 02797 bear(); 02798 } 02799 if (print_bird_flag ==1) { 02800 bird(); 02801 } 02802 if (print_cactus_flag ==1) { 02803 cactus(); 02804 } 02805 if (print_t_rex_flag ==1) { 02806 t_rex(); 02807 } 02808 if (print_fire_ball_flag ==1) { 02809 fire_ball(); 02810 } 02811 if (print_quick_sand_flag ==1) { 02812 quick_sand(); 02813 } 02814 if (print_heart_flag ==1) { 02815 heart(); 02816 } 02817 if (print_ammo_flag ==1) { 02818 pickUp_ammo(); 02819 } 02820 if (print_speed_boost_flag ==1) { 02821 speed_boost(); 02822 } 02823 if (recks_movement >=3&i %150==0) { 02824 recks_movement =2; 02825 } 02826 if (lives <=0) { 02827 run_game=Game_over(); //calls game over returns 1 if continue was selected returns 0 if back to menu 02828 } 02829 if (swJoy==1) { 02830 Pause(); 02831 } 02832 02833 02834 if (difficulty ==-1&story_mode_flag ==1) { 02835 if (i >70) { 02836 initialize_values(); 02837 return; 02838 } 02839 } else if (difficulty ==0&story_mode_flag ==1) { 02840 if (score >60) { 02841 return; 02842 } 02843 } else if (difficulty ==1&story_mode_flag ==1) { 02844 if (score >200) { 02845 return; 02846 } 02847 } else if (difficulty ==2&story_mode_flag ==1) { 02848 if (score >500) { 02849 return; 02850 } 02851 } else if (difficulty ==3&story_mode_flag ==1) { 02852 print_t_rex_flag =1; 02853 g_story_mode_win =0; 02854 if (t_rex_lives >=24) { 02855 print_t_rex_flag =0; 02856 g_story_mode_win =1; 02857 return; 02858 } 02859 } 02860 i ++; 02861 print_clouds(); 02862 } 02863 lcd.refresh(); 02864 sleep(); //puts mbed to sleep 02865 } 02866 } 02867 02868 //Funtion for pause 02869 void Pause() 02870 { 02871 int q; 02872 lcd.printString("PAUSED",25,3); 02873 ticker_wait(10); 02874 while (!swJoy) { 02875 q++; 02876 if (g_Ticker_Menu_flag ) { 02877 g_Ticker_Menu_flag =0; 02878 if (q>=20) { 02879 lcd.setBrightness(0); 02880 led=0; 02881 } 02882 } 02883 sleep(); //puts mbed to sleep 02884 } 02885 lcd.setBrightness(brightness ); 02886 led_bar(); 02887 } 02888 02889 02890 //Funtion that increases game difficuly as difficulty increases 02891 void set_difficulty() 02892 { 02893 switch(difficulty ) { 02894 case -1: 02895 break; 02896 case 0: 02897 if (random_num <3000) { 02898 print_cactus_flag =1; 02899 } else if (random_num >=3000&random_num <6000) { 02900 print_rat_flag =1; 02901 } else if (random_num >=6000&random_num <6100) { 02902 print_heart_flag =1; 02903 } 02904 break; 02905 case 1: 02906 if (random_num <3000) { 02907 print_cactus_flag =1; 02908 } else if (random_num >=3000&random_num <5000) { 02909 print_rat_flag =1; 02910 } else if (random_num >=5000&random_num <6000) { 02911 print_bird_flag =1; 02912 } else if (random_num >=6000&random_num <6050) { 02913 print_heart_flag =1; 02914 } else if (random_num >=6050&random_num <7000) { 02915 print_hound_flag =1; 02916 } else if (random_num >=7000&random_num <7200) { 02917 print_ammo_flag =1; 02918 } 02919 break; 02920 case 2: 02921 if (random_num <3000) { 02922 print_cactus_flag =1; 02923 } else if (random_num >=3000&random_num <5000) { 02924 print_rat_flag =1; 02925 } else if (random_num >=5000&random_num <6000) { 02926 print_bird_flag =1; 02927 } else if (random_num >=6000&random_num <6040) { 02928 print_heart_flag =1; 02929 } else if (random_num >=6040&random_num <7000) { 02930 print_hound_flag =1; 02931 } else if (random_num >=7000&random_num <7200) { 02932 print_ammo_flag =1; 02933 } else if (random_num >=7200&random_num <8000) { 02934 print_bear_flag =1; 02935 } else if (random_num >=8000&random_num <8200) { 02936 print_speed_boost_flag =1; 02937 } 02938 break; 02939 case 3: 02940 if (random_num <1000) { 02941 print_bear_flag =1; 02942 } else if (random_num >=1000&random_num <3000) { 02943 print_bird_flag =1; 02944 } else if (random_num >=3000&random_num <3010) { 02945 print_heart_flag =1; 02946 } else if (random_num >=3010&random_num <3050) { 02947 print_ammo_flag =1; 02948 } else if (random_num >=3050&random_num <6000) { 02949 print_cactus_flag =1; 02950 } else if (random_num >=6000&random_num <6100) { 02951 print_ammo_flag =1; 02952 print_t_rex_flag =1; 02953 } else if (random_num >=6100&random_num <7000) { 02954 print_rat_flag =1; 02955 } else if (random_num >=7000&random_num <8000) { 02956 print_hound_flag =1; 02957 } else if (random_num >=8000&random_num <8200) { 02958 print_speed_boost_flag =1; 02959 } 02960 break; 02961 case 4: 02962 if (random_num <1000) { 02963 print_bear_flag =1; 02964 } else if (random_num >=1000&random_num <3000) { 02965 print_bird_flag =1; 02966 } else if (random_num >=3000&random_num <3010) { 02967 print_heart_flag =1; 02968 } else if (random_num >=3010&random_num <3050) { 02969 print_ammo_flag =1; 02970 } else if (random_num >=3050&random_num <6000) { 02971 print_cactus_flag =1; 02972 } else if (random_num >=6000&random_num <6300) { 02973 print_ammo_flag =1; 02974 print_t_rex_flag =1; 02975 } else if (random_num >=6300&random_num <7000) { 02976 print_rat_flag =1; 02977 } else if (random_num >=7000&random_num <8000) { 02978 print_hound_flag =1; 02979 } else if (random_num >=8000&random_num <8200) { 02980 print_speed_boost_flag =1; 02981 } else if (random_num >=8200&random_num <9000) { 02982 print_quick_sand_flag =1; 02983 } 02984 break; 02985 } 02986 } 02987 02988 02989 //Game over funtion 02990 int Game_over() 02991 { 02992 led_bar(); 02993 lcd.clear(); //Clear all the pixels on the LCD screen 02994 sort_top_scores(); 02995 writeSD(); 02996 lcd.printString("GAME",25,1); 02997 lcd.printString("OVER",25,2); 02998 lcd.refresh(); 02999 ticker_wait(10); 03000 lcd.printString("A Retry",40,4); 03001 lcd.printString("B Back to Menu",0,5); 03002 lcd.refresh(); 03003 g_press_b_A_flag =0; 03004 g_press_b_B_flag =0; 03005 while (1) { 03006 if (g_press_b_A_flag |g_press_b_B_flag ) { 03007 if (g_press_b_A_flag ) { 03008 initialize_values(); 03009 g_press_b_A_flag =0; 03010 return 1; 03011 } else { 03012 initialize_values(); 03013 g_press_b_B_flag =0; 03014 return 0; 03015 } 03016 } 03017 sleep(); //puts mbed to sleep 03018 } 03019 } 03020 03021 //Print ammo 03022 void print_ammo() 03023 { 03024 for(int c=0; c<=2; c++) { // 2 beacause the the loop stats from 0 but the array size from 1 03025 for(int r=0; r<=4; r++) { 03026 for (int n=70; n<=74; n+=4) { 03027 if (n==74&ammo %10==0) { 03028 if (zero[r][c]==1) { 03029 lcd.setPixel(c+n,r); 03030 } else { 03031 lcd.clearPixel(c+n,r); 03032 } 03033 } else if (n==74&ammo %10==1) { 03034 if (one[r][c]==1) { 03035 lcd.setPixel(c+n,r); 03036 } else { 03037 lcd.clearPixel(c+n,r); 03038 } 03039 } else if (n==74&ammo %10==2) { 03040 if (two[r][c]==1) { 03041 lcd.setPixel(c+n,r); 03042 } else { 03043 lcd.clearPixel(c+n,r); 03044 } 03045 } else if (n==74&ammo %10==3) { 03046 if (three[r][c]==1) { 03047 lcd.setPixel(c+n,r); 03048 } else { 03049 lcd.clearPixel(c+n,r); 03050 } 03051 } else if (n==74&ammo %10==4) { 03052 if (four[r][c]==1) { 03053 lcd.setPixel(c+n,r); 03054 } else { 03055 lcd.clearPixel(c+n,r); 03056 } 03057 } else if (n==74&ammo %10==5) { 03058 if (five[r][c]==1) { 03059 lcd.setPixel(c+n,r); 03060 } else { 03061 lcd.clearPixel(c+n,r); 03062 } 03063 } else if (n==74&ammo %10==6) { 03064 if (six[r][c]==1) { 03065 lcd.setPixel(c+n,r); 03066 } else { 03067 lcd.clearPixel(c+n,r); 03068 } 03069 } else if (n==74&ammo %10==7) { 03070 if (seven[r][c]==1) { 03071 lcd.setPixel(c+n,r); 03072 } else { 03073 lcd.clearPixel(c+n,r); 03074 } 03075 } else if (n==74&ammo %10==8) { 03076 if (eight[r][c]==1) { 03077 lcd.setPixel(c+n,r); 03078 } else { 03079 lcd.clearPixel(c+n,r); 03080 } 03081 } else if (n==74&ammo %10==9) { 03082 if (nine[r][c]==1) { 03083 lcd.setPixel(c+n,r); 03084 } else { 03085 lcd.clearPixel(c+n,r); 03086 } 03087 } 03088 03089 if (n==70&(ammo %100>=0&ammo %100<10)) { 03090 if (zero[r][c]==1) { 03091 lcd.setPixel(c+n,r); 03092 } else { 03093 lcd.clearPixel(c+n,r); 03094 } 03095 } else if (n==70&(ammo %100>=10&ammo %100<20)) { 03096 if (one[r][c]==1) { 03097 lcd.setPixel(c+n,r); 03098 } else { 03099 lcd.clearPixel(c+n,r); 03100 } 03101 } else if (n==70&(ammo %100>=20&ammo %100<30)) { 03102 if (two[r][c]==1) { 03103 lcd.setPixel(c+n,r); 03104 } else { 03105 lcd.clearPixel(c+n,r); 03106 } 03107 } else if (n==70&(ammo %100>=30&ammo %100<40)) { 03108 if (three[r][c]==1) { 03109 lcd.setPixel(c+n,r); 03110 } else { 03111 lcd.clearPixel(c+n,r); 03112 } 03113 } else if (n==70&(ammo %100>=40&ammo %100<50)) { 03114 if (four[r][c]==1) { 03115 lcd.setPixel(c+n,r); 03116 } else { 03117 lcd.clearPixel(c+n,r); 03118 } 03119 } else if (n==70&(ammo %100>=50&ammo %100<60)) { 03120 if (five[r][c]==1) { 03121 lcd.setPixel(c+n,r); 03122 } else { 03123 lcd.clearPixel(c+n,r); 03124 } 03125 } else if (n==70&(ammo %100>=60&ammo %100<70)) { 03126 if (six[r][c]==1) { 03127 lcd.setPixel(c+n,r); 03128 } else { 03129 lcd.clearPixel(c+n,r); 03130 } 03131 } else if (n==70&(ammo %100>=70&ammo %100<80)) { 03132 if (seven[r][c]==1) { 03133 lcd.setPixel(c+n,r); 03134 } else { 03135 lcd.clearPixel(c+n,r); 03136 } 03137 } else if (n==70&(ammo %100>=80&ammo %100<90)) { 03138 if (eight[r][c]==1) { 03139 lcd.setPixel(c+n,r); 03140 } else { 03141 lcd.clearPixel(c+n,r); 03142 } 03143 } else if (n==70&(ammo %100>=90&ammo %100<100)) { 03144 if (nine[r][c]==1) { 03145 lcd.setPixel(c+n,r); 03146 } else { 03147 lcd.clearPixel(c+n,r); 03148 } 03149 } 03150 } 03151 } 03152 } 03153 for(int c=0; c<=14; c++) { //14 beacause the the loop stats from 0 but the array size from 1 03154 for(int r=0; r<=4; r++) { 03155 if (g_ammo[r][c]==0) { 03156 lcd.clearPixel(c+50,r); 03157 } else if (g_ammo[r][c]==1) { 03158 lcd.setPixel(c+50,r); 03159 } 03160 } 03161 } 03162 if (ammo >=99) { 03163 ammo =99; 03164 } 03165 lcd.refresh(); 03166 } 03167 03168 //Print score 03169 void print_score() 03170 { 03171 score =h_movement /10+kill_score -shield_score ; 03172 if (score <=0) { 03173 score =0; 03174 } 03175 for(int c=0; c<=2; c++) { //2 beacause the the loop stats from 0 but the array size from 1 03176 for(int r=0; r<=4; r++) { 03177 for (int n=24; n<=36; n+=4) { 03178 if (n==36&score %10==0) { 03179 if (zero[r][c]==1) { 03180 lcd.setPixel(c+n,r); 03181 } else { 03182 lcd.clearPixel(c+n,r); 03183 } 03184 } else if (n==36&score %10==1) { 03185 if (one[r][c]==1) { 03186 lcd.setPixel(c+n,r); 03187 } else { 03188 lcd.clearPixel(c+n,r); 03189 } 03190 } else if (n==36&score %10==2) { 03191 if (two[r][c]==1) { 03192 lcd.setPixel(c+n,r); 03193 } else { 03194 lcd.clearPixel(c+n,r); 03195 } 03196 } else if (n==36&score %10==3) { 03197 if (three[r][c]==1) { 03198 lcd.setPixel(c+n,r); 03199 } else { 03200 lcd.clearPixel(c+n,r); 03201 } 03202 } else if (n==36&score %10==4) { 03203 if (four[r][c]==1) { 03204 lcd.setPixel(c+n,r); 03205 } else { 03206 lcd.clearPixel(c+n,r); 03207 } 03208 } else if (n==36&score %10==5) { 03209 if (five[r][c]==1) { 03210 lcd.setPixel(c+n,r); 03211 } else { 03212 lcd.clearPixel(c+n,r); 03213 } 03214 } else if (n==36&score %10==6) { 03215 if (six[r][c]==1) { 03216 lcd.setPixel(c+n,r); 03217 } else { 03218 lcd.clearPixel(c+n,r); 03219 } 03220 } else if (n==36&score %10==7) { 03221 if (seven[r][c]==1) { 03222 lcd.setPixel(c+n,r); 03223 } else { 03224 lcd.clearPixel(c+n,r); 03225 } 03226 } else if (n==36&score %10==8) { 03227 if (eight[r][c]==1) { 03228 lcd.setPixel(c+n,r); 03229 } else { 03230 lcd.clearPixel(c+n,r); 03231 } 03232 } else if (n==36&score %10==9) { 03233 if (nine[r][c]==1) { 03234 lcd.setPixel(c+n,r); 03235 } else { 03236 lcd.clearPixel(c+n,r); 03237 } 03238 } 03239 03240 if (n==32&(score %100>=0&score %100<10)) { 03241 if (zero[r][c]==1) { 03242 lcd.setPixel(c+n,r); 03243 } else { 03244 lcd.clearPixel(c+n,r); 03245 } 03246 } else if (n==32&(score %100>=10&score %100<20)) { 03247 if (one[r][c]==1) { 03248 lcd.setPixel(c+n,r); 03249 } else { 03250 lcd.clearPixel(c+n,r); 03251 } 03252 } else if (n==32&(score %100>=20&score %100<30)) { 03253 if (two[r][c]==1) { 03254 lcd.setPixel(c+n,r); 03255 } else { 03256 lcd.clearPixel(c+n,r); 03257 } 03258 } else if (n==32&(score %100>=30&score %100<40)) { 03259 if (three[r][c]==1) { 03260 lcd.setPixel(c+n,r); 03261 } else { 03262 lcd.clearPixel(c+n,r); 03263 } 03264 } else if (n==32&(score %100>=40&score %100<50)) { 03265 if (four[r][c]==1) { 03266 lcd.setPixel(c+n,r); 03267 } else { 03268 lcd.clearPixel(c+n,r); 03269 } 03270 } else if (n==32&(score %100>=50&score %100<60)) { 03271 if (five[r][c]==1) { 03272 lcd.setPixel(c+n,r); 03273 } else { 03274 lcd.clearPixel(c+n,r); 03275 } 03276 } else if (n==32&(score %100>=60&score %100<70)) { 03277 if (six[r][c]==1) { 03278 lcd.setPixel(c+n,r); 03279 } else { 03280 lcd.clearPixel(c+n,r); 03281 } 03282 } else if (n==32&(score %100>=70&score %100<80)) { 03283 if (seven[r][c]==1) { 03284 lcd.setPixel(c+n,r); 03285 } else { 03286 lcd.clearPixel(c+n,r); 03287 } 03288 } else if (n==32&(score %100>=80&score %100<90)) { 03289 if (eight[r][c]==1) { 03290 lcd.setPixel(c+n,r); 03291 } else { 03292 lcd.clearPixel(c+n,r); 03293 } 03294 } else if (n==32&(score %100>=90&score %100<100)) { 03295 if (nine[r][c]==1) { 03296 lcd.setPixel(c+n,r); 03297 } else { 03298 lcd.clearPixel(c+n,r); 03299 } 03300 } 03301 if (n==28&(score %1000>=0&score %1000<100)) { 03302 if (zero[r][c]==1) { 03303 lcd.setPixel(c+n,r); 03304 } else { 03305 lcd.clearPixel(c+n,r); 03306 } 03307 } else if (n==28&(score %1000>=100&score %1000<200)) { 03308 if (one[r][c]==1) { 03309 lcd.setPixel(c+n,r); 03310 } else { 03311 lcd.clearPixel(c+n,r); 03312 } 03313 } else if (n==28&(score %1000>=200&score %1000<300)) { 03314 if (two[r][c]==1) { 03315 lcd.setPixel(c+n,r); 03316 } else { 03317 lcd.clearPixel(c+n,r); 03318 } 03319 } else if (n==28&(score %1000>=300&score %1000<400)) { 03320 if (three[r][c]==1) { 03321 lcd.setPixel(c+n,r); 03322 } else { 03323 lcd.clearPixel(c+n,r); 03324 } 03325 } else if (n==28&(score %1000>=400&score %1000<500)) { 03326 if (four[r][c]==1) { 03327 lcd.setPixel(c+n,r); 03328 } else { 03329 lcd.clearPixel(c+n,r); 03330 } 03331 } else if (n==28&(score %1000>=500&score %1000<600)) { 03332 if (five[r][c]==1) { 03333 lcd.setPixel(c+n,r); 03334 } else { 03335 lcd.clearPixel(c+n,r); 03336 } 03337 } else if (n==28&(score %1000>=600&score %1000<700)) { 03338 if (six[r][c]==1) { 03339 lcd.setPixel(c+n,r); 03340 } else { 03341 lcd.clearPixel(c+n,r); 03342 } 03343 } else if (n==28&(score %1000>=700&score %1000<800)) { 03344 if (seven[r][c]==1) { 03345 lcd.setPixel(c+n,r); 03346 } else { 03347 lcd.clearPixel(c+n,r); 03348 } 03349 } else if (n==28&(score %1000>=800&score %1000<900)) { 03350 if (eight[r][c]==1) { 03351 lcd.setPixel(c+n,r); 03352 } else { 03353 lcd.clearPixel(c+n,r); 03354 } 03355 } else if (n==28&(score %1000>=900&score %1000<1000)) { 03356 if (nine[r][c]==1) { 03357 lcd.setPixel(c+n,r); 03358 } else { 03359 lcd.clearPixel(c+n,r); 03360 } 03361 } 03362 if (n==24&(score %10000>=0&score %10000<1000)) { 03363 if (zero[r][c]==1) { 03364 lcd.setPixel(c+n,r); 03365 } else { 03366 lcd.clearPixel(c+n,r); 03367 } 03368 } else if (n==24&(score %10000>=1000&score %10000<2000)) { 03369 if (one[r][c]==1) { 03370 lcd.setPixel(c+n,r); 03371 } else { 03372 lcd.clearPixel(c+n,r); 03373 } 03374 } else if (n==24&(score %10000>=2000&score %10000<3000)) { 03375 if (two[r][c]==1) { 03376 lcd.setPixel(c+n,r); 03377 } else { 03378 lcd.clearPixel(c+n,r); 03379 } 03380 } else if (n==24&(score %10000>=3000&score %10000<4000)) { 03381 if (three[r][c]==1) { 03382 lcd.setPixel(c+n,r); 03383 } else { 03384 lcd.clearPixel(c+n,r); 03385 } 03386 } else if (n==24&(score %10000>=4000&score %10000<5000)) { 03387 if (four[r][c]==1) { 03388 lcd.setPixel(c+n,r); 03389 } else { 03390 lcd.clearPixel(c+n,r); 03391 } 03392 } else if (n==24&(score %10000>=5000&score %10000<6000)) { 03393 if (five[r][c]==1) { 03394 lcd.setPixel(c+n,r); 03395 } else { 03396 lcd.clearPixel(c+n,r); 03397 } 03398 } else if (n==24&(score %10000>=6000&score %10000<7000)) { 03399 if (six[r][c]==1) { 03400 lcd.setPixel(c+n,r); 03401 } else { 03402 lcd.clearPixel(c+n,r); 03403 } 03404 } else if (n==24&(score %10000>=7000&score %10000<8000)) { 03405 if (seven[r][c]==1) { 03406 lcd.setPixel(c+n,r); 03407 } else { 03408 lcd.clearPixel(c+n,r); 03409 } 03410 } else if (n==24&(score %10000>=8000&score %10000<9000)) { 03411 if (eight[r][c]==1) { 03412 lcd.setPixel(c+n,r); 03413 } else { 03414 lcd.clearPixel(c+n,r); 03415 } 03416 } else if (n==24&(score %10000>=9000&score %10000<10000)) { 03417 if (nine[r][c]==1) { 03418 lcd.setPixel(c+n,r); 03419 } else { 03420 lcd.clearPixel(c+n,r); 03421 } 03422 } 03423 } 03424 } 03425 } 03426 for(int c=0; c<=18; c++) { //18 beacause the the loop stats from 0 but the array size from 1 03427 for(int r=0; r<=4; r++) { 03428 if (g_score[r][c]==0) { 03429 lcd.clearPixel(c,r); 03430 } else if (g_score[r][c]==1) { 03431 lcd.setPixel(c,r); 03432 } 03433 } 03434 } 03435 lcd.refresh(); 03436 }
Generated on Fri Jul 22 2022 22:31:14 by
1.7.2