ELEC2645 (2018/19) / Mbed 2 deprecated el18jz_

Dependencies:   mbed

main.cpp

Committer:
jiaxinZHOU
Date:
2019-05-08
Revision:
1:538386e72e40
Parent:
0:07c4fef6c0af
Child:
4:0f2006e9c8f8

File content as of revision 1:538386e72e40:

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

Name: Jiaxin Zhou   
Username: Jiaxin Zhou     
Student ID Number: 201282650
Date:16/04/2019

*/

#include "mbed.h"
#include "Gamepad.h"
#include "N5110.h"
#include "Move.h"
#include "Menu.h"
/** @file main.cpp
 *  @brief This file is used to callback all functions.
 */

N5110 lcd(PTC9,PTC0,PTC7,PTD2,PTD1,PTC11);
Gamepad pad;
Move move;
Menu menu;

void initial();
void welcome();
void render();
void menus(N5110 &lcd);
int input(int sel,Gamepad &pad);

///////////// MAIN.CPP ////////////////
int main () {
    int fps = 1;
    initial();
    welcome();
    menu.menus(lcd,pad);
    fps = menu.difficulty(lcd,pad);
    render();
    move.getfood();
    while(1) {
    //process_input();
    //update_game_state();
    //refresh_display();
    //wait_ms(1000/fps);
    move.eatfood();
    move.update(pad);
    move.updatebody();
    
    render();
    move.die(lcd,pad);
    wait(1.0f/fps);
    }
    
    
}

void initial() {
    lcd.init();
    pad.init();
    move.initial();
}

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

void welcome() {
    lcd.printString("    snake!    ",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);
    }
        
}