ELEC2645 (2019/20)
/
ELEC2645_Project_el17oc1
Owen Cavender 201159294
Diff: main.cpp
- Revision:
- 12:60c856354406
- Parent:
- 10:ee781d18e0f6
- Child:
- 14:7fb3c93343b6
diff -r ee781d18e0f6 -r 60c856354406 main.cpp --- a/main.cpp Thu May 28 20:58:49 2020 +0000 +++ b/main.cpp Fri May 29 16:00:56 2020 +0000 @@ -29,7 +29,7 @@ Gamepad pad; Snake snake; N5110 lcd; -Timer timer; +Ticker ticker; GameEngine engine; //functions @@ -38,63 +38,70 @@ void init(); void update_game_state(); void gameover_true(); +void ticker_isr(); + +int countdown; + + //Serial pc(USBTX, USBRX); int main() { - int fps = 6; // frames per second - - init(); // initialise and then display welcome screen... + int fps = 6; + init(); // frames per second welcome(); - wait(1.0f/fps); // and wait for one frame period + // initialise and then display welcome screen... + + // and wait for one frame period render(); - timer.start(); //ROB atm the code works to here + //ROB atm the code works to here //need to draw an initial snake - + while (1) { - - snake.get_direction(pad); - snake.render_clear_tail(lcd); - engine.get_LEDs(pad, snake); // =needs to be cleared before _x3, _y3 is updated - snake.move_snake(); - - snake.check_collisions(); - snake.apple_collected(lcd, pad, timer); - - snake.get_time(timer); + + + 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); - gameover_true(); - snake.render(lcd); - snake.print_display_time(lcd); - - wait(1.0f/fps); + wait(1.0f/6); } } -//added old score - changed postion of timer and code +//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); + // lcd.printString(" Press Start ",0,4); while ( pad.start_pressed() == false) { lcd.setContrast( pad.read_pot1()); @@ -103,7 +110,7 @@ pad.leds_off(); wait(0.1); } - lcd.refresh(); + lcd.refresh(); } @@ -113,36 +120,18 @@ 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.printString( " Game Over L ", 0, 2 ); - engine.print_scores(lcd, snake); +//MAKE TIMER IN ONE CLASS SNAKE +//SPAWN APPLE +//MOVE THE SNAKE --- +// - 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); - } - wait(3); - - 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