Zeyu Feng 201377605

Dependencies:   mbed

On Minerva

main.cpp

Committer:
el19zf
Date:
2020-04-28
Revision:
6:dce38fe4e092
Parent:
5:6774b7272e85
Child:
7:c49f3d3b672f

File content as of revision 6:dce38fe4e092:

/* 
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"


// objects
Gamepad pad;
N5110 lcd;
PeopleEngine engine;
shot shot;

//flag and triggers
Ticker ticker;
volatile int timer_flag = 0;

//    functions
void flip() { 
    timer_flag = 1;
}
void init();
void control_people();
void  shot_update();


int main()
{
    //initial
    init();
    
    ticker.attach(&flip,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._size < 30)
                shot._size = shot._size + 2;
        }
        lcd.clear();
        //   people
        control_people();
        shot_update();
        lcd.refresh();
        //printf("shot refresh\n");
        //printf("size = %d\n",shot._size);
        wait_ms(100);//fps = 10

    }
        
}


void init()
{
    lcd.init();
    lcd.setContrast(0.5);
    engine.init();
    pad.init();
    lcd.refresh();
    shot.init();
}

void control_people()
{
    engine.read_input(pad);
    engine.update();
    engine.draw(lcd);
}
void shot_update()
{
        shot.update();
        shot.delete_shot();
        shot.gen_shot();
        shot.draw(lcd);
}