Stick_Runner
Dependencies: FXOS8700CQ Gamepad N5110 SDFileSystem mbed
Diff: Gems/Gems.cpp
- Revision:
- 3:0c690f1c04d8
- Parent:
- 2:98a41609c827
- Child:
- 4:2fdafb53eac2
--- a/Gems/Gems.cpp Tue May 02 18:42:45 2017 +0000 +++ b/Gems/Gems.cpp Wed May 03 09:27:04 2017 +0000 @@ -3,9 +3,11 @@ void Gems::init() { + //Initializing the X and Y co ordinates of the character gemPosX = rand() % 84; gemPosY = rand() % 42-42; + //variable to store the status of the gem gStatus = true; } @@ -13,10 +15,7 @@ void Gems::draw(N5110 &lcd) { - //lcd.drawRect(gemPosX-4,gemPosY-3,3,3,FILL_BLACK); - //lcd.drawLine(gemPosX-3, gemPosY-3,gemPosX-3,gemPosY+1,1); - - //lcd.drawCircle(gemPosX,gemPosY,2,FILL_BLACK); + //Drawing the gems lcd.setPixel(gemPosX,gemPosY); lcd.setPixel(gemPosX+1,gemPosY); lcd.setPixel(gemPosX-1,gemPosY); @@ -30,13 +29,11 @@ -int Gems::gemScore() -{ - //return counter; -} +//To move the gem void Gems::updateGems() { + //Updating the position of the gem on the screen and setting its speed gemPosY =gemPosY+2; } @@ -44,15 +41,16 @@ void Gems::gemStatus(Vector2D p) { + //Loop to check if a gem has touched the character and update its staus to make it siappear from the screen if(((gemPosX>p.x-5)&&(gemPosX<p.x+5))&&(gemPosY>p.y)) { - //counter++; + gStatus = false; } - + //To check if the gem has reached the bottom of the screen so we can intialise and render again if(gemPosY > HEIGHT) { gStatus = false; @@ -60,6 +58,7 @@ } +//Returns the postion (x,y) of the gems on the screen Vector2D Gems::getGemPos() { @@ -67,8 +66,10 @@ return p; } +//Returns the status of the obstacle bool Gems::getGemStatus() { + //Used to check when to initialise and render the gem return gStatus; }