Final Submission. I have read and agreed with Statement of Academic Integrity.

Dependencies:   mbed Gamepad N5110 Joystick

main.cpp

Committer:
el16dlc
Date:
2019-05-09
Revision:
3:660de4311976
Parent:
2:0bd6711eae26
Child:
4:0fc3441556e1

File content as of revision 3:660de4311976:

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

Name: DANIEL CROCKFORD
Username: el16dlc
Student ID Number: 201039580
Date: 07/05/2019
*/


#include "main.h"
#include "Snake.h"
#include "Game_engine.h"

// Gamepad Peripherals
N5110 lcd(PTC9,PTC0,PTC7,PTD2,PTD1,PTC11);

Gamepad gamepad;

// Instances
GameEngine engine;


int main() {
    srand(time(NULL));
    Init(); 
    Welcome();
    engine.init();
    

    
    while(1) {
        render();
        engine.get_dir(gamepad);
        engine.snake_move();
        engine.food_move();
    }
}


// Initialise gamepad
void Init() {
    lcd.init();
    gamepad.init();
    lcd.setContrast(0.5);
    lcd.setBrightness(0.5);
    gamepad.leds_off();
    gamepad.check_event(Gamepad::A_PRESSED);
    gamepad.check_event(Gamepad::B_PRESSED);
    gamepad.check_event(Gamepad::X_PRESSED);
    gamepad.check_event(Gamepad::Y_PRESSED);
    gamepad.check_event(Gamepad::L_PRESSED);
    gamepad.check_event(Gamepad::R_PRESSED);
    gamepad.check_event(Gamepad::BACK_PRESSED);
    gamepad.check_event(Gamepad::START_PRESSED);  
}

// Prototype welcome screen
void Welcome() {
    lcd.clear();
    lcd.printString("Welcome",2,1);
    lcd.refresh();
    wait(2.0);
}

// Draws each frame on screen
void render() {
    lcd.clear();
    engine.draw(lcd);
    lcd.refresh();
    wait(0.2);
}