Owen Cavender
/
ELEC2645_Project_el17oc11
Owen Cavender 201159294
GameEngine.cpp
- Committer:
- el17oc
- Date:
- 2020-05-26
- Revision:
- 4:748e3ff14e72
- Parent:
- 2:44e4a6ecdbef
File content as of revision 4:748e3ff14e72:
#include "GameEngine.h" GameEngine::GameEngine() { } GameEngine::~GameEngine() { } void GameEngine::init(int shx, int shy, int apx, int apy, int Oshx, int Oshy) { _shx = shx; _shy = shy; _apx = apx; _apy = apy; _Oshx = Oshx; _Oshy = Oshy; } 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_oldSnakehead() { Vector2D oldSnakehead = {_Oshx, _Oshy}; return oldSnakehead; } Vector2D GameEngine::get_Applepos() { Vector2D Applepos = {_apx, _apy}; return Applepos; } void GameEngine::set_Applepos(N5110 &lcd) { int appleposx = rand()%84; int appleposy = rand()%24; //ROB apparently rand() is seeded so will generate same position each time - do you know any other random methods to put here? if(lcd.getPixel(appleposx, appleposy)) { // this pixel is set -- 'if it is already filled on lcd, pick new position' 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);