test avoid bulled game
Dependencies: C12832_lcd LCD_fonts mbed mbed-rtos
main.cpp
- Committer:
- kaku_jyoko
- Date:
- 2016-12-06
- Revision:
- 18:0f6f2aa2339d
- Parent:
- 17:dfb8d3c5911a
- Child:
- 19:55f3114f3996
File content as of revision 18:0f6f2aa2339d:
#include "mbed.h" #include "C12832_lcd.h" #include "Arial_9.h" #include "Small_7.h" #include "graphics.h" #include "models.h" #include "rtos.h" #include "point.h" C12832_LCD lcd; // down: p12, left: p13, center: p14, up: p15, right: p16 InterruptIn button(p14); DigitalOut led1(LED1); Mutex jump_mtx; Mutex update_mtx; int jump_flag = 0; Person h; Serial pc(USBTX, USBRX); // tx, rx Bullet* b = NULL; void a(){ h.jump(); } void jump_receive(void const *argument){ while(true){ jump_mtx.lock(); button.rise(&a); jump_mtx.unlock(); //Thread::wait(0.1); } } 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_person, p_bullet; printf("hello\n"); Thread jump_th(jump_receive); Thread bullet_th(bullet_receive); while(true){ update_mtx.lock(); 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_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_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); } }