![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
Owen Cavender 201159294
GameEngine.cpp@1:897160a1a3ae, 2020-05-26 (annotated)
- Committer:
- el17oc
- Date:
- Tue May 26 12:17:59 2020 +0000
- Revision:
- 1:897160a1a3ae
- Child:
- 2:44e4a6ecdbef
ELEC2645
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
el17oc | 1:897160a1a3ae | 1 | #include "GameEngine.h" |
el17oc | 1:897160a1a3ae | 2 | GameEngine::GameEngine() |
el17oc | 1:897160a1a3ae | 3 | { |
el17oc | 1:897160a1a3ae | 4 | |
el17oc | 1:897160a1a3ae | 5 | } |
el17oc | 1:897160a1a3ae | 6 | |
el17oc | 1:897160a1a3ae | 7 | GameEngine::~GameEngine() |
el17oc | 1:897160a1a3ae | 8 | { |
el17oc | 1:897160a1a3ae | 9 | |
el17oc | 1:897160a1a3ae | 10 | } |
el17oc | 1:897160a1a3ae | 11 | |
el17oc | 1:897160a1a3ae | 12 | void GameEngine::init(int shx, int shy, int apx, int apy) |
el17oc | 1:897160a1a3ae | 13 | { |
el17oc | 1:897160a1a3ae | 14 | _shx = shx; |
el17oc | 1:897160a1a3ae | 15 | _shy = shy; //intial value in front of snake |
el17oc | 1:897160a1a3ae | 16 | _apx = apx; |
el17oc | 1:897160a1a3ae | 17 | _apy = apy; |
el17oc | 1:897160a1a3ae | 18 | } |
el17oc | 1:897160a1a3ae | 19 | |
el17oc | 1:897160a1a3ae | 20 | |
el17oc | 1:897160a1a3ae | 21 | |
el17oc | 1:897160a1a3ae | 22 | void GameEngine::set_Snakehead(Vector2D Snakehead) |
el17oc | 1:897160a1a3ae | 23 | { |
el17oc | 1:897160a1a3ae | 24 | Snakehead.x = _shx; |
el17oc | 1:897160a1a3ae | 25 | Snakehead.y = _shy; |
el17oc | 1:897160a1a3ae | 26 | } |
el17oc | 1:897160a1a3ae | 27 | |
el17oc | 1:897160a1a3ae | 28 | Vector2D GameEngine::get_Snakehead() |
el17oc | 1:897160a1a3ae | 29 | { |
el17oc | 1:897160a1a3ae | 30 | Vector2D Snakehead = {_shx, _shy}; |
el17oc | 1:897160a1a3ae | 31 | return Snakehead; |
el17oc | 1:897160a1a3ae | 32 | } |
el17oc | 1:897160a1a3ae | 33 | |
el17oc | 1:897160a1a3ae | 34 | |
el17oc | 1:897160a1a3ae | 35 | Vector2D GameEngine::get_Applepos() |
el17oc | 1:897160a1a3ae | 36 | { |
el17oc | 1:897160a1a3ae | 37 | Vector2D Applepos = {_apx, _apy}; |
el17oc | 1:897160a1a3ae | 38 | return Applepos; |
el17oc | 1:897160a1a3ae | 39 | } |
el17oc | 1:897160a1a3ae | 40 | |
el17oc | 1:897160a1a3ae | 41 | |
el17oc | 1:897160a1a3ae | 42 | void GameEngine::set_Applepos(N5110 &lcd) |
el17oc | 1:897160a1a3ae | 43 | { |
el17oc | 1:897160a1a3ae | 44 | |
el17oc | 1:897160a1a3ae | 45 | 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 |
el17oc | 1:897160a1a3ae | 46 | int appleposy = rand()%24; |
el17oc | 1:897160a1a3ae | 47 | |
el17oc | 1:897160a1a3ae | 48 | |
el17oc | 1:897160a1a3ae | 49 | if(lcd.getPixel(appleposx, appleposy)) { // this pixel is set } else { // this pixel is clear } |
el17oc | 1:897160a1a3ae | 50 | appleposx = rand()%84; |
el17oc | 1:897160a1a3ae | 51 | appleposy = rand()%24; // making sure the apple doesnt spawn inside the snakes body or wall which would increase the score |
el17oc | 1:897160a1a3ae | 52 | } else { |
el17oc | 1:897160a1a3ae | 53 | |
el17oc | 1:897160a1a3ae | 54 | |
el17oc | 1:897160a1a3ae | 55 | _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 |
el17oc | 1:897160a1a3ae | 56 | _apy = appleposy; //alters value of private variable - this can then be accessed by get_Applepos |
el17oc | 1:897160a1a3ae | 57 | |
el17oc | 1:897160a1a3ae | 58 | lcd.setPixel(_apx,_apy, true); |
el17oc | 1:897160a1a3ae | 59 | } |
el17oc | 1:897160a1a3ae | 60 | } |
el17oc | 1:897160a1a3ae | 61 | |
el17oc | 1:897160a1a3ae | 62 | |
el17oc | 1:897160a1a3ae | 63 | //void GameEngine::clear_applepos(N5110 &lcd) { |
el17oc | 1:897160a1a3ae | 64 | // int length = _snake.get_Length(); |
el17oc | 1:897160a1a3ae | 65 | // wait(length x fps); |
el17oc | 1:897160a1a3ae | 66 | // lcd.setPixel(Applepos.x, Applepos.y,0); |
el17oc | 1:897160a1a3ae | 67 | // } |
el17oc | 1:897160a1a3ae | 68 | //void Snakerender_apple() |
el17oc | 1:897160a1a3ae | 69 | // lcd.setPixel(_apx,_apy, true); |