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:
Tue Dec 06 15:09:16 2016 +0000
Parent:
13:70e31c1d8205
Parent:
17:dfb8d3c5911a
Child:
19:55f3114f3996
Commit message:
input bullet

Changed in this revision

Bullet.cpp Show annotated file Show diff for this revision Revisions of this file
Person.cpp Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
--- a/Bullet.cpp	Mon Dec 05 12:11:29 2016 +0000
+++ b/Bullet.cpp	Tue Dec 06 15:09:16 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	Mon Dec 05 12:11:29 2016 +0000
+++ b/main.cpp	Tue Dec 06 15:09:16 2016 +0000
@@ -17,12 +17,15 @@
 Mutex update_mtx;
 int jump_flag = 0;
 Person h;
+Serial pc(USBTX, USBRX); // tx, rx
+Bullet* b = NULL;
+
 
 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 +34,46 @@
     }
 }
 
+void bullet_receive(void const *argument){
+    point start;
+    start.x = 127;
+    start.y = 27;
+    char c;
+    while(true){
+        c = pc.getc();
+        if(c == 'a'){
+            b = &Bullet(start, 2);
+            wait(5);
+        }
+        b = NULL;
+    }
+}
+
 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);
     }