Owen Cavender 201159294

Dependencies:   mbed Gamepad2

Committer:
el17oc
Date:
Tue May 26 18:42:16 2020 +0000
Revision:
4:748e3ff14e72
Parent:
2:44e4a6ecdbef
N0.3

Who changed what in which revision?

UserRevisionLine numberNew 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 2:44e4a6ecdbef 12 void GameEngine::init(int shx, int shy, int apx, int apy, int Oshx, int Oshy)
el17oc 1:897160a1a3ae 13 {
el17oc 1:897160a1a3ae 14 _shx = shx;
el17oc 2:44e4a6ecdbef 15 _shy = shy;
el17oc 1:897160a1a3ae 16 _apx = apx;
el17oc 1:897160a1a3ae 17 _apy = apy;
el17oc 2:44e4a6ecdbef 18 _Oshx = Oshx;
el17oc 2:44e4a6ecdbef 19 _Oshy = Oshy;
el17oc 1:897160a1a3ae 20 }
el17oc 1:897160a1a3ae 21
el17oc 1:897160a1a3ae 22
el17oc 1:897160a1a3ae 23
el17oc 1:897160a1a3ae 24 void GameEngine::set_Snakehead(Vector2D Snakehead)
el17oc 1:897160a1a3ae 25 {
el17oc 1:897160a1a3ae 26 Snakehead.x = _shx;
el17oc 1:897160a1a3ae 27 Snakehead.y = _shy;
el17oc 1:897160a1a3ae 28 }
el17oc 1:897160a1a3ae 29
el17oc 1:897160a1a3ae 30 Vector2D GameEngine::get_Snakehead()
el17oc 1:897160a1a3ae 31 {
el17oc 1:897160a1a3ae 32 Vector2D Snakehead = {_shx, _shy};
el17oc 1:897160a1a3ae 33 return Snakehead;
el17oc 1:897160a1a3ae 34 }
el17oc 1:897160a1a3ae 35
el17oc 2:44e4a6ecdbef 36 Vector2D GameEngine::get_oldSnakehead()
el17oc 2:44e4a6ecdbef 37 {
el17oc 2:44e4a6ecdbef 38 Vector2D oldSnakehead = {_Oshx, _Oshy};
el17oc 2:44e4a6ecdbef 39 return oldSnakehead;
el17oc 2:44e4a6ecdbef 40 }
el17oc 1:897160a1a3ae 41
el17oc 1:897160a1a3ae 42 Vector2D GameEngine::get_Applepos()
el17oc 1:897160a1a3ae 43 {
el17oc 1:897160a1a3ae 44 Vector2D Applepos = {_apx, _apy};
el17oc 1:897160a1a3ae 45 return Applepos;
el17oc 1:897160a1a3ae 46 }
el17oc 1:897160a1a3ae 47
el17oc 1:897160a1a3ae 48
el17oc 1:897160a1a3ae 49 void GameEngine::set_Applepos(N5110 &lcd)
el17oc 1:897160a1a3ae 50 {
el17oc 1:897160a1a3ae 51
el17oc 2:44e4a6ecdbef 52 int appleposx = rand()%84;
el17oc 2:44e4a6ecdbef 53 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?
el17oc 1:897160a1a3ae 54
el17oc 1:897160a1a3ae 55
el17oc 2:44e4a6ecdbef 56 if(lcd.getPixel(appleposx, appleposy)) { // this pixel is set -- 'if it is already filled on lcd, pick new position'
el17oc 1:897160a1a3ae 57 appleposx = rand()%84;
el17oc 1:897160a1a3ae 58 appleposy = rand()%24; // making sure the apple doesnt spawn inside the snakes body or wall which would increase the score
el17oc 1:897160a1a3ae 59 } else {
el17oc 1:897160a1a3ae 60
el17oc 1:897160a1a3ae 61
el17oc 1:897160a1a3ae 62 _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 63 _apy = appleposy; //alters value of private variable - this can then be accessed by get_Applepos
el17oc 1:897160a1a3ae 64
el17oc 1:897160a1a3ae 65 lcd.setPixel(_apx,_apy, true);
el17oc 1:897160a1a3ae 66 }
el17oc 1:897160a1a3ae 67 }
el17oc 1:897160a1a3ae 68
el17oc 1:897160a1a3ae 69
el17oc 1:897160a1a3ae 70 //void GameEngine::clear_applepos(N5110 &lcd) {
el17oc 1:897160a1a3ae 71 // int length = _snake.get_Length();
el17oc 1:897160a1a3ae 72 // wait(length x fps);
el17oc 1:897160a1a3ae 73 // lcd.setPixel(Applepos.x, Applepos.y,0);
el17oc 1:897160a1a3ae 74 // }
el17oc 1:897160a1a3ae 75 //void Snakerender_apple()
el17oc 1:897160a1a3ae 76 // lcd.setPixel(_apx,_apy, true);