![](/media/cache/group/default_image.jpg.50x50_q85.jpg)
Owen Cavender 201159294
GameEngine.cpp
- Committer:
- el17oc
- Date:
- 2020-05-30
- Revision:
- 15:6857657bb4e2
- Parent:
- 14:7fb3c93343b6
- Child:
- 16:9500059ad5d8
File content as of revision 15:6857657bb4e2:
#include "GameEngine.h" GameEngine::GameEngine() { } GameEngine::~GameEngine() { } 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); } void GameEngine::get_LEDs(Gamepad &pad, Snake &snake) { pad.leds_off(); Vector2D Snakehead = snake.get_Snakehead(); 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 <= 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); wait(0.2); pad.led(4, 0); } // topleft led on if (_x0 <= 42 && _y0 <= 16 ) { pad.led(1, 1); wait(0.2); pad.led(1, 0); } //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 >= 16) { // top right led on pad.led(6, 1); wait(0.2); pad.led(6, 0); } else { } } void GameEngine::print_countdown(N5110 &lcd, Snake &snake) { int countdown = snake.get_countdown(); //Accessing the value of the member variale _countdown char buffer1[14]; 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); }