Stephen Ralph / Mbed 2 deprecated Asteroids

Dependencies:   mbed 4DGL-uLCD-SE PinDetect

Files at this revision

API Documentation at this revision

Comitter:
sralph3
Date:
Fri Nov 30 05:57:32 2018 +0000
Parent:
2:fe6ab9956767
Child:
4:4a7cbab8c390
Commit message:
4

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
--- a/main.cpp	Fri Nov 30 05:52:13 2018 +0000
+++ b/main.cpp	Fri Nov 30 05:57:32 2018 +0000
@@ -1,6 +1,7 @@
 #include "uLCD_4DGL.h"
 #include "MMA8452.h"
 #include "Speaker.h"
+#include "PinDetect.h"
 
 
 #include "SSE.h"
@@ -43,6 +44,19 @@
 Serial pc(USBTX,USBRX);
 MMA8452 acc(p9, p10, 40000);  //instantiate an acc object!
 Speaker mySpeaker(p21);
+PinDetect pb1(p18);
+
+bool BombUsed = false;
+bool ExplodeAllAsteroids = false;
+
+void pb1_hit_callback (void)
+{
+    if (!BombUsed ){
+        ExplodeAllAsteroids = true;
+        BombUsed = true;
+        mySpeaker.PlayNote(100.0,0.25,0.1);
+    }
+}
 
 int asteroid_sprite_1[ASTEROID_HEIGHT * ASTEROID_WIDTH] = {
     _,_,_,_,X,X,X,X,X,X,X,X,_,_,_,
@@ -134,6 +148,7 @@
     wait(0.2);    
     srand(time(0)); // do this srandcall here ONLY... no where else in the code!
     ScreenObject *AstAry[NUM_ASTEROIDS];
+    pb1.mode(PullUp);
     
     AstAry[0] = new ConcreteAsteroid1;
     AstAry[1] = new ConcreteAsteroid2;
@@ -166,6 +181,23 @@
             return 0;
         }
         
+        if (ExplodeAllAsteroids){
+            for(int i=0; i < NUM_ASTEROIDS; i++){
+                int rando = (rand() % 4);
+                
+                if (rando == 0) {
+                    AstAry[i] = new ConcreteAsteroid1;   
+                } else if (rando == 1) {
+                    AstAry[i] = new ConcreteAsteroid2;   
+                } else if (rando == 2) {
+                    AstAry[i] = new ConcreteAsteroid3;   
+                } else {
+                    AstAry[i] = new ConcreteAsteroid4;   
+                }
+            }
+            ExplodeAllAsteroids = false;
+        }
+        
         ship.update();
         
         for(int i=0; i < NUM_ASTEROIDS; i++){