![](/media/cache/group/default_image.jpg.50x50_q85.jpg)
Owen Cavender 201159294
Diff: main.cpp
- Revision:
- 16:9500059ad5d8
- Parent:
- 14:7fb3c93343b6
--- a/main.cpp Sat May 30 03:06:22 2020 +0000 +++ b/main.cpp Sat May 30 05:43:50 2020 +0000 @@ -4,28 +4,22 @@ University of Leeds 2019/20 +/////////////SNAKE /////////// 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 - -this on the LCD. There is usual//// */ -// includes -#include "mbed.h" +////////////////////////////// + +//includes +#include "mbed.h" //addresses each header file of external classes being used in the programme #include "Gamepad.h" #include "N5110.h" #include "snake.h" #include "GameEngine.h" -//write spec for game - - //objects Gamepad pad; @@ -45,26 +39,23 @@ int main() { - //int fps = 6; - init(); // frames per second - welcome(); + init(); //initialises game objects + welcome(); //displays welcome screen before entering game loop - // initialise and then display welcome screen... + while (1) { - update_snake(); - snake.check_gameover(lcd); - snake.gameover_true(lcd, pad); - + update_snake(); //reads input from gamepad and updates the position of the snake - this is the function influences how the other functions behave + snake.check_gameover(lcd); //checking if any one of the three game over conditions is true + // snake.gameover_true(lcd, pad); //checking if an apple has been collected - increases the score and generates new apple position if apple has been collected snake.apple_collected(lcd, pad); snake.get_Apple_position(lcd); - + engine.get_LEDs(pad, snake); - engine.get_LEDs(pad, snake); - engine.print_countdown(lcd, snake); - snake.render(lcd); + engine.print_countdown(lcd, snake); //prints the value of the countdown counter - it will have incremented by 25 if an apple has been collected and would have decreased by 1 if not + snake.render(lcd, pad); //prints the snake, the apple, the score and the border // snake.print_display_time(lcd); @@ -73,13 +64,11 @@ } -//apples //timer check - void init() { - lcd.init(); - pad.init(); - snake.init(); //need to initialise snake class + lcd.init(); //initialises the lcd + pad.init(); //initialises the gamepad + snake.init(); //initialises snake class } @@ -97,11 +86,11 @@ { - while ( pad.start_pressed() == false) { - lcd.printString(" SNAKE ",0,1); - lcd.printString("COLLECT APPLES",0,3); - lcd.printString(" Press Start ",0,5); - lcd.setContrast( pad.read_pot1()); + while ( pad.start_pressed() == false) { //main menu - wont enter game loop until start is pressed + lcd.printString(" SNAKE ",0,1); // + lcd.printString("COLLECT APPLES",0,3); //game task + lcd.printString(" Press Start ",0,5); //instruction + lcd.setContrast( pad.read_pot1()); //adjust contrast pad.leds_off(); @@ -124,22 +113,8 @@ pad.led(4,1); wait(0.2); - lcd.refresh(); + lcd.refresh(); //updates screen } } - - - - -//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 \ No newline at end of file