ELEC2645 (2019/20)
/
ELEC2645_Project_el17oc1
Owen Cavender 201159294
main.cpp
- Committer:
- el17oc
- Date:
- 2020-05-28
- Revision:
- 6:bf90044188d0
- Parent:
- 5:d716013c6a18
- Child:
- 8:997f90c88246
File content as of revision 6:bf90044188d0:
/* 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 "Apple.h" //objects Gamepad pad; Snake snake; N5110 lcd; Apple apple; Timer timer; //functions void welcome(); void render(); void init(); void update_game_state(); void gameover_true(); //Serial pc(USBTX, USBRX); int main() { printf("hello world"); int fps = 6; // frames per second init(); // initialise and then display welcome screen... welcome(); wait(1.0f/fps); // and wait for one frame period render(); timer.start(); //ROB atm the code works to here //need to draw an initial snake while (1) { ; snake.get_position(pad); snake.check_collisions(); snake.check_score(lcd, pad, apple, timer); snake.get_timer(timer); gameover_true(); snake.render(lcd, apple); wait(1.0f/fps); } } void init() { snake.init(); //need to initialise snake class pad.init(); lcd.init(); apple.init(48, 24); } void welcome() { lcd.refresh(); printf("hello world"); 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); } } void render() { lcd.clear(); lcd.drawRect(0, 0, 84, 42, FILL_TRANSPARENT); lcd.printString(" GO! ", 0,25); wait(1.0); lcd.refresh(); } void gameover_true() //taking action if crash has occured { bool gameover = snake.get_gameover(); int score = snake.get_score(); while (gameover == true) { lcd.clear(); lcd.refresh(); lcd.printString( " Game Over L ", 0, 2 ); snake.print_scores(lcd); if (score <= 7) { lcd.printString(" Loser ", 0,10); } if (7< score <= 25) { lcd.printString(" Good Job! ", 0,10); } else { lcd.printString(" SNAKE PRO ", 0,10); lcd.printString(" ~.~.~.~.<8>~ ", 0, 5); } } } //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