ELEC2645 (2019/20)
/
ELEC2645_Project_el17oc1
Owen Cavender 201159294
Diff: GameEngine.cpp
- Revision:
- 14:7fb3c93343b6
- Parent:
- 12:60c856354406
- Child:
- 15:6857657bb4e2
diff -r b37dde18bfdc -r 7fb3c93343b6 GameEngine.cpp --- a/GameEngine.cpp Fri May 29 16:27:29 2020 +0000 +++ b/GameEngine.cpp Sat May 30 02:31:43 2020 +0000 @@ -12,11 +12,12 @@ void GameEngine::print_scores(N5110 &lcd, Snake &snake) { + int score = snake.get_score(); char buffer1[14]; sprintf(buffer1,"%2d",score); - lcd.printString(buffer1,0 ,48); // font is 8 wide, so leave 4 pixel gape from middle assuming two digits + lcd.printString(buffer1,0,48); // font is 8 wide, so leave 4 pixel gape from middle assuming two digits } @@ -26,10 +27,10 @@ { pad.leds_off(); Vector2D Snakehead = snake.get_Snakehead(); - int _x0 = Snakehead.x; - int _y0 = Snakehead.y; + int _x0 = Snakehead.x; + int _y0 = Snakehead.y; //depending where the snakehead is on the screen, different LEDs will turn on indicating its postion - if (_x0 >= 42 && _y0 >= 24) { + if (_x0 >= 42 && _y0 <= 16) { //defines paramaters of the top right quadrant of the lcd rectangle and turns on and off the top right LED if the // top right led on pad.led(4, 1); @@ -37,37 +38,37 @@ pad.led(4, 0); } // topleft led on - if (_x0 <= 42 && _y0 >=24) { - // top right led on + if (_x0 <= 42 && _y0 <= 16 ) { + pad.led(1, 1); wait(0.2); pad.led(1, 0); } - //bottom left - if (_x0 <=42 && _y0 <= 24) { + //bottom left //defines paramaters of the bottom left quadrant of the rectangle ont the lcd display and turns on and off the bottom left LED + if (_x0 <=42 && _y0 >= 16 ) { pad.led(3,1); wait(0.2); pad.led(3, 0); } //bottom right - if (_x0 >= 42 && _y0 <= 24) { + if (_x0 >= 42 && _y0 >= 16) { // top right led on pad.led(6, 1); wait(0.2); pad.led(6, 0); + } else { } - else { -} } -void GameEngine::print_countdown(N5110 &lcd, Snake &snake){ +void GameEngine::print_countdown(N5110 &lcd, Snake &snake) +{ - int countdown = snake.get_countdown(); + int countdown = snake.get_countdown(); //Accessing the value of the member variale _countdown char buffer1[14]; - sprintf(buffer1,"%2d",countdown); - lcd.printString(buffer1,WIDTH/2 - 3,4); // font is 8 wide, so leave 4 pixel gape from middle assuming two digits - printf(" countdown= %d ", countdown); + sprintf(buffer1,"%2d",countdown); //printing value onto lcd in each loops. - counter is set to decrement by 1 each loop + lcd.printString(buffer1,0,4); // +// printf(" countdown= %d ", countdown); }