Stick_Runner
Dependencies: FXOS8700CQ Gamepad N5110 SDFileSystem mbed
Fork of Stick_Runner by
Gems/Gems.cpp
- Committer:
- el15ss
- Date:
- 2017-05-03
- Revision:
- 4:2fdafb53eac2
- Parent:
- 3:0c690f1c04d8
- Child:
- 5:1bf7c83f86cc
File content as of revision 4:2fdafb53eac2:
#include "Gems.h" 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; } void Gems::draw(N5110 &lcd) { //Drawing the gems lcd.setPixel(gemPosX,gemPosY); lcd.setPixel(gemPosX+1,gemPosY); lcd.setPixel(gemPosX-1,gemPosY); lcd.setPixel(gemPosX,gemPosY+1); lcd.setPixel(gemPosX,gemPosY-1); } //To move the gem void Gems::updateGems() { //Updating the position of the gem on the screen and setting its speed gemPosY =gemPosY+2; } 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)) { 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; } } //Returns the postion (x,y) of the gems on the screen Vector2D Gems::getGemPos() { Vector2D p = {gemPosX,gemPosY}; return p; } //Returns the status of the obstacle bool Gems::getGemStatus() { //Used to check when to initialise and render the gem return gStatus; }