Owen Cavender 201159294

Dependencies:   mbed Gamepad2

main.cpp

Committer:
el17oc
Date:
2020-05-29
Revision:
12:60c856354406
Parent:
10:ee781d18e0f6
Child:
14:7fb3c93343b6

File content as of revision 12:60c856354406:

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

Name: Owen Cavender
Username: el17oc
Student ID Number: 201159294
Date: 20/04/2020

The game loop will be entered after the game is initialised. The first step is to process the
user input (if any). The next step is to update the game apple depending on the input i.e.
moving a character or checking for collisions. The final step is to update the display and render
this on the LCD. There is usual////
*/

// includes
#include "mbed.h"
#include "Gamepad.h"
#include "N5110.h"
#include "snake.h"
#include "GameEngine.h"




//objects
Gamepad pad;
Snake snake;
N5110 lcd;
Ticker ticker;
GameEngine engine;
//functions

void welcome();
void render();
void init();
void update_game_state();
void gameover_true();
void ticker_isr();

int countdown;



//Serial pc(USBTX, USBRX);

int main()
{

    int fps = 6;
    init();   // frames per second
    welcome();
    // initialise and then display welcome screen...

    // and wait for one frame period
    render();
    //ROB atm the code works to here
    //need to draw an initial snake

    while (1) {


        update_game_state();
        snake.check_gameover(lcd);
        snake.gameover_true(lcd);
        snake.apple_collected(lcd, pad);
        snake.get_Apple_position(lcd);

        engine.get_LEDs(pad, snake);

        snake.render(lcd);
        engine.print_countdown(lcd, snake);
        //  snake.print_display_time(lcd);


        wait(1.0f/6);
    }

}

//apples  //timer check

void init()
{
    snake.init();           //need to initialise snake class
    pad.init();
    lcd.init();
}

void update_game_state()
{
    snake.get_direction(pad);
    snake.render_clear_tail(lcd);
    // =needs to be cleared before _x3, _y3 is updated
    snake.move_snake();
    engine.get_LEDs(pad, snake);
}

void welcome()
{
    lcd.printString("     SNAKE    ",0,1);
    // lcd.printString("  Press Start ",0,4);

    while ( pad.start_pressed() == false) {
        lcd.setContrast( pad.read_pot1());
        pad.leds_on();
        wait(0.1);
        pad.leds_off();
        wait(0.1);
    }
    lcd.refresh();
}


void render()
{
    lcd.clear();
    lcd.drawRect(0, 0, 84, 42, FILL_TRANSPARENT);
    lcd.printString("     GO!      ", 0,25);
    wait(1.0);

}




//MAKE TIMER IN ONE CLASS SNAKE
//SPAWN APPLE
//MOVE THE SNAKE --- 
//



//has an apple been collected? if so increase length by 1 increase score by 1 and makes coin collecting noise and spawn new apple
//has snake touched itself or wall - if so end game - present score - make xxx sound fail --- apple needs to be different to the snakes body and different to wall
//has button button been pressed - if so change direction accordingly
//max length - when length = width x height - 1 - game complete
//each pixel of length must follow the front pixel
// 2 modes - time race - "get an apple before time runs out" - resets timer --- then classic snake



//need to add audio, leds, (main menu end menu and entering and leaving the while(1) loop), time trial mode, .h files