Owen Cavender 201159294

Dependencies:   mbed Gamepad2

Committer:
el17oc
Date:
Wed May 27 10:27:34 2020 +0000
Revision:
5:d716013c6a18
Parent:
2:44e4a6ecdbef
not final

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