RUOFAN LI / Mbed 2 deprecated el17rl

Dependencies:   mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers homepage.cpp Source File

homepage.cpp

00001 #include "homepage.h"
00002 
00003 Homepage::homepage(){
00004     
00005 }
00006 
00007 Homepage::~homepage()
00008 {}
00009 
00010 void Homepage::welcome(N5110 &lcd,BusOut &output,Bgm &bgm) 
00011 {
00012     //show "Spaceship"
00013     lcd.printString("   Spaceship   ",0,1);  
00014     lcd.refresh();
00015     drawEverything(lcd);
00016     lcd.refresh();
00017     output=0b000000;
00018     
00019     //welcome bgm
00020     bgm.welcome();
00021     output=0b111111;
00022     lcd.clear();
00023 }
00024 void Homepage::over(N5110 &lcd,BusOut &output) 
00025 {
00026     //show game over
00027     lcd.printString(" You are failed ",0,1);   
00028     lcd.printString(" Press Start ",0,4);
00029     lcd.refresh();
00030     wait(1.0f);
00031     output=0b000000;
00032     wait(1.0f);
00033     output=0b111111;
00034     lcd.clear();
00035 }
00036 void Homepage::homepage(N5110 &lcd,InterruptIn &buttonA, InterruptIn &start,int *score,int n)
00037 {
00038     //show Homepage and check the pressed button 
00039     lcd.refresh();
00040     while(1){
00041         
00042         lcd.printString(" Press Start to start ",0,0);
00043         lcd.printString(" A Rules",0,2);
00044         lcd.refresh();
00045         
00046         if(buttonA){
00047             wait(0.5f);
00048             lcd.clear(); 
00049             //show the game rule
00050             rules(lcd,buttonA);
00051         }else if(start){
00052             lcd.clear(); //start the game
00053             break;
00054         }
00055     }
00056     
00057 }
00058 
00059 
00060 void Homepage::displayCurScore(N5110 &lcd,int score){
00061     char buffer[4];
00062     sprintf(buffer,"%d",score);
00063     lcd.printString(buffer,0,0);
00064 }
00065 void Homepage::drawEverything(N5110 &lcd){
00066     
00067    int Spaceship[15][10] = {
00068    0,0,0,0,0,0,0,0,0,0,
00069    0,0,0,0,1,1,0,0,0,0,
00070    0,0,0,0,1,1,0,0,0,0,
00071    0,0,1,1,0,0,1,1,0,0,
00072    0,1,1,1,1,1,1,1,1,0,
00073    0,1,1,1,1,1,1,1,1,0,
00074    1,1,1,1,1,1,1,1,1,1,
00075    1,1,1,1,1,1,1,1,1,1,
00076    1,1,1,1,1,1,1,1,1,1,
00077    1,1,1,1,1,1,1,1,1,1,
00078    1,1,1,1,1,1,1,1,1,1,
00079    1,1,1,1,0,0,1,1,1,1,
00080    0,1,1,1,0,0,1,1,1,0,
00081    0,0,1,1,0,0,1,1,0,0,
00082    0,0,0,1,1,1,1,0,0,0,
00083    0,0,0,0,0,0,0,0,0,0,
00084     //draw spaceship
00085     Bitmap sprite2(_Spaceship, 16, 10); 
00086     sprite2.render(lcd, 28, 28); 
00087 }
00088 void Homepage::rules(N5110 &lcd,InterruptIn &buttonA) {
00089     //show game rules
00090     while(1) {
00091         lcd.clear();
00092         lcd.printString("press X to fire",0,0);
00093         lcd.printString("use Joystick to move",0,1);
00094         lcd.printString("You need to destroy UFO",0,2);       
00095         lcd.printString("Don't let a UFO come near you",0,3);
00096         lcd.printString("Press B to go back",0,5);
00097         lcd.refresh();
00098         if(buttonB) {
00099             lcd.clear();
00100             wait(0.5f);
00101             return;
00102         }
00103     }
00104 }
00105 int homepage::again(N5110 &lcd,int score,InterruptIn &buttonX,InterruptIn &buttonY){
00106     
00107     lcd.clear();
00108     while(1){
00109         if(score>10){
00110             //if score > 10, player have enough POINTS to replay when he is defeated.
00111             lcd.printString("Play Again?",0,0);
00112             lcd.printString("Price: 10",0,2);
00113             lcd.printString("X Yes",0,3);
00114             lcd.printString("Y No",0,4);
00115             lcd.refresh();
00116             if(buttonX){
00117                 wait(0.5f);
00118                 lcd.clear();
00119                 return -10;
00120             }else if(buttonY){
00121                 wait(0.5f);
00122                 lcd.clear();
00123                 return 0;
00124             }
00125         }else{
00126             // player doesn't have enough scores , so game over directly
00127             lcd.printString("Fail",0,1);
00128             lcd.printString("Press Y return",0,2);
00129             lcd.refresh();
00130             if(buttonY){
00131                 wait(0.5f);
00132                 lcd.clear();
00133                 return 0;
00134             }
00135         }
00136     }
00137 
00138 }