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:
Sat Dec 10 13:13:00 2016 +0000
Parent:
16:1104089ff3cb
Parent:
19:55f3114f3996
Child:
21:1911f2c4684b
Child:
28:efe19c092c2c
Commit message:
fixed button

Changed in this revision

--- a/Bullet.cpp	Fri Dec 09 13:46:34 2016 +0000
+++ b/Bullet.cpp	Sat Dec 10 13:13:00 2016 +0000
@@ -7,6 +7,6 @@
 }
 
 point Bullet::update(){
-    p.x += v;
+    p.x -= v;
     return p;    
 }
\ No newline at end of file
--- a/main.cpp	Fri Dec 09 13:46:34 2016 +0000
+++ b/main.cpp	Sat Dec 10 13:13:00 2016 +0000
@@ -17,12 +17,16 @@
 Mutex update_mtx;
 int jump_flag = 0;
 Person h;
+Serial pc(USBTX, USBRX); // tx, rx
+Bullet* b = NULL;
+Timer t;
+
 
 void a(){
     h.jump();
 }
 
-void receive(void const *argument){
+void jump_receive(void const *argument){
     while(true){
         jump_mtx.lock();
         button.rise(&a);
@@ -31,23 +35,47 @@
     }
 }
 
+void bullet_receive(void const *argument){
+    point start;
+    start.x = 127;
+    start.y = 27;
+    char c;
+    while(true){
+        t.start();
+        c = pc.getc();
+        if(c == 'a' && t.read() > 5.0){
+            b = NULL;
+            b = &Bullet(start, 2);
+            t.reset();
+        }
+    }
+}
+
 int main(){
-    point p;
+    point p_person, p_bullet;
     printf("hello\n");
-    Thread receive_th(receive);
+    Thread jump_th(jump_receive);
+    Thread bullet_th(bullet_receive);
     while(true){
         update_mtx.lock();
-        p = h.update();
-        if(p.y == 0){
+        p_person = h.update(1);
+        if(b != NULL){
+            p_bullet = b->update();
         }
+        //printf("x: %d,  y: %d", p_bullet.x,p_bullet.y);
         update_mtx.unlock();
         lcd.cls();
-        lcd.print_bm(bitmPlayer,p.x,p.y);
-        lcd.print_bm(bitmBullet_graphics, 40, 10);
+        lcd.print_bm(bitmPlayer,p_person.x,p_person.y);
+        if(b != NULL){
+            lcd.print_bm(bitmBullet_graphics, p_bullet.x, p_bullet.y);
+        }
         lcd.copy_to_lcd();
         wait(0.02);
         lcd.cls();
-        lcd.print_bm(bitmPlayerB,p.x,p.y);
+        lcd.print_bm(bitmPlayerB,p_person.x,p_person.y);
+        if(b != NULL){
+            lcd.print_bm(bitmBullet_graphics, p_bullet.x, p_bullet.y);
+        }
         lcd.copy_to_lcd();
         wait(0.02);
     }