Philip Park / Mbed 2 deprecated TEST

Dependencies:   4DGL-uLCD-SE PinDetect mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 #include "mbed.h"
00002 #include "MMA8452.h"
00003 #include "uLCD_4DGL.h"
00004 #include "PinDetect.h"
00005 #include "Speaker.h"
00006 
00007 
00008 #define ASTEROID_HEIGHT 12
00009 #define ASTEROID_WIDTH 15
00010 #define SPRITE_MAX 15
00011 #define EARTH_WIDTH 10
00012 #define EARTH_HEIGHT 10
00013 #define EXPLOSION1_WIDTH 20
00014 
00015 #define SCREEN_MAX 125
00016 #define SCREEN_MIN 1
00017 #define NUM_ASTEROIDS 4
00018 
00019 #define Q 0x808000 //OLIVE
00020 #define I 0x008000 //GREEN
00021 #define S 0xC0C0C0 //SILVER
00022 #define C 0x17202A //UFO GLASS
00023 #define D 0x797D7F //DARK GREY
00024 #define L 0x00FF00 //LIME
00025 #define P 0xFF00FF //PINK
00026 #define R 0xF1C40F //YELLOW
00027 #define O 0xF39C12 //ORANGE
00028 #define G 0xAAB7B8 //GREY
00029 #define _ 0x000000 //BLACK
00030 #define X 0xFFFFFF //WHITE
00031 #define B 0x0000FF //BLUE
00032 #define r 0xFF0000 //RED
00033 
00034 int asteroid_sprite_1[ASTEROID_HEIGHT * ASTEROID_WIDTH] = {
00035     _,_,_,_,X,X,X,X,X,X,X,X,_,_,_,
00036     _,_,_,X,_,_,_,_,_,_,_,_,X,_,_,
00037     _,_,X,_,_,_,_,_,_,_,_,_,X,_,_,
00038     _,X,_,_,_,_,_,_,_,_,_,_,X,_,_,
00039     X,X,X,X,_,_,_,_,_,_,_,_,_,X,_,
00040     _,_,_,X,_,_,_,_,_,_,_,_,_,X,_,
00041     _,_,X,_,_,_,_,_,_,_,_,_,_,X,_,
00042     _,X,_,_,_,_,_,X,_,_,_,_,_,X,_,
00043     X,_,_,_,_,_,X,X,_,_,_,_,X,_,_,
00044     _,X,_,_,_,X,_,X,_,_,_,_,X,_,_,
00045     _,_,X,_,X,_,_,X,_,_,_,X,_,_,_,
00046     _,_,_,X,_,_,_,X,X,X,X,_,_,_,_
00047 };
00048 
00049 int asteroid_sprite_2[ASTEROID_HEIGHT * ASTEROID_WIDTH] = {
00050     _,_,_,_,X,_,_,_,_,_,_,_,X,_,_,
00051     _,_,_,X,_,X,_,_,_,_,_,X,_,X,_,
00052     _,_,X,_,_,_,X,_,_,_,X,_,_,_,X,
00053     _,X,_,_,_,_,_,X,_,X,_,_,_,X,_,
00054     X,_,_,_,_,_,_,_,X,_,_,_,X,_,_,
00055     X,_,_,_,_,_,_,_,_,_,_,X,_,_,_,
00056     X,_,_,_,_,_,_,_,_,_,_,_,X,_,_,
00057     X,_,_,_,_,_,_,_,_,_,_,_,_,X,_,
00058     X,_,_,_,_,_,_,_,_,_,_,_,_,_,X,
00059     _,X,_,_,_,_,_,_,_,_,_,_,_,X,_,
00060     _,_,X,_,_,_,_,_,_,_,_,_,X,_,_,
00061     _,_,_,X,X,X,X,X,X,X,X,X,_,_,_
00062 };
00063 
00064 int asteroid_sprite_3[ASTEROID_HEIGHT * ASTEROID_WIDTH] = {
00065     _,_,_,_,X,X,X,X,X,X,X,_,_,_,_,
00066     _,_,_,X,_,_,_,_,_,_,_,X,X,_,_,
00067     _,_,X,_,_,_,_,_,_,_,_,_,_,X,X,
00068     _,_,_,X,_,_,_,_,_,_,_,_,X,X,_,
00069     X,X,X,X,_,_,_,_,_,_,X,X,_,_,_,
00070     X,_,_,_,_,_,_,_,X,X,_,_,_,_,_,
00071     X,_,_,_,_,_,_,_,_,_,X,X,_,_,_,
00072     X,_,_,_,_,_,_,_,_,_,_,_,X,X,_,
00073     X,_,_,_,_,_,_,_,X,_,_,_,_,_,X,
00074     _,X,_,_,_,_,X,X,_,X,_,_,_,X,_,
00075     _,_,X,_,X,X,_,_,_,_,X,_,X,_,_,
00076     _,_,_,X,_,_,_,_,_,_,_,X,_,_,_
00077 };
00078 
00079 int asteroid_sprite_4[ASTEROID_HEIGHT * ASTEROID_WIDTH] = {
00080     _,_,_,_,X,X,_,_,_,_,_,_,X,_,_,
00081     _,_,_,X,_,_,X,X,_,_,X,X,_,X,_,
00082     _,_,X,_,_,_,_,_,X,X,_,_,_,_,X,
00083     _,X,_,_,_,_,_,_,_,_,_,_,_,X,_,
00084     _,_,X,_,_,_,_,_,_,_,_,_,X,_,_,
00085     _,_,_,X,_,_,_,_,_,_,_,X,_,_,_,
00086     _,_,X,_,_,_,_,_,_,_,_,_,X,_,_,
00087     _,X,_,_,_,_,_,_,_,_,_,_,_,X,_,
00088     X,_,_,_,_,_,X,_,_,_,_,_,_,_,X,
00089     _,X,_,_,_,X,_,X,X,_,_,_,_,X,_,
00090     _,_,X,_,X,_,_,_,_,X,X,_,X,_,_,
00091     _,_,_,X,_,_,_,_,_,_,_,X,_,_,_
00092 };
00093 
00094 int spaceship_explode[EARTH_WIDTH *EARTH_HEIGHT] = {
00095     _,_,r,r,r,r,r,r,_,_,
00096     _,r,r,r,r,r,r,r,r,_,
00097     r,r,r,r,r,r,r,r,r,r,
00098     r,r,r,r,r,r,r,r,r,r,
00099     r,r,r,r,r,r,r,r,r,r,
00100     r,r,r,r,r,r,r,r,r,r,
00101     r,r,r,r,r,r,r,r,r,r,
00102     r,r,r,r,r,r,r,r,r,r,
00103     _,r,r,r,r,r,r,r,r,_,
00104     _,_,r,r,r,r,r,r,_,_,
00105 };
00106 
00107 int spaceship_earth1[EARTH_WIDTH *EARTH_HEIGHT] = {
00108     _,_,S,S,S,S,S,S,_,_,
00109     _,S,I,I,I,I,I,I,S,_,
00110     S,I,I,I,I,I,I,I,I,S,
00111     S,I,I,I,I,I,I,I,I,S,
00112     S,I,I,I,I,I,I,I,I,S,
00113     S,I,I,I,I,I,I,I,I,S,
00114     S,I,I,I,I,I,I,I,I,S,
00115     S,I,I,I,I,I,I,I,I,S,
00116     S,I,I,I,I,I,I,I,S,_,
00117     _,S,S,S,S,S,S,S,_,_,
00118 };
00119 
00120 
00121 int earth_update[EARTH_WIDTH *EARTH_HEIGHT] = {
00122     _,_,_,_,_,_,_,_,_,_,
00123     _,_,_,_,_,_,_,_,_,_,
00124     _,_,_,_,_,_,_,_,_,_,
00125     _,_,_,_,_,_,_,_,_,_,
00126     _,_,_,_,_,_,_,_,_,_,
00127     _,_,_,_,_,_,_,_,_,_,
00128     _,_,_,_,_,_,_,_,_,_,
00129     _,_,_,_,_,_,_,_,_,_,
00130     _,_,_,_,_,_,_,_,_,_,
00131     _,_,_,_,_,_,_,_,_,_,
00132 };
00133 
00134 int asteroid_update[ASTEROID_HEIGHT * ASTEROID_WIDTH] = {
00135     _,_,_,_,_,_,_,_,_,_,_,_,_,_,_,
00136     _,_,_,_,_,_,_,_,_,_,_,_,_,_,_,
00137     _,_,_,_,_,_,_,_,_,_,_,_,_,_,_,
00138     _,_,_,_,_,_,_,_,_,_,_,_,_,_,_,
00139     _,_,_,_,_,_,_,_,_,_,_,_,_,_,_,
00140     _,_,_,_,_,_,_,_,_,_,_,_,_,_,_,
00141     _,_,_,_,_,_,_,_,_,_,_,_,_,_,_,
00142     _,_,_,_,_,_,_,_,_,_,_,_,_,_,_,
00143     _,_,_,_,_,_,_,_,_,_,_,_,_,_,_,
00144     _,_,_,_,_,_,_,_,_,_,_,_,_,_,_,
00145     _,_,_,_,_,_,_,_,_,_,_,_,_,_,_,
00146     _,_,_,_,_,_,_,_,_,_,_,_,_,_,_
00147 };
00148 
00149 uLCD_4DGL uLCD(p28, p27, p29); 
00150 Serial pc(USBTX,USBRX);
00151 
00152 class ScreenObject
00153 {
00154 protected:
00155     int x_pos, y_pos;
00156 public:
00157     ScreenObject():x_pos(0),y_pos(0) {}
00158     ScreenObject(int x, int y):x_pos(x),y_pos(y) {}
00159     virtual void draw()=0;
00160     virtual void update()=0;
00161     double getX() {
00162         return x_pos;
00163     }
00164     double getY() {
00165         return y_pos;
00166     }
00167     void setX(int x){
00168         x_pos=x;
00169         }
00170     void setY(int y){
00171         y_pos=y;
00172         }
00173 };
00174 class SpaceShipEarth: public ScreenObject
00175 {
00176 public:
00177     SpaceShipEarth() {
00178         x_pos=63;
00179         y_pos=63;
00180 
00181     }
00182     void setX(double x) {
00183         x_pos=x;
00184     }
00185     void setY(double y) {
00186         y_pos=y;
00187     }
00188 
00189     void draw() {
00190         uLCD.BLIT(x_pos, y_pos, EARTH_WIDTH, EARTH_HEIGHT,spaceship_earth1);
00191     }
00192     void update() {
00193 
00194         uLCD.BLIT(x_pos, y_pos, EARTH_WIDTH, EARTH_HEIGHT,earth_update);
00195     }
00196 
00197 };
00198 class AbstractAsteroid: public ScreenObject
00199 {
00200 protected:
00201     int deltaX, deltaY;
00202 };
00203 class ConcreteAsteroid1: public AbstractAsteroid
00204 {
00205 public:
00206     ConcreteAsteroid1() {
00207         x_pos=rand() % 126 + 1;
00208         y_pos=rand() % 126 + 1;
00209         deltaX=rand() % 4 + 1;
00210         deltaY=rand() % 4 + 1;
00211         int ranNum=rand() % 4 + 1;
00212         if (ranNum==1) {
00213             x_pos=0*x_pos;
00214             deltaY=deltaY*-1;
00215         } else if(ranNum==2) {
00216             y_pos=0*y_pos;
00217             deltaX=deltaX*-1;
00218         } else if (ranNum==3) {
00219             x_pos=x_pos*0;
00220             y_pos=y_pos*0;
00221         } else {
00222             x_pos=x_pos;
00223             y_pos=y_pos;
00224             deltaX=deltaX*-1;
00225             deltaY=deltaY*-1;
00226         }
00227     }
00228 
00229     void draw() {
00230         uLCD.BLIT(x_pos, y_pos, ASTEROID_WIDTH, ASTEROID_HEIGHT,asteroid_sprite_1);
00231     }
00232     void update() {
00233         uLCD.filled_rectangle(x_pos+ASTEROID_WIDTH,y_pos+ASTEROID_HEIGHT,x_pos,y_pos,BLACK);
00234         x_pos=x_pos+deltaX;
00235         y_pos=y_pos+deltaY;
00236         if(x_pos>125 || y_pos>125 || x_pos<1 || y_pos<1) {
00237             x_pos=rand() % 126 + 1;
00238             y_pos=rand() % 126 + 1;
00239             deltaX=rand() % 4 + 1;
00240             deltaY=rand() % 4 + 1;
00241             int ranNum=rand() % 4 + 1;
00242             if (ranNum==1) {
00243                 x_pos=0*x_pos;
00244                 deltaY=deltaY*-1;
00245             } else if(ranNum==2) {
00246                 y_pos=0*y_pos;
00247                 deltaX=deltaX*-1;
00248             } else if (ranNum==3) {
00249                 x_pos=x_pos*0;
00250                 y_pos=y_pos*0;
00251             } else {
00252                 x_pos=x_pos;
00253                 y_pos=y_pos;
00254                 deltaX=deltaX*-1;
00255                 deltaY=deltaY*-1;
00256             }
00257         }
00258     }
00259 };
00260 class ConcreteAsteroid2: public AbstractAsteroid
00261 {
00262 public:
00263     ConcreteAsteroid2() {
00264         x_pos=rand() % 126 + 1;
00265         y_pos=rand() % 126 + 1;
00266         deltaX=rand() % 4 + 1;
00267         deltaY=rand() % 4 + 1;
00268         int ranNum=rand() % 4 + 1;
00269         if (ranNum==1) {
00270             x_pos=0*x_pos;
00271             deltaY=deltaY*-1;
00272         } else if(ranNum==2) {
00273             y_pos=0*y_pos;
00274             deltaX=deltaX*-1;
00275         } else if (ranNum==3) {
00276             x_pos=x_pos*0;
00277             y_pos=y_pos*0;
00278         } else {
00279             x_pos=x_pos;
00280             y_pos=y_pos;
00281             deltaX=deltaX*-1;
00282             deltaY=deltaY*-1;
00283         }
00284     }
00285 
00286     void draw() {
00287         uLCD.BLIT(x_pos, y_pos, ASTEROID_WIDTH, ASTEROID_HEIGHT,asteroid_sprite_2);
00288     }
00289     void update() {
00290         uLCD.filled_rectangle(x_pos+ASTEROID_WIDTH,y_pos+ASTEROID_HEIGHT,x_pos,y_pos,BLACK);
00291         x_pos=x_pos+deltaX;
00292         y_pos=y_pos+deltaY;
00293         if(x_pos>125 || y_pos>125 || x_pos<0 || y_pos<0) {
00294             x_pos=rand() % 126 + 1;
00295             y_pos=rand() % 126 + 1;
00296             deltaX=rand() % 4 + 1;
00297             deltaY=rand() % 4 + 1;
00298             int ranNum=rand() % 4 + 1;
00299             if (ranNum==1) {
00300                 x_pos=0*x_pos;
00301                 deltaY=deltaY*-1;
00302             } else if(ranNum==2) {
00303                 y_pos=0*y_pos;
00304                 deltaX=deltaX*-1;
00305             } else if (ranNum==3) {
00306                 x_pos=x_pos*0;
00307                 y_pos=y_pos*0;
00308             } else {
00309                 x_pos=x_pos;
00310                 y_pos=y_pos;
00311                 deltaX=deltaX*-1;
00312                 deltaY=deltaY*-1;
00313             }
00314         }
00315         
00316     }
00317 };
00318 
00319 class ConcreteAsteroid3: public AbstractAsteroid
00320 {
00321 public:
00322     ConcreteAsteroid3() {
00323         x_pos=rand() % 126 + 1;
00324         y_pos=rand() % 126 + 1;
00325         deltaX=rand() % 4 + 1;
00326         deltaY=rand() % 4 + 1;
00327         int ranNum=rand() % 4 + 1;
00328         if (ranNum==1) {
00329             x_pos=0*x_pos;
00330             deltaY=deltaY*-1;
00331         } else if(ranNum==2) {
00332             y_pos=0*y_pos;
00333             deltaX=deltaX*-1;
00334         } else if (ranNum==3) {
00335             x_pos=x_pos*0;
00336             y_pos=y_pos*0;
00337         } else {
00338             x_pos=x_pos;
00339             y_pos=y_pos;
00340             deltaX=deltaX*-1;
00341             deltaY=deltaY*-1;
00342         }
00343     }
00344 
00345     void draw() {
00346         uLCD.BLIT(x_pos, y_pos, ASTEROID_WIDTH, ASTEROID_HEIGHT,asteroid_sprite_3);
00347     }
00348     void update() {
00349         uLCD.filled_rectangle(x_pos+ASTEROID_WIDTH,y_pos+ASTEROID_HEIGHT,x_pos,y_pos,BLACK);
00350         x_pos=x_pos+deltaX;
00351         y_pos=y_pos+deltaY;
00352         if(x_pos>125 || y_pos>125 || x_pos<1 || y_pos<1) {
00353             x_pos=rand() % 126 + 1;
00354             y_pos=rand() % 126 + 1;
00355             deltaX=rand() % 4 + 1;
00356             deltaY=rand() % 4 + 1;
00357             int ranNum=rand() % 4 + 1;
00358             if (ranNum==1) {
00359                 x_pos=0*x_pos;
00360                 deltaY=deltaY*-1;
00361             } else if(ranNum==2) {
00362                 y_pos=0*y_pos;
00363                 deltaX=deltaX*-1;
00364             } else if (ranNum==3) {
00365                 x_pos=x_pos*0;
00366                 y_pos=y_pos*0;
00367             } else {
00368                 x_pos=x_pos;
00369                 y_pos=y_pos;
00370                 deltaX=deltaX*-1;
00371                 deltaY=deltaY*-1;
00372             }
00373         }
00374         
00375     }
00376 };
00377 
00378 class ConcreteAsteroid4: public AbstractAsteroid
00379 {
00380 public:
00381     ConcreteAsteroid4() {
00382         x_pos=rand() % 126 + 1;
00383         y_pos=rand() % 126 + 1;
00384         deltaX=rand() % 4 + 1;
00385         deltaY=rand() % 4 + 1;
00386         int ranNum=rand() % 4 + 1;
00387         if (ranNum==1) {
00388             x_pos=0*x_pos;
00389             deltaY=deltaY*-1;
00390         } else if(ranNum==2) {
00391             y_pos=0*y_pos;
00392             deltaX=deltaX*-1;
00393         } else if (ranNum==3) {
00394             x_pos=x_pos*0;
00395             y_pos=y_pos*0;
00396         } else {
00397             x_pos=x_pos;
00398             y_pos=y_pos;
00399             deltaX=deltaX*-1;
00400             deltaY=deltaY*-1;
00401         }
00402     }
00403 
00404     void draw() {
00405         uLCD.BLIT(x_pos, y_pos, ASTEROID_WIDTH, ASTEROID_HEIGHT,asteroid_sprite_4);
00406     }
00407     void update() {
00408         uLCD.filled_rectangle(x_pos+ASTEROID_WIDTH,y_pos+ASTEROID_HEIGHT,x_pos,y_pos,BLACK);
00409         x_pos=x_pos+deltaX;
00410         y_pos=y_pos+deltaY;
00411         if(x_pos>125 || y_pos>125 || x_pos<1 || y_pos<1) {
00412             x_pos=rand() % 126 + 1;
00413             y_pos=rand() % 126 + 1;
00414             deltaX=rand() % 4 + 1;
00415             deltaY=rand() % 4 + 1;
00416             int ranNum=rand() % 4 + 1;
00417             if (ranNum==1) {
00418                 x_pos=0*x_pos;
00419                 deltaY=deltaY*-1;
00420             } else if(ranNum==2) {
00421                 y_pos=0*y_pos;
00422                 deltaX=deltaX*-1;
00423             } else if (ranNum==3) {
00424                 x_pos=x_pos*0;
00425                 y_pos=y_pos*0;
00426             } else {
00427                 x_pos=x_pos;
00428                 y_pos=y_pos;
00429                 deltaX=deltaX*-1;
00430                 deltaY=deltaY*-1;
00431             }
00432         }
00433         
00434     }
00435 };
00436 
00437 bool overlap(ScreenObject & objectA, ScreenObject & objectB)
00438 {
00439     int EarthX=objectA.getX();
00440     int EarthY=objectA.getY();
00441     
00442     int TXSB=EarthX-15;
00443     int TYSB=EarthY-12;
00444     int LXSB=EarthX+10;
00445     int LYSB=EarthY+10;
00446     int AstX=objectB.getX();
00447     int AstY=objectB.getY();
00448     
00449     if ((AstX>TXSB && AstX<LXSB) && (AstY>TYSB && AstY<LYSB)){
00450         return true;
00451         }
00452     else{
00453         return false;
00454         }
00455 }
00456 
00457 
00458 Speaker mySpeaker(p21);
00459 bool BombUsed=false;
00460 bool ExplodeAllAsteroids=false;
00461 //DigitalIn pb1(p16);
00462 
00463 PinDetect pb1(p16);
00464 void pb1_hit_callback (void)
00465         {
00466             if (!BombUsed )
00467             {
00468                 
00469             ExplodeAllAsteroids = true;
00470             BombUsed = true;
00471             
00472             }
00473         }
00474 
00475 
00476 int main()
00477 {
00478     uLCD.baudrate(300000);
00479     wait(0.2);
00480     srand(time(0)); 
00481 
00482     ScreenObject * ActiveAsteroids[NUM_ASTEROIDS];
00483 
00484     SpaceShipEarth ship;
00485     ConcreteAsteroid1 Ast1;
00486     ConcreteAsteroid2 Ast2;
00487     ConcreteAsteroid3 Ast3;
00488     ConcreteAsteroid4 Ast4;
00489     
00490     //ship draw
00491     ActiveAsteroids[0]=&Ast1;
00492     ActiveAsteroids[1]=&Ast2;
00493     ActiveAsteroids[2]=&Ast3;
00494     ActiveAsteroids[3]=&Ast4;
00495 
00496 
00497 
00498     double x=0,y=0,z=0;
00499     double factor=50;
00500 
00501 
00502     MMA8452 acc(p9, p10, 40000);   
00503     acc.setBitDepth(MMA8452::BIT_DEPTH_12);
00504     acc.setDynamicRange(MMA8452::DYNAMIC_RANGE_4G);
00505     acc.setDataRate(MMA8452::RATE_100);
00506     set_time(0);
00507     time_t startTime;
00508     startTime = time(0);
00509     time_t timeElapsed;
00510     timeElapsed= time(0)-startTime; // timeBar;
00511 
00512 
00513 
00514     int x_pos=63;
00515     int y_pos=63;
00516     bool check=true;
00517     
00518     
00519      pb1.mode(PullUp);
00520      pb1.attach_asserted(&pb1_hit_callback);
00521      pb1.setSampleFrequency();
00522    
00523     
00524     for (int i=0; i<NUM_ASTEROIDS; i++) {
00525         ActiveAsteroids[i]->draw();
00526         }
00527     
00528     while (timeElapsed<3 && check) {
00529         timeElapsed= time(0)-startTime;
00530         uLCD.filled_rectangle(0,0,126,3,BLACK);
00531         uLCD.filled_rectangle(0,0,126-(126/29) * timeElapsed,3,BLUE);
00532       
00533         
00534         for (int i=0; i<NUM_ASTEROIDS; i++) {
00535             ActiveAsteroids[i]->update();    
00536         }
00537         ship.update();
00538 
00539 
00540 
00541         if(!acc.isXYZReady()) {
00542             wait(0.01);
00543         } else {
00544             acc.readXYZGravity(&x,&y,&z); //notice this is passed by reference use pointers
00545             ship.setX(-x*factor+x_pos);
00546             ship.setY(-y*factor+y_pos);
00547             ship.draw();
00548         }
00549 
00550         for (int i=0; i<NUM_ASTEROIDS; i++) {
00551             ActiveAsteroids[i]->draw();
00552             if (overlap(ship,*ActiveAsteroids[i])){
00553                 uLCD.BLIT(ship.getX(),ship.getY(),EARTH_WIDTH,EARTH_HEIGHT,spaceship_explode);
00554                 mySpeaker.PlayNote(160.0 + x*200, .4 + 0.2*y, 0.05);
00555                 check=false;
00556                 }
00557         }
00558         
00559         if (ExplodeAllAsteroids){    
00560             for (int i=0; i<NUM_ASTEROIDS; i++) {
00561                 ActiveAsteroids[i]->update();
00562                 ActiveAsteroids[i]->setX(127);  
00563                 ActiveAsteroids[i]->setY(127);
00564             } 
00565             mySpeaker.PlayNote(880, .750, 0.015);
00566             ExplodeAllAsteroids=false;
00567         }
00568         
00569         
00570 
00571     }
00572     if (!check){
00573         uLCD.cls();
00574         mySpeaker.PlayNote(658, .125, 0.015);
00575         mySpeaker.PlayNote(1320, .500, 0.015);
00576         mySpeaker.PlayNote(990, .250, 0.015);
00577         mySpeaker.PlayNote(1056, .250, 0.015);
00578         mySpeaker.PlayNote(1188, .250, 0.015);
00579         mySpeaker.PlayNote(1320, .125, 0.015);
00580         mySpeaker.PlayNote(1188, .125, 0.015);
00581         mySpeaker.PlayNote(1056, .250, 0.015);
00582         mySpeaker.PlayNote(990, .250, 0.015);
00583         mySpeaker.PlayNote(880, .500, 0.015);
00584         mySpeaker.PlayNote(880, .250, 0.015);
00585         mySpeaker.PlayNote(1056, .250, 0.015);
00586         mySpeaker.PlayNote(1320, .500, 0.015);
00587         mySpeaker.PlayNote(1188, .250, 0.015);
00588         mySpeaker.PlayNote(1056, .250, 0.015);
00589         mySpeaker.PlayNote(990, .750, 0.015);
00590         mySpeaker.PlayNote(1056, .250, 0.015);
00591         mySpeaker.PlayNote(1188, .5, 0.015);
00592         mySpeaker.PlayNote(1320, .500, 0.015);
00593         mySpeaker.PlayNote(1056, .500, 0.015);
00594         mySpeaker.PlayNote(880, .500, 0.015);
00595         mySpeaker.PlayNote(880, .750, 0.015);
00596         
00597         uLCD.locate(5,8);
00598         uLCD.printf("Game Over!");
00599         }
00600     else{
00601         uLCD.cls();
00602         uLCD.locate(5,5);
00603         uLCD.printf("Congrat!\n");
00604         uLCD.printf("YOU SAVE THE WORLD");
00605         }
00606 }