Zeyu Feng 201377605

Dependencies:   mbed

On Minerva

Revision:
9:62d6559f0d50
Parent:
8:8287d2ef965d
Child:
10:02ab3324be6c
--- a/main.cpp	Wed Apr 29 15:20:34 2020 +0000
+++ b/main.cpp	Sat May 09 08:27:07 2020 +0000
@@ -28,18 +28,26 @@
 Collision collision;
 
 //flag and triggers
-Ticker ticker;
+Ticker ticker;//gradually increase number of shots
+Timeout timeout;
 volatile int timer_flag = 0;
+volatile int timeout_flag = 0;
+volatile int count_flag = 30;
 
 //    functions
 void flip()
 {
     timer_flag = 1;
 }
+void time_out()
+{
+    timeout_flag = 1;
+}
 void init();
 void control_check();
+void draw();
 void shot_update();
-
+void count_down();
 
 int main()
 {
@@ -47,13 +55,14 @@
     init();
     //set a ticker
     ticker.attach(&flip,2);
+    timeout.attach(&time_out,5);
 
     //a infinite loop to control position of the people, update the game state
     while(1) {
         if(timer_flag == 1) {
             timer_flag = 0;
             if(shot.get_size() < 30){
-                int size = shot.get_size()+ 2;
+                int size = shot.get_size()+ 4;
                 shot.set_size(size);
             }
         }
@@ -62,12 +71,17 @@
         shot_update();
         
         //   control people and check collision
-        control_check();
-
+        if(timeout_flag){
+            control_check();
+        } 
+        draw();
+        if(!timeout_flag){
+            count_down();
+        }
         lcd.refresh();
         //printf("shot refresh\n");
         //printf("size = %d\n",shot._size);
-        wait_ms(200);//fps = 5
+        wait_ms(1000/6);//fps = 6
     }
 }
 
@@ -93,8 +107,12 @@
         lcd.clear();
         shot.init();
     }
+}
+
+void draw()
+{
+    engine.draw(lcd);
     collision.draw(lcd);
-    engine.draw(lcd);
 }
 
 void shot_update()
@@ -104,3 +122,12 @@
     shot.gen_shot();
     shot.draw(lcd);
 }
+
+void count_down()
+{   
+    char buffer[6];
+    sprintf(buffer,"%d",(int)count_flag/6);
+    lcd.printString(buffer,40,2);
+    printf("count: %d\n",count_flag);
+    count_flag--;
+}
\ No newline at end of file