Joshua O'hara 201291390

Dependencies:   mbed

main.cpp

Committer:
josh_ohara
Date:
2020-03-27
Revision:
9:8e695df3cc36
Parent:
8:86cb9a9f8a73
Child:
10:9189419fda68

File content as of revision 9:8e695df3cc36:

/* 
ELEC2645 Embedded Systems Project
School of Electronic & Electrical Engineering
University of Leeds
2019/20

Name: Joshua O'hara
Username: el18jkeo
Student ID Number: 201291390
Date: 11.03.2020
*/

// includes
#include "mbed.h"
#include "Gamepad.h"
#include "N5110.h"
#include "SpaceInvaderEngine.h"

#define SHIP_WIDTH 8
#define SHIP_HEIGHT 2
#define SHIP_SIZE 4

// objects
Gamepad pad;
N5110 lcd;
SpaceInvaderEngine SpaceInvader;

// structs
struct UserInput {
    Direction d;
    float mag;
};
    
//functions
void init();
void draw_game();
void start_menu();
void update_game(UserInput input);

int main()
{
    int fps = 6;
    
    init();
    start_menu();
    
    draw_game();
    wait(1.0f/fps);
    
    while(1) {
        SpaceInvader.read_input(pad);
        SpaceInvader.update(pad);
        draw_game();
        wait(1.0f/fps);
    }
}

void start_menu() {
    lcd.printString("Space Invaders",0,1);  
    lcd.printString("  Press Start ",0,4);
    lcd.refresh();
    
    while ( pad.start_pressed() == false) {
        lcd.setContrast( pad.read_pot1());
        pad.leds_on();
        wait(0.1);
        pad.leds_off();
        wait(0.1);
    }
 
}

void draw_game()
{
    lcd.clear();  
    SpaceInvader.render(lcd);
    lcd.refresh();
}

void init()
{ 
    lcd.init();
    pad.init();
    SpaceInvader.init(SHIP_HEIGHT,SHIP_WIDTH,SHIP_SIZE);
    
//    lcd.printString("MainInit",0,1);
//    lcd.refresh();
//    wait(5);
}