Stick_Runner
Dependencies: FXOS8700CQ Gamepad N5110 SDFileSystem mbed
Diff: Obstacles/Obstacles.cpp
- Revision:
- 3:0c690f1c04d8
- Parent:
- 2:98a41609c827
- Child:
- 4:2fdafb53eac2
diff -r 98a41609c827 -r 0c690f1c04d8 Obstacles/Obstacles.cpp --- a/Obstacles/Obstacles.cpp Tue May 02 18:42:45 2017 +0000 +++ b/Obstacles/Obstacles.cpp Wed May 03 09:27:04 2017 +0000 @@ -5,17 +5,17 @@ void Obstacles::init() { + //Initializing the X and Y co ordinates of the obstacle obsPosX = rand() % 84; obsPosY = rand() % 42-42; + + //variable to store the status of the obstacle obStatus = true; } void Obstacles::draw(N5110 &lcd) { - //lcd.drawRect(obsPosX-4,obsPosY-3,3,3,FILL_BLACK); - //lcd.drawLine(obsPosX-3, obsPosY-3,obsPosX-3,obsPosY+1,1); - - //lcd.drawCircle(obsPosX,obsPosY,2,FILL_BLACK); + //Drawing the character lcd.setPixel(obsPosX,obsPosY); @@ -24,36 +24,35 @@ } - +//To move the obstacle void Obstacles::updateObstacle() { + //Updating the position of the obstacle on the screen and setting its speed obsPosY =obsPosY+1; } +//Function to check if the obstacle has reached the end of the screen void Obstacles::obstacleStatus(Vector2D p) { - /* if(((p.x<obsPosX+3)&&(p.x>obsPosX-3))&&((p.y<obsPosY+3)&&(p.y>obsPosY-3))){ - - obstacleStatus = false; - } - */ + //Update status if at end of the screen if(obsPosY > HEIGHT) { obStatus = false; } } - +//Returns the postion (x,y) of the obstacle on the screen Vector2D Obstacles::getObstaclePos() { Vector2D p = {obsPosX,obsPosY}; return p; } - +//Returns the status of the obstacle bool Obstacles::getObstacleStatus() { + //Used to check when to initialise and render the obstacle return obStatus; }