
Zeyu Feng 201377605
Dependencies: mbed
On Minerva
main.cpp
- Committer:
- el19zf
- Date:
- 2020-05-09
- Revision:
- 9:62d6559f0d50
- Parent:
- 8:8287d2ef965d
- Child:
- 10:02ab3324be6c
File content as of revision 9:62d6559f0d50:
/* ELEC2645 Embedded Systems Project School of Electronic & Electrical Engineering University of Leeds 2019/20 Name:Zeyu Feng Username:el19zf Student ID Number:201377605 Date:11/3/2020 */ // includes #include "mbed.h" #include "Gamepad.h" #include "N5110.h" #include "People.h" #include "PeopleEngine.h" #include "shot.h" #include "Collision.h" // objects Gamepad pad; N5110 lcd; PeopleEngine engine; shot shot; Collision collision; //flag and triggers Ticker ticker;//gradually increase number of shots Timeout timeout; volatile int timer_flag = 0; volatile int timeout_flag = 0; volatile int count_flag = 30; // functions void flip() { timer_flag = 1; } void time_out() { timeout_flag = 1; } void init(); void control_check(); void draw(); void shot_update(); void count_down(); int main() { //initial init(); //set a ticker ticker.attach(&flip,2); timeout.attach(&time_out,5); //a infinite loop to control position of the people, update the game state while(1) { if(timer_flag == 1) { timer_flag = 0; if(shot.get_size() < 30){ int size = shot.get_size()+ 4; shot.set_size(size); } } lcd.clear(); // shot update shot_update(); // control people and check collision if(timeout_flag){ control_check(); } draw(); if(!timeout_flag){ count_down(); } lcd.refresh(); //printf("shot refresh\n"); //printf("size = %d\n",shot._size); wait_ms(1000/6);//fps = 6 } } void init() { lcd.init(); lcd.setContrast(0.5); engine.init(); pad.init(); shot.init(); collision.init(); lcd.refresh(); } 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(); } } void draw() { engine.draw(lcd); collision.draw(lcd); } void shot_update() { shot.update(); shot.delete_shot(); shot.gen_shot(); shot.draw(lcd); } void count_down() { char buffer[6]; sprintf(buffer,"%d",(int)count_flag/6); lcd.printString(buffer,40,2); printf("count: %d\n",count_flag); count_flag--; }