Stick_Runner
Dependencies: FXOS8700CQ Gamepad N5110 SDFileSystem mbed
Gems/Gems.cpp
- Committer:
- el15ss
- Date:
- 2017-05-04
- Revision:
- 6:bf601a65cb27
- Parent:
- 5:1bf7c83f86cc
File content as of revision 6:bf601a65cb27:
#include "Gems.h" void Gems::init() { //fprintf("in gem 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 //fprintf("gem being drawn"); 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 //fprintf("updating th gem to make it move"); gemPosY =gemPosY+2; } void Gems::gemStatus(Vector2D p) { //fprintf("in gem status"); //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; } //fprintf("gem status vale after checking if consumed %d",gStatus ); //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() { //fprintf("in gem get pos"); Vector2D p = {gemPosX,gemPosY}; return p; } //Returns the status of the obstacle bool Gems::getGemStatus() { //fprintf("in get gem status"); //fprintf("The value of gem status is (in 0/1) %d",gStatus); //Used to check when to initialise and render the gem return gStatus; }