test avoid bulled game

Dependencies:   C12832_lcd LCD_fonts mbed mbed-rtos

Files at this revision

API Documentation at this revision

Comitter:
kaku_jyoko
Date:
Wed Dec 14 03:02:14 2016 +0000
Parent:
54:64c0bdcc94ae
Child:
56:2ab95bb6fbcc
Commit message:
add bullet option

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
--- a/main.cpp	Wed Dec 14 02:17:49 2016 +0000
+++ b/main.cpp	Wed Dec 14 03:02:14 2016 +0000
@@ -27,6 +27,7 @@
 int white_board[LCD_Y][LCD_X];
 int* wall_height;
 
+
 void reset_white_board()
 {
     for(int i = 0; i < LCD_Y; i++){
@@ -47,30 +48,76 @@
     }
 }
 
-void a(){
+void call_jump(){
     h.jump();
 }
 
 void jump_receive(void const *argument){
     while(true){
         jump_mtx.lock();
-        button.rise(&a);
+        button.rise(&call_jump);
         jump_mtx.unlock();
         //Thread::wait(0.1);
     }
 }
 
 void bullet_receive(void const *argument){
+    //bullet option
+    int fast = 4;
+    int normal = 3;
+    int slow = 2;
+    int high = 17;
+    int middle = 12;
+    int low = 7;
+
     point start;
     start.x = 127;
-    start.y = 27;
     char c;
     while(true){
         t.start();
         c = pc.getc();
-        if(c == 'a' && t.read() > 5.0){
+        if(c >= '1' && c <= '9' && t.read() > 5.0){
             b = NULL;
-            b = &Bullet(start, 2);
+            switch(c){
+                case '1':
+                    start.y = LCD_Y - high;
+                    b = &Bullet(start, slow);
+                    break;
+                case '2':
+                    start.y = LCD_Y - high;
+                    b = &Bullet(start, normal);
+                    break;
+                case '3':
+                    start.y = LCD_Y - high;
+                    b = &Bullet(start, fast);
+                    break;
+                case '4':
+                    start.y = LCD_Y - middle;
+                    b = &Bullet(start, slow);
+                    break;
+                case '5':
+                    start.y = LCD_Y - middle;
+                    b = &Bullet(start, normal);
+                    break;
+                case '6':
+                    start.y = LCD_Y - middle;
+                    b = &Bullet(start, fast);
+                    break;
+                case '7':
+                    start.y = LCD_Y - low;
+                    b = &Bullet(start, slow);
+                    break;
+                case '8':
+                    start.y = LCD_Y - low;
+                    b = &Bullet(start, normal);
+                    break;
+                case '9':
+                    start.y = LCD_Y - low;
+                    b = &Bullet(start, fast);
+                    break;
+                default:
+                    break;
+            }
             t.reset();
         }
     }
@@ -83,6 +130,7 @@
   else if(y>x){
     return(y-x);
   }
+    return 0;
 }
 
 bool bullet_collision(point p_person, point p_bullet){
@@ -114,7 +162,6 @@
 
 int main(){
     point p_person, p_bullet;
-    printf("hello\n");
     Thread jump_th(jump_receive);
     Thread bullet_th(bullet_receive);
     lcd.setmode(XOR);
@@ -123,6 +170,11 @@
     srand((int)(aIn * 100));
     Converter converter;
     Bitmap picture;
+    printf("Bullet Option\n");
+    printf("       slow    normal  fast\n");
+    printf("high     1       2       3\n");
+    printf("middle   4       5       6\n");
+    printf("low      7       8       9\n");
     
     while(true){
         if(!gameover){
@@ -130,15 +182,14 @@
             reset_white_board();
             make_wall();
             p_person = h.update(wall_height[3]);
-           // p_person = h.update(1);
+            //p_person = h.update(1);
             if(b != NULL){
                 p_bullet = b->update();
             }
-            //printf("bullet  x: %d,  y: %d \n", p_bullet.x,p_bullet.y);
-            //printf("person  x: %d,  y: %d \n", p_person.x,p_person.y);
-            gameover = bullet_collision(p_person, p_bullet);
-            gameover = wall_collision(p_person);
             picture = converter.convert(white_board);
+            
+            gameover |= bullet_collision(p_person, p_bullet);
+            gameover |= wall_collision(p_person);
             update_mtx.unlock();
             
             lcd.cls();