Ikenna Adrian Ozoemena 201157039

Dependencies:   mbed

main.cpp

Committer:
ikenna1
Date:
2019-04-13
Revision:
18:2cc6898de6b2
Parent:
14:88ca5b1a111a
Child:
21:628fb703188f

File content as of revision 18:2cc6898de6b2:

/*
ELEC2645 Embedded Systems Project
School of Electronic & Electrical Engineering
University of Leeds
Name: Ikenna Adrian Ozoemena
Username: el17aio
Student ID Number: 201157039
Date: 20/02/2019
*/

//______________pre-processor directives________________________________________
#include "mbed.h"
#include "N5110.h"
#include "RosenEngine.h"
#include "Menu.h"

//_______________objects________________________________________________________
N5110 lcd(PTC9,PTC0,PTC7,PTD2,PTD1,PTC11);
Gamepad pad;
RosenEngine rosen;
Menu menu;

//_______________prototypes_____________________________________________________
void init();
void welcome();
void render();
void ship_select();

//_______________functions______________________________________________________
int main()
{
    int fps = 12;
    init();
    printf("Init function completed...\n");

    while(1) {
        welcome();
        //printf("ycursor = %d",rosen.get_ycursor());
        // make it so it works with get_cursor = 16;

        if(rosen.get_ycursor() == 16) {
            while ( pad.check_event(Gamepad::BACK_PRESSED) == false) {
                // printf("play...\n");
                rosen.read_input(pad);
                rosen.update(pad);
                render();
                wait(1.0f/fps);
            }
        }
        if(rosen.get_ycursor() == 24) {
            while ( pad.check_event(Gamepad::BACK_PRESSED) == false) {
                rosen.read_input(pad);
                rosen.update(pad);
                ship_select();
                wait(1.0f/fps);
                printf("ship = %d\n",rosen.get_xcursor());
                // printf("menu...\n");
            }
        }
    }
}

void init()
{
    // need to initialise LCD and Gamepad
    lcd.init();
    pad.init();
    rosen.init(9,6,3,42,41);

}
void render()
{
    // clear screen, re-draw and refresh
    lcd.clear();
    rosen.draw(lcd, pad);
    rosen.get_pos();
    lcd.refresh();
}
void ship_select()
{
    lcd.clear();
    rosen.ship_select(lcd);
    rosen.get_pos();
    lcd.refresh();
}

// simple splash screen displayed on start-up
void welcome()
{
    while( pad.check_event(Gamepad::START_PRESSED) == false) {
        rosen.title(lcd);
        rosen.read_input(pad);
        rosen.update(pad);
        lcd.refresh();
    }
    printf("Welcome Function completed...\n");
}