ELEC2645 (2018/19) / Mbed 2 deprecated el17m2h_public

Dependencies:   mbed

main.cpp

Committer:
el17m2h
Date:
2019-04-13
Revision:
5:8814d6de77d0
Parent:
4:8ec314f806ae
Child:
15:4efa04a6a376

File content as of revision 5:8814d6de77d0:

/*
ELEC2645 Embedded Systems Project
School of Electronic & Electrical Engineering
University of Leeds
Name: Melissa Hartmann
Username: el17m2h
Student ID Number: 201176603
Date: 11/04/2019
*/


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

#define FLOORS_WIDTH 13
#define FLOORS_HEIGHT 2
#define DOODLER_RADIUS 2

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


// objects
N5110 lcd(PTC5,PTC9,PTC0,PTC7,PTD2,PTD1,PTC11); // START, LCD SCE, LCD RST, LCD DC, LCD MOSI, LCD CLK, LCD Backlight
Gamepad pad;
Engine eng;

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

// functions
int main(){
    int fps = 8;
    init();     // initialise and then display welcome screen...
    welcome();
    render();
    wait(1.0f/fps);
    while(1){   
      eng.read_input(pad);
      eng.update(pad);
      render();
      wait(1.0f/fps);
    }
}


// initialies all classes and libraries
void init(){
    // need to initialise LCD and Gamepad 
    lcd.init();
    pad.init();
    eng.init(FLOORS_WIDTH, FLOORS_HEIGHT, DOODLER_RADIUS);
}

void render(){
    lcd.clear();
    eng.draw(lcd);
    lcd.refresh();
}

// Starting menu screen display
void welcome() {   
    lcd.printString(" Doodle Jump! ",0,1);  
    lcd.printString("  Press Start ",0,4);
    lcd.refresh();
    
    while ( pad.check_event(Gamepad::START_PRESSED) == false) {
        pad.leds_on();
        wait(0.1);
        pad.leds_off();
        wait(0.1);
    }
 }