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: el14hzbm_Final_Project mbed
main.cpp
00001 /** 00002 @file main.cpp 00003 @brief Program implementation 00004 */ 00005 00006 #include "mbed.h" 00007 #include "N5110.h" 00008 #include "tone.h" 00009 #include "main.h" 00010 00011 #define PI 3.14159265359 00012 #define PAUSE 1 00013 #define PLAY 0 00014 00015 int main() 00016 { 00017 lcd.init(); //initialize the lcd 00018 initArray(); //fill array with sine sample 00019 button.rise(&button_isr); //will read the rise edge when button is pressed 00020 button.mode(PullDown); //external button is set as PullDown 00021 00022 while(1) { 00023 00024 intro(); //state 0 - introduction interface 00025 firstView(); //state 1 - main menu interface 00026 gameView(); //state 2 - game interface 00027 optionView(); //state 3 - option interface 00028 instructionView(); //state 4 - how to play interface 00029 brightnessView(); //state 5 - set up brightness interface 00030 finishView(g_score ); //state 6 - final score interface 00031 } 00032 } 00033 00034 void intro() //state 0 - introduction interface 00035 { 00036 if(state ==0) { 00037 00038 for(int k=90; k>5; k--) { 00039 lcd.printString("KAMIKAZE",k,1); //display game title in left moving motion 00040 lcd.printString("RACE",k+12,2); 00041 lcd.refresh(); 00042 wait(0.1); 00043 lcd.clear(); 00044 00045 if(g_button_flag ==1) { 00046 g_button_flag =0; 00047 state =1; 00048 break; 00049 } 00050 } 00051 state =1; 00052 } 00053 } 00054 00055 void firstView() //state 1 - main menu interface 00056 { 00057 if(state ==1) { 00058 pointer_x =20; 00059 pointer_y =31; 00060 00061 while(loop ==0) { 00062 sleepTimer.start(); // start timer 00063 00064 if(sleepTimer.read()<15) { //display all the main menu interface 00065 lcd.printString("KAMIKAZE",5,1); 00066 lcd.printString("RACE",17,2); 00067 lcd.drawLine(58,46,58,2,2); 00068 lcd.drawLine(67,46,67,2,2); 00069 lcd.drawLine(76,46,76,2,2); 00070 lcd.drawCar(60,10,1); 00071 lcd.drawCar(60,25,1); 00072 lcd.drawCar(69,23,1); 00073 lcd.printString("Start",14,4); 00074 lcd.printString("Option",14,5); 00075 firstViewPointer(); 00076 lcd.drawCar(5,pointer_y ,1); 00077 lcd.refresh(); 00078 wait(0.1); 00079 lcd.clear(); 00080 00081 if(g_button_flag ==1) { 00082 g_button_flag =0; 00083 loop =1; 00084 00085 if(pointer_y ==31) { 00086 state =2; //go to game state 00087 } else { 00088 state =3; //go to option state 00089 } 00090 } 00091 } else { //go to sleep mode after 15 second has passed 00092 sleepTimer.stop(); // stop the timer 00093 sleepTimer.reset(); // reset to 0 00094 SleepView(); 00095 } 00096 } 00097 loop =0; 00098 sleepTimer.stop(); // stop the timer 00099 sleepTimer.reset(); // reset to 0 00100 } 00101 } 00102 00103 void gameView() //state 2 - game interface 00104 { 00105 if(state ==2) { 00106 00107 initialGameInterface(); //function to initialize the game with countdown timer. 00108 initGameVar(); //function to initiate all variable used in the game 00109 00110 while(g_crash ==0) { //0 - crash not occur 00111 00112 for(int i=1; i<=g_level *20; i++) { 00113 carValue [i]=9*((rand()%6)+1)-5; //generate random position for all vehicle on the road 00114 } 00115 00116 for(int y_move=-5; y_move<100000; y_move++) { 00117 00118 if(game ==PLAY) { //when game is played 00119 crash(carValue ,y_move,g_score ,g_level ,car_x ,car_y ,delay ); //function to check whether crash occur 00120 playermovement(g_level ); //function to control the player's car movement 00121 lcd.refresh(); 00122 checkLastCar(g_level ); //function to check when will the last last car go out from the screen to finish level 00123 00124 if((y_move-(lastCar ))>40) { 00125 finishLevel(g_level ); //finish level when last car has passed through 00126 break; 00127 } 00128 if(g_crash ==1) { 00129 crashsound(); //play sound when crush happened 00130 wait(2); //delay to give time for new game 00131 00132 if(g_liveleft <=1) { //check if live is zero after crash occured 00133 lcd.clear(); // if zero, game stop 00134 break; 00135 } else { //if still has life 00136 g_crash =0; //continue the game 00137 g_liveleft =g_liveleft -1; //reduce the life 00138 g_level =g_level -1; //start at same level when crash occur 00139 car_x =22; //return the car back to initial position 00140 car_y =38; 00141 break; 00142 } 00143 } 00144 lcd.clear(); 00145 g_score =g_score +1; //increase the score by 1 after every loop 00146 } else { //when game is paused 00147 y_move=y_move-1; //fix y_move to make the vehicle static 00148 game_interface(g_score ,g_level ,g_liveleft ); 00149 lcd.printString("Paused",15,2); //display pause on the screen 00150 lcd.refresh(); 00151 } 00152 if (g_button_flag ==1) { //press button to paused/play the game. 00153 g_button_flag =0; 00154 pausesound(); 00155 wait(0.1); 00156 if(game == PLAY) { 00157 game = PAUSE; 00158 } else { 00159 game =PLAY; 00160 } 00161 } 00162 } 00163 g_level =g_level +1; 00164 } //when the game finished, move to finish View(display high score) 00165 state =6; 00166 finishView(g_score ); 00167 state =0; //goes back to main menu 00168 } 00169 } 00170 00171 void optionView() //state 3 - option interface 00172 { 00173 if(state ==3) { 00174 pointer_x =5; 00175 pointer_y =7; 00176 00177 while(loop ==0) { 00178 sleepTimer.start(); // start timer 00179 00180 if(sleepTimer.read()<15) { 00181 lcd.printString("Instruction",13,1); 00182 lcd.printString("Brightness",13,2); 00183 lcd.printString("Achievement",13,3); 00184 lcd.printString("Back",13,4); 00185 optionPointer(); 00186 lcd.drawCar(4,pointer_y ,1); 00187 lcd.refresh(); 00188 wait(0.1); 00189 lcd.clear(); 00190 00191 if(g_button_flag ==1) { 00192 g_button_flag =0; 00193 loop =1; 00194 00195 if(pointer_y ==7) { 00196 state =4;//go to instruction 00197 } else if(pointer_y ==15) { 00198 state =5;//go to brightness 00199 } else if(pointer_y ==31) { 00200 state =1;//go back 00201 } else { //pointer====23 00202 state =6;//go to achievement 00203 } 00204 } 00205 } else { 00206 sleepTimer.stop(); // stop the timer 00207 sleepTimer.reset(); // reset to 0 00208 SleepView(); 00209 } 00210 } 00211 loop =0; 00212 sleepTimer.stop(); // stop the timer 00213 sleepTimer.reset(); // reset to 0 00214 } 00215 } 00216 00217 void instructionView() //state 4 - how to play interface 00218 { 00219 if(state ==4) { 00220 00221 while(loop ==0) { 00222 sleepTimer.start(); // start timer 00223 00224 if(sleepTimer.read()<15) { 00225 lcd.printString("Make your way",0,0); //explain how to play the game 00226 lcd.printString("through the",0,1); 00227 lcd.printString("traffic by ",0,2); 00228 lcd.printString("avoiding all",0,3); 00229 lcd.printString("vehicles on",0,4); 00230 lcd.printString("the highway.",0,5); 00231 lcd.refresh(); 00232 wait(0.1); 00233 lcd.clear(); 00234 00235 if(g_button_flag ==1) { 00236 g_button_flag =0; 00237 loop =1; 00238 state =9; 00239 } 00240 } else { 00241 sleepTimer.stop(); // stop the timer 00242 sleepTimer.reset(); // reset to 0 00243 SleepView(); 00244 } 00245 } 00246 loop =0; 00247 sleepTimer.stop(); // stop the timer 00248 sleepTimer.reset(); // reset to 0 00249 } 00250 if(state ==9) { 00251 00252 while(loop ==0) { 00253 sleepTimer.start(); // start timer 00254 00255 if(sleepTimer.read()<15) { 00256 lcd.printString("You have ",0,0); 00257 lcd.printString("three lives",0,1); 00258 lcd.printString("at the ",0,2); 00259 lcd.printString("start of",0,3); 00260 lcd.printString("the game.",0,4); 00261 lcd.printString("Good Luck!!!",0,5); 00262 lcd.refresh(); 00263 wait(0.1); 00264 lcd.clear(); 00265 00266 if(g_button_flag ==1) { 00267 g_button_flag =0; 00268 loop =1; 00269 state =3; 00270 } 00271 } else { 00272 sleepTimer.stop(); // stop the timer 00273 sleepTimer.reset(); // reset to 0 00274 SleepView(); 00275 } 00276 } 00277 loop =0; 00278 sleepTimer.stop(); // stop the timer 00279 sleepTimer.reset(); // reset to 0 00280 } 00281 } 00282 00283 void brightnessView() //state 5 - set up brightness interface 00284 { 00285 if(state ==5) { 00286 brightness_adjuster =5; 00287 00288 while(loop ==0) { 00289 sleepTimer.start(); // start timer 00290 00291 if(sleepTimer.read()<15) { 00292 brightnessController(); 00293 lcd.printString("Adjust",25,1); 00294 lcd.printString("Brightness",13,2); 00295 lcd.printString("+",78,4); 00296 lcd.printString("-",2,4); 00297 lcd.setBrightness(brightness_adjuster /10); 00298 lcd.drawRect(1,27,brightness_adjuster *8,4,1); 00299 lcd.drawRect(1,27,81,4,0); 00300 lcd.refresh(); 00301 wait(0.1); 00302 lcd.clear(); 00303 00304 if(g_button_flag ==1) { 00305 g_button_flag =0; 00306 loop =1; 00307 state =3; 00308 } 00309 } else { 00310 sleepTimer.stop(); // stop the timer 00311 sleepTimer.reset(); // reset to 0 00312 SleepView(); 00313 } 00314 } 00315 loop =0; 00316 sleepTimer.stop(); // stop the timer 00317 sleepTimer.reset(); // reset to 0 00318 } 00319 } 00320 00321 void finishView(int g_score ) //state 6 - final score interface 00322 { 00323 if(state ==6) { 00324 00325 while(loop ==0) { 00326 sleepTimer.start(); // start timer 00327 00328 if(sleepTimer.read()<15) { 00329 char buffer[14]; 00330 int length = sprintf(buffer,"%2d",g_score/20); //display final score 00331 lcd.printString("Your",30,1); 00332 lcd.printString("Final Score",10,2); 00333 lcd.printString("Is",34,3); 00334 lcd.printString(buffer,34,4); 00335 lcd.refresh(); 00336 wait(0.1); 00337 lcd.clear(); 00338 00339 if(g_button_flag ==1) { 00340 g_button_flag =0; 00341 loop =1; 00342 state =3; 00343 } 00344 } else { 00345 sleepTimer.stop(); // stop the timer 00346 sleepTimer.reset(); // reset to 0 00347 SleepView(); 00348 } 00349 } 00350 loop =0; 00351 } 00352 } 00353 00354 void SleepView() //this function applies the sleep mode concept 00355 { //improve power effciency for the game system 00356 while(loop ==0) { //expand the battery lifetime. 00357 lcd.turnOff(); //also turn off the lcd scrren when not in used 00358 sleep(); 00359 00360 if(g_button_flag ==1) { 00361 g_button_flag =0; //if button pressed, turn on the screen back. 00362 lcd.init(); 00363 loop =1; 00364 } 00365 } 00366 loop =0; 00367 } 00368 00369 00370 00371 void crash(int carValue [],int opponent_y,int g_score ,int g_level ,int k,int l,int delay ) //function to check if crash occur 00372 { 00373 float carPixel[84][48]; //create array for vehicle on the road 00374 float enemyPixel[84][48]; 00375 00376 lcd.clear(); 00377 lcd.drawCar(k,l,1); 00378 lcd.refresh(); 00379 00380 for(int i=0; i<=54; i++) { 00381 for(int j=0; j<=48; j++) { 00382 carPixel[i][j]=lcd.getPixel(i,j); //check player's car pixel 00383 } 00384 } 00385 lcd.clear(); 00386 00387 for(int i=1; i<=(g_level*20); i++) { 00388 00389 if (g_level>=9) { //for this part, it draw different type of vehicle for given road lane. 00390 if (carValue[i]<10) { 00391 lcd.drawTruck(carValue[i],opponent_y-delay,1); //truck is drawn on most left lane 00392 } else if (carValue[i]<20) { 00393 lcd.drawVan(carValue[i],opponent_y-delay,1); //van is drawn second left lane 00394 } else if (carValue[i]<40) { 00395 lcd.drawCar(carValue[i],opponent_y-delay,1); //car is drawn on lane three and four 00396 } else { 00397 lcd.drawCarReverse(carValue[i],opponent_y-delay,1); //car is drawn in opposite direction for opposite lane 00398 } 00399 if(i%3==0) { 00400 delay=delay+20; 00401 } 00402 } else if(g_level>=5) { //the step is repeat for different level 00403 if (carValue[i]<10) { //higher the level, more car will be on the road to make it more difficult 00404 lcd.drawTruck(carValue[i],opponent_y-delay,1); 00405 } else if (carValue[i]<20) { 00406 lcd.drawVan(carValue[i],opponent_y-delay,1); 00407 } else if (carValue[i]<40) { 00408 lcd.drawCar(carValue[i],opponent_y-delay,1); 00409 } else { 00410 lcd.drawCarReverse(carValue[i],opponent_y-delay,1); 00411 } 00412 if(i%2==0) { 00413 delay=delay+20; 00414 } 00415 } else { 00416 if (carValue[i]<10) { 00417 lcd.drawTruck(carValue[i],opponent_y-delay,1); 00418 } else if (carValue[i]<20) { 00419 lcd.drawVan(carValue[i],opponent_y-delay,1); 00420 } else if (carValue[i]<40) { 00421 lcd.drawCar(carValue[i],opponent_y-delay,1); 00422 } else { 00423 lcd.drawCarReverse(carValue[i],opponent_y-delay,1); 00424 } 00425 delay=delay+20; 00426 } 00427 } 00428 lcd.refresh(); 00429 for(int i=0; i<=54; i++) { 00430 for(int j=0; j<=48; j++) { 00431 enemyPixel[i][j]=lcd.getPixel(i,j); //now, check the pixel for traffic's car 00432 } 00433 } 00434 for(int i=0; i<=54; i++) { 00435 for(int j=0; j<=48; j++) { 00436 if(enemyPixel[i][j]!=0 && carPixel[i][j]!=0) { //now, check if player's car pixel overlap with traffic's car pixel 00437 lcd.printString("!!CRASH!!",2,2); //if yes, print crash 00438 g_crash =1; 00439 } 00440 } 00441 } 00442 game_interface(g_score,g_level,g_liveleft ); //put all the other displaying stuff to finish off the interface 00443 lcd.drawCar(k,l,1); 00444 lcd.refresh(); 00445 double ki=-((g_level )); 00446 duration =(0.02*exp(ki))+0.005; //use exponential decay equation to be used for speed control at increasing level 00447 00448 if(opponent_y%5==0) { 00449 gameplaysound(duration ); 00450 } else { 00451 wait(duration ); 00452 } 00453 } 00454 00455 void game_interface(int g_score ,int g_level ,int g_liveleft ) //function to provide game interface during gameplay 00456 { 00457 score(61,2); 00458 level(61,18); 00459 char buffer[14]; 00460 int length = sprintf(buffer,"%2d",g_score/20); 00461 lcd.printString(buffer,62,1); 00462 int length1 = sprintf(buffer,"%2d",g_level); 00463 lcd.printString(buffer,62,3); 00464 live(g_liveleft); 00465 roadline(g_score); 00466 lcd.drawRect(59,33,g_level*2,4,1); 00467 lcd.drawRect(59,33,22,4,0); 00468 } 00469 00470 void playermovement(int g_level ) //function to control the player's car movement 00471 { 00472 if (g_level>=3) { //at higher level, speed is faster, so give small scale movement to give better handling 00473 playerSpeed =1; 00474 } else if(g_level<3) { //at lower level, speed is slower, so high scale movemement is allowed. 00475 playerSpeed =2; 00476 } 00477 00478 if(xPot>=0.7f) { //joystick movement control the screen is shown here 00479 if(car_x >-3 && car_x <49) { 00480 car_x =car_x +playerSpeed ; 00481 } 00482 } 00483 if(xPot<=0.3f) { 00484 if(car_x >5 && car_x <57) { 00485 car_x =car_x -playerSpeed ; 00486 } 00487 } 00488 if(yPot>0.7f) { 00489 if(car_y >5 && car_y <48) { 00490 car_y =car_y -playerSpeed ; 00491 } 00492 } 00493 if(yPot<0.3f) { 00494 00495 if(car_y >-3 && car_y <38) { 00496 car_y =car_y +playerSpeed ; 00497 } 00498 } 00499 } 00500 00501 void checkLastCar(int g_level ) //check for last car will be on the screen 00502 { //needed in order to stop the for loop and finish the level 00503 if(g_level>=9) { 00504 lastCar =g_level*33*4; 00505 } else if(g_level>=5) { 00506 lastCar =g_level*50*4; 00507 } else { 00508 lastCar =g_level*100*4; 00509 } 00510 } 00511 00512 void finishLevel(int g_level ) //display the high score screen when the game is finish 00513 { 00514 char buffer[48]; 00515 int length = sprintf(buffer,"%2d",g_level); 00516 lcd.printString(buffer,24,3); 00517 lcd.printString("Finish",10,1); 00518 lcd.printString("Level",14,2); 00519 lcd.refresh(); 00520 wait(2); 00521 lcd.clear(); 00522 delay =0; 00523 car_x =22; 00524 car_y =38; 00525 } 00526 00527 void initialGameInterface() //provide initial countdown before the game start 00528 { 00529 for(int countdown=5; countdown>=1; countdown--) { //countdown from 5-1 00530 score(61,2); 00531 level(61,18); 00532 lcd.printString("0",68,1); 00533 lcd.printString("1",68,3); 00534 lcd.drawHeart(59,40,3,1); 00535 00536 lcd.drawLine(0,47,0,0,1); 00537 lcd.drawLine(83,47,83,0,1); 00538 lcd.drawLine(83,0,0,0,1); 00539 lcd.drawLine(83,47,0,47,1); 00540 00541 lcd.drawRect(59,33,22,4,1); 00542 lcd.printString("Game",15,1); 00543 lcd.printString("Start",14,2); 00544 lcd.printString("In",12,3); 00545 char buffer[14]; 00546 int length = sprintf(buffer,"%2d",countdown); 00547 lcd.printString(buffer,30,3); 00548 00549 lcd.refresh(); 00550 wait(1); 00551 lcd.clear(); 00552 } 00553 } 00554 00555 void initGameVar() //initiate every variable use in the game before the game start 00556 { 00557 g_crash =0; 00558 g_liveleft =3; 00559 g_level =1; 00560 g_score =0; 00561 car_x =22; 00562 car_y =38; 00563 } 00564 00565 void firstViewPointer() //control the pointer on main menu 00566 { 00567 if(yPot>0.7f) { 00568 pointer_y =31; 00569 } 00570 if(yPot<0.3f) { 00571 pointer_y =39; 00572 } 00573 } 00574 00575 void optionPointer() //control the pointer on option menu 00576 { 00577 if(yPot>0.7f) { 00578 if(pointer_y >11 && pointer_y <32) { 00579 pointer_y =pointer_y -8; 00580 } 00581 } 00582 if(yPot<0.3f) { 00583 if(pointer_y >5 && pointer_y <28) { 00584 pointer_y =pointer_y +8; 00585 } 00586 } 00587 } 00588 00589 void brightnessController() //control the brightness by using joystick 00590 { 00591 if(xPot>0.7f) { 00592 if(brightness_adjuster >=0 && brightness_adjuster <=9) { 00593 brightness_adjuster =brightness_adjuster +1; 00594 } 00595 } 00596 if(xPot<0.3f) { 00597 if(brightness_adjuster >=1 && brightness_adjuster <=10) { 00598 brightness_adjuster =brightness_adjuster -1; 00599 } 00600 } 00601 } 00602 00603 void initArray() 00604 { 00605 // create LUT - loop through array and calculate sine wave samples 00606 for (int i = 0; i < n ; i++) { 00607 y [i] = 60 + 60*sin(i*2*PI/n); 00608 } 00609 00610 } 00611 00612 void tone(float frequency,float duration ) 00613 { 00614 green=1; //turn on LED 00615 00616 if (frequency > 0) { // a frequency of 0 indicates no note played so only play a note if frequency is not 0 00617 00618 float dt = 1.0f/(frequency*n ) - (1.34e-6 + 1e-6); // calculate time step - take into account DAC time and wait() offset 00619 00620 noteTimer.start(); // start timer 00621 00622 while(noteTimer.read() < duration ) { // keep looping while timer less than duration 00623 00624 for (int i = 0; i < n ; i++) { // loop through samples and output analog waveform 00625 buzzer = y [i]; 00626 wait(dt); // leave appropriate delay for frequency 00627 } 00628 } 00629 00630 noteTimer.stop(); // stop the timer 00631 noteTimer.reset(); // reset to 0 00632 00633 } else { // if no note played, have a simple delay 00634 wait(duration); 00635 } 00636 00637 green = 0; // turn off LEDs 00638 } 00639 00640 void gameplaysound(float duration ) 00641 { 00642 float noteArray[] = { 00643 // provide sound during the time game is played 00644 NOTE_G3, 00645 }; 00646 00647 int notes = sizeof(noteArray)/sizeof(float); 00648 for(int i=0; i < notes; i++) { 00649 tone(noteArray[i],duration); 00650 00651 } 00652 } 00653 00654 void crashsound() 00655 { 00656 float noteArray[] = { 00657 // provide sound during the time game is played 00658 NOTE_G5, NOTE_F6,0,NOTE_F6,NOTE_F6,NOTE_E6,0,NOTE_D6,NOTE_C6,NOTE_G5,0,NOTE_E5,NOTE_C5 00659 }; 00660 float noteDuration[] = { 00661 4,4,4,4,4,4,4,4,4,4,4,4,4 00662 }; 00663 int notes = sizeof(noteArray)/sizeof(float); 00664 for(int i=0; i < notes; i++) { 00665 tone(noteArray[i],60.0f/(BPM *noteDuration[i])); 00666 00667 } 00668 } 00669 00670 void pausesound() 00671 { 00672 float noteArray[] = { 00673 // provide sound during the time game is played 00674 NOTE_E6,NOTE_C6,NOTE_E6,NOTE_C6, 00675 }; 00676 float noteDuration[] = { 00677 8,8,8,8 00678 }; 00679 int notes = sizeof(noteArray)/sizeof(float); 00680 for(int i=0; i < notes; i++) { 00681 tone(noteArray[i],60.0f/(BPM *noteDuration[i])); 00682 00683 } 00684 } 00685 00686 void finishsound() 00687 { 00688 float noteArray[] = { 00689 // provide sound during the time game is played 00690 NOTE_E6,NOTE_C6,NOTE_E6,NOTE_C6, 00691 }; 00692 float noteDuration[] = { 00693 8,8,8,8 00694 }; 00695 int notes = sizeof(noteArray)/sizeof(float); 00696 for(int i=0; i < notes; i++) { 00697 tone(noteArray[i],60.0f/(BPM *noteDuration[i])); 00698 00699 } 00700 } 00701 00702 void live(int liveleft) //draw how many life left on the screen 00703 { 00704 lcd.drawHeart(59,40,liveleft,1); 00705 lcd.refresh(); 00706 } 00707 00708 void roadline(int moving) //draw the road line +border line on the screen 00709 { //road line 00710 lcd.drawLine(11,46,11,2,2); 00711 lcd.drawLine(20,46,20,2,2); 00712 lcd.drawLine(29,46,29,2,2); 00713 lcd.drawLine(38,45,38,2,1); 00714 lcd.drawLine(47,46,47,2,2); 00715 //border line 00716 lcd.drawLine(0,47,0,0,1); 00717 lcd.drawLine(83,47,83,0,1); 00718 lcd.drawLine(83,0,0,0,1); 00719 lcd.drawLine(83,47,0,47,1); 00720 00721 if(moving%2!=0) { 00722 lcd.drawLine(2,46,2,2,2); 00723 lcd.drawLine(56,46,56,2,2); 00724 lcd.refresh(); 00725 } else { 00726 lcd.drawLine(2,45,2,1,2); 00727 lcd.drawLine(56,45,56,1,2); 00728 lcd.refresh(); 00729 } 00730 } 00731 00732 void score(int m,int my) //display the score text on the screen 00733 { 00734 //show score title 00735 lcd.setPixel(m,my); 00736 lcd.setPixel(m,my+1); 00737 lcd.setPixel(m,my+2); 00738 lcd.setPixel(m,my+4); 00739 lcd.setPixel(m+1,my); 00740 lcd.setPixel(m+1,my+2); 00741 lcd.setPixel(m+1,my+4); 00742 lcd.setPixel(m+2,my); 00743 lcd.setPixel(m+2,my+2); 00744 lcd.setPixel(m+2,my+3); 00745 lcd.setPixel(m+2,my+4); 00746 lcd.setPixel(m+4,my); 00747 lcd.setPixel(m+4,my+1); 00748 lcd.setPixel(m+4,my+2); 00749 lcd.setPixel(m+4,my+3); 00750 lcd.setPixel(m+4,my+4); 00751 lcd.setPixel(m+5,my); 00752 lcd.setPixel(m+5,my+4); 00753 lcd.setPixel(m+6,my); 00754 lcd.setPixel(m+6,my+4); 00755 lcd.setPixel(m+8,my); 00756 lcd.setPixel(m+8,my+1); 00757 lcd.setPixel(m+8,my+2); 00758 lcd.setPixel(m+8,my+3); 00759 lcd.setPixel(m+8,my+4); 00760 lcd.setPixel(m+9,my); 00761 lcd.setPixel(m+9,my+4); 00762 lcd.setPixel(m+10,my); 00763 lcd.setPixel(m+10,my+1); 00764 lcd.setPixel(m+10,my+2); 00765 lcd.setPixel(m+10,my+3); 00766 lcd.setPixel(m+10,my+4); 00767 lcd.setPixel(m+12,my); 00768 lcd.setPixel(m+12,my+1); 00769 lcd.setPixel(m+12,my+2); 00770 lcd.setPixel(m+12,my+3); 00771 lcd.setPixel(m+12,my+4); 00772 lcd.setPixel(m+13,my); 00773 lcd.setPixel(m+13,my+2); 00774 lcd.setPixel(m+14,my); 00775 lcd.setPixel(m+14,my+1); 00776 lcd.setPixel(m+14,my+3); 00777 lcd.setPixel(m+14,my+4); 00778 lcd.setPixel(m+16,my); 00779 lcd.setPixel(m+16,my+1); 00780 lcd.setPixel(m+16,my+2); 00781 lcd.setPixel(m+16,my+3); 00782 lcd.setPixel(m+16,my+4); 00783 lcd.setPixel(m+17,my); 00784 lcd.setPixel(m+17,my+2); 00785 lcd.setPixel(m+17,my+4); 00786 lcd.setPixel(m+18,my); 00787 lcd.setPixel(m+18,my+4); 00788 } 00789 00790 void level(int x1,int y1) //display the level text on the screen 00791 { 00792 int x0=x1; 00793 int y0=y1; 00794 lcd.drawLine(x1,y1+4,x0,y0,1); 00795 lcd.drawLine(x1+2,y1+4,x0,y0+4,1); 00796 lcd.drawLine(x1+4,y1+4,x0+4,y0,1); 00797 lcd.drawLine(x1+6,y1,x0+4,y0,1); 00798 lcd.drawLine(x1+6,y1+4,x0+4,y0+4,1); 00799 lcd.setPixel(x1+5,y1+2); 00800 lcd.drawLine(x1+8,y1+3,x0+8,y0,1); 00801 lcd.drawLine(x1+10,y1+3,x0+10,y0,1); 00802 lcd.setPixel(x1+9,y1+4); 00803 lcd.drawLine(x1+12,y1+4,x0+12,y0,1); 00804 lcd.drawLine(x1+14,y1,x0+12,y0,1); 00805 lcd.drawLine(x1+14,y1+4,x0+12,y0+4,1); 00806 lcd.setPixel(x1+13,y1+2); 00807 lcd.drawLine(x1+16,y1+4,x0+16,y0,1); 00808 lcd.drawLine(x1+18,y1+4,x0+16,y0+4,1); 00809 } 00810 00811 void button_isr() //use for interrupt 00812 { 00813 g_button_flag =1; 00814 }
Generated on Wed Jul 20 2022 02:51:26 by
1.7.2