ELEC2645 (2017/18) / Mbed OS el16ajm

main.cpp

Committer:
Andrew_M
Date:
2018-05-06
Revision:
8:9d01fd4a63ad
Parent:
3:6253a2d374fa
Child:
9:fe86ddbf7799

File content as of revision 8:9d01fd4a63ad:

/*
ELEC2645 Embedded Systems Project
School of Electronic & Electrical Engineering
University of Leeds
Name: Andrew Moore
Username: el16ajm
Student ID Number: 201042893
Date:
*/

#include "mbed.h"
#include "Gamepad.h"
#include "N5110.h"
#include "Engine.h"

/////////////// structs /////////////////
struct UserInput {
    Direction d;
};

/////////////// objects ///////////////
N5110 lcd(PTC9,PTC0,PTC7,PTD2,PTD1,PTC11);
Gamepad pad;
Engine gameEngine;

///////////// prototypes ///////////////
void init();
void update_game(UserInput input);
void render();
void welcome();
void menu();

///////////// functions ////////////////
int main()
{
    int fps = 8;  // frames per second

    init();
    welcome();

    wait(1.0f/fps);  // and wait for one frame period


    // game loop - read input, update the game state and render the display
    while (1) {
        gameEngine.read_input(pad);
        gameEngine.update(pad);
        render();
        wait(1.0f/fps);
    }
}

void welcome()
{
    lcd.printString("     Snake!    ",0,1);
    lcd.printString("  Press Start ",0,4);
    lcd.refresh();

    // wait flashing LEDs until start button is pressed
    while ( pad.check_event(Gamepad::START_PRESSED) == false) {
        pad.leds_on();
        wait(0.1);
        pad.leds_off();
        wait(0.1);
    }
    
    menu();
}

void init()
{
    // need to initialise LCD and Gamepad
    gameEngine.init();
    lcd.init();
    pad.init();

}

void render()
{
    // clear screen, re-draw and refresh
    lcd.clear();
    gameEngine.draw(lcd);
    lcd.refresh();
}