
Zeyu Feng 201377605
Dependencies: mbed
On Minerva
Diff: main.cpp
- Revision:
- 8:8287d2ef965d
- Parent:
- 7:c49f3d3b672f
- Child:
- 9:62d6559f0d50
--- a/main.cpp Wed Apr 29 05:10:57 2020 +0000 +++ b/main.cpp Wed Apr 29 15:20:34 2020 +0000 @@ -17,6 +17,7 @@ #include "People.h" #include "PeopleEngine.h" #include "shot.h" +#include "Collision.h" // objects @@ -24,6 +25,7 @@ N5110 lcd; PeopleEngine engine; shot shot; +Collision collision; //flag and triggers Ticker ticker; @@ -35,7 +37,7 @@ timer_flag = 1; } void init(); -void control_people(); +void control_check(); void shot_update(); @@ -43,27 +45,30 @@ { //initial init(); - - ticker.attach(&flip,5); + //set a ticker + ticker.attach(&flip,2); //a infinite loop to control position of the people, update the game state while(1) { if(timer_flag == 1) { timer_flag = 0; - if(shot._size < 30) - shot._size = shot._size + 2; + if(shot.get_size() < 30){ + int size = shot.get_size()+ 2; + shot.set_size(size); + } } lcd.clear(); - // people - control_people(); + // shot update shot_update(); + + // control people and check collision + control_check(); + lcd.refresh(); //printf("shot refresh\n"); //printf("size = %d\n",shot._size); wait_ms(200);//fps = 5 - } - } @@ -74,15 +79,24 @@ engine.init(); pad.init(); shot.init(); + collision.init(); lcd.refresh(); } -void control_people() +void control_check() { engine.read_input(pad); engine.update(); + collision.set_pos(engine.get_pos()); + if(collision.check(lcd)) { + engine.init(); + lcd.clear(); + shot.init(); + } + collision.draw(lcd); engine.draw(lcd); } + void shot_update() { shot.update();