test avoid bulled game

Dependencies:   C12832_lcd LCD_fonts mbed mbed-rtos

Revision:
29:7784b098ef1d
Parent:
19:55f3114f3996
Child:
31:17b4ee41bdc5
Child:
32:abb3086c210d
--- a/main.cpp	Mon Dec 12 09:48:23 2016 +0000
+++ b/main.cpp	Mon Dec 12 11:13:59 2016 +0000
@@ -6,21 +6,46 @@
 #include "models.h"
 #include "rtos.h"
 #include "point.h"
+#include "stdlib.h"
 
 C12832_LCD lcd;
 
 // down: p12, left: p13, center: p14, up: p15, right: p16
 InterruptIn button(p14);
+AnalogIn aIn(p20);
 DigitalOut led1(LED1);
 
 Mutex jump_mtx;
 Mutex update_mtx;
 int jump_flag = 0;
 Person h;
+Stage stage;
 Serial pc(USBTX, USBRX); // tx, rx
 Bullet* b = NULL;
 Timer t;
+char picture[(LCD_X / 8 + 1) * LCD_Y];
+int white_board[LCD_Y][LCD_X];
+int* wall_height;
 
+void reset_white_board()
+{
+    for(int i = 0; i < LCD_Y; i++){
+        for (int j = 0; j < LCD_X; j++){
+            white_board[i][j] = 0;
+        }
+    }
+}
+
+void make_wall(){
+    wall_height = stage.getStage();
+    for(int i = 0; i < LCD_Y; i++){
+        for(int j = 0; j < LCD_X ; j++){
+            if(wall_height[i] > (LCD_Y - 1 - j)){
+                white_board[i][j] = white_board[i][j] ^ 1;
+            }
+        }
+    }
+}
 
 void a(){
     h.jump();
@@ -51,18 +76,37 @@
     }
 }
 
+int corrision_judge(point p_person, point p_bullet){
+    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);
+    if((p_person.x + 2 >= p_bullet.x) && (p_person.x + 2 <= p_bullet.x + 5)){
+        printf("aaaaa");
+        if((p_person.y + 2 >= p_bullet.y + 1) && (p_person.y + 2 <= p_bullet.y + 4)){
+            printf("gameover\n");
+        }   
+    }
+    return 0;
+}
+
 int main(){
     point p_person, p_bullet;
     printf("hello\n");
     Thread jump_th(jump_receive);
     Thread bullet_th(bullet_receive);
+    lcd.setmode(XOR);
+    int gameOver = 0;
+    srand((int)(aIn * 100));
     while(true){
         update_mtx.lock();
+        reset_white_board();
+        make_wall();
         p_person = h.update(1);
         if(b != NULL){
             p_bullet = b->update();
         }
-        //printf("x: %d,  y: %d", p_bullet.x,p_bullet.y);
+        //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);
+        corrision_judge(p_person, p_bullet);
         update_mtx.unlock();
         lcd.cls();
         lcd.print_bm(bitmPlayer,p_person.x,p_person.y);