![](/media/cache/group/default_image.jpg.50x50_q85.jpg)
Owen Cavender 201159294
main.cpp
- Committer:
- el17oc
- Date:
- 2020-05-30
- Revision:
- 14:7fb3c93343b6
- Parent:
- 12:60c856354406
- Child:
- 16:9500059ad5d8
File content as of revision 14:7fb3c93343b6:
/* 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 this on the LCD. There is usual//// */ // includes #include "mbed.h" #include "Gamepad.h" #include "N5110.h" #include "snake.h" #include "GameEngine.h" //write spec for game //objects Gamepad pad; Snake snake; N5110 lcd; GameEngine engine; //functions void welcome(); void render(); void init(); void update_snake(); //Serial pc(USBTX, USBRX); int main() { //int fps = 6; init(); // frames per second welcome(); // initialise and then display welcome screen... while (1) { update_snake(); snake.check_gameover(lcd); snake.gameover_true(lcd, pad); snake.apple_collected(lcd, pad); snake.get_Apple_position(lcd); engine.get_LEDs(pad, snake); engine.print_countdown(lcd, snake); snake.render(lcd); // snake.print_display_time(lcd); wait(0.01); } } //apples //timer check void init() { lcd.init(); pad.init(); snake.init(); //need to initialise snake class } void update_snake() { snake.get_direction(pad); //sets the direction based on buttons pressed on the Gamepad snake.render_clear_tail(lcd); //clears the trailing pixel of the snake before updating position to avoid the snake growing with each move - the trailing pixel would be locked and fixed as 1 in its initial position without this // =needs to be cleared before _x3, _y3 is updated snake.move_snake(); //alters the coordinate of each snake bit in accordance with the Gamepad instruction engine.get_LEDs(pad, snake); //Turns on on LEDS based on where the snake is in the box } void welcome() { 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()); pad.leds_off(); pad.led(1,1); wait(0.2); pad.led(1,0); //turning on the LEDS in a sequence which reflects the snakes movement pad.led(2,1); wait (0.2); pad.led(2,0); pad.led(3,1); wait(0.2); pad.led(3,0); wait(0.1); pad.led(6,1); wait (0.2); pad.led(6,0); pad.led(5,1); wait (0.2); pad.led(5,0); pad.led(4,1); wait(0.2); lcd.refresh(); } } //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