![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
Owen Cavender 201159294
GameEngine.cpp
- Committer:
- el17oc
- Date:
- 2020-05-26
- Revision:
- 1:897160a1a3ae
- Child:
- 2:44e4a6ecdbef
File content as of revision 1:897160a1a3ae:
#include "GameEngine.h" GameEngine::GameEngine() { } GameEngine::~GameEngine() { } void GameEngine::init(int shx, int shy, int apx, int apy) { _shx = shx; _shy = shy; //intial value in front of snake _apx = apx; _apy = apy; } void GameEngine::set_Snakehead(Vector2D Snakehead) { Snakehead.x = _shx; Snakehead.y = _shy; } Vector2D GameEngine::get_Snakehead() { Vector2D Snakehead = {_shx, _shy}; return Snakehead; } Vector2D GameEngine::get_Applepos() { Vector2D Applepos = {_apx, _apy}; return Applepos; } void GameEngine::set_Applepos(N5110 &lcd) { int appleposx = rand()%84; //is this generating new position or will it just stick to one random selection - need to make sure its in the loop int appleposy = rand()%24; if(lcd.getPixel(appleposx, appleposy)) { // this pixel is set } else { // this pixel is clear } appleposx = rand()%84; appleposy = rand()%24; // making sure the apple doesnt spawn inside the snakes body or wall which would increase the score } else { _apx = appleposx; //i and j are fed into applepos.x/y -- those values are then fed into set_applepos which assigngs that value to _appleposx/y which then is fed into get_applepos where it is stored and returned _apy = appleposy; //alters value of private variable - this can then be accessed by get_Applepos lcd.setPixel(_apx,_apy, true); } } //void GameEngine::clear_applepos(N5110 &lcd) { // int length = _snake.get_Length(); // wait(length x fps); // lcd.setPixel(Applepos.x, Applepos.y,0); // } //void Snakerender_apple() // lcd.setPixel(_apx,_apy, true);