Stick_Runner

Dependencies:   FXOS8700CQ Gamepad N5110 SDFileSystem mbed

Committer:
el15ss
Date:
Thu May 04 13:04:14 2017 +0000
Revision:
6:bf601a65cb27
Parent:
4:2fdafb53eac2
StickRunner v1.0;

Who changed what in which revision?

UserRevisionLine numberNew contents of line
el15ss 0:12cfe63faa6a 1
el15ss 0:12cfe63faa6a 2
el15ss 0:12cfe63faa6a 3 #include "Obstacles.h"
el15ss 0:12cfe63faa6a 4
el15ss 0:12cfe63faa6a 5
el15ss 0:12cfe63faa6a 6 void Obstacles::init()
el15ss 0:12cfe63faa6a 7 {
el15ss 6:bf601a65cb27 8 //fprintf("in obstacle init");
el15ss 3:0c690f1c04d8 9 //Initializing the X and Y co ordinates of the obstacle
el15ss 1:db9ff66f67c8 10 obsPosX = rand() % 84;
el15ss 1:db9ff66f67c8 11 obsPosY = rand() % 42-42;
el15ss 3:0c690f1c04d8 12
el15ss 3:0c690f1c04d8 13 //variable to store the status of the obstacle
el15ss 1:db9ff66f67c8 14 obStatus = true;
el15ss 0:12cfe63faa6a 15 }
el15ss 0:12cfe63faa6a 16
el15ss 0:12cfe63faa6a 17 void Obstacles::draw(N5110 &lcd)
el15ss 0:12cfe63faa6a 18 {
el15ss 6:bf601a65cb27 19
el15ss 3:0c690f1c04d8 20 //Drawing the character
el15ss 6:bf601a65cb27 21 //fprintf("Obstacle being drawn");
el15ss 1:db9ff66f67c8 22 lcd.setPixel(obsPosX,obsPosY);
el15ss 1:db9ff66f67c8 23
el15ss 1:db9ff66f67c8 24
el15ss 0:12cfe63faa6a 25 }
el15ss 0:12cfe63faa6a 26
el15ss 3:0c690f1c04d8 27 //To move the obstacle
el15ss 2:98a41609c827 28 void Obstacles::updateObstacle()
el15ss 2:98a41609c827 29 {
el15ss 3:0c690f1c04d8 30 //Updating the position of the obstacle on the screen and setting its speed
el15ss 6:bf601a65cb27 31 //fprintf("updating th obstaclee to make it move");
el15ss 2:98a41609c827 32 obsPosY =obsPosY+1;
el15ss 2:98a41609c827 33
el15ss 2:98a41609c827 34 }
el15ss 2:98a41609c827 35
el15ss 3:0c690f1c04d8 36 //Function to check if the obstacle has reached the end of the screen
el15ss 1:db9ff66f67c8 37 void Obstacles::obstacleStatus(Vector2D p)
el15ss 0:12cfe63faa6a 38 {
el15ss 6:bf601a65cb27 39 //fprintf("in obstacle status");
el15ss 6:bf601a65cb27 40
el15ss 3:0c690f1c04d8 41 //Update status if at end of the screen
el15ss 1:db9ff66f67c8 42 if(obsPosY > HEIGHT)
el15ss 0:12cfe63faa6a 43 {
el15ss 1:db9ff66f67c8 44 obStatus = false;
el15ss 0:12cfe63faa6a 45 }
el15ss 0:12cfe63faa6a 46 }
el15ss 0:12cfe63faa6a 47
el15ss 3:0c690f1c04d8 48 //Returns the postion (x,y) of the obstacle on the screen
el15ss 1:db9ff66f67c8 49 Vector2D Obstacles::getObstaclePos()
el15ss 1:db9ff66f67c8 50 {
el15ss 6:bf601a65cb27 51 //fprintf("in obstacle get pos");
el15ss 6:bf601a65cb27 52
el15ss 1:db9ff66f67c8 53 Vector2D p = {obsPosX,obsPosY};
el15ss 6:bf601a65cb27 54 //fprintf("the value of p is %d", p);
el15ss 6:bf601a65cb27 55
el15ss 0:12cfe63faa6a 56 return p;
el15ss 0:12cfe63faa6a 57 }
el15ss 1:db9ff66f67c8 58
el15ss 3:0c690f1c04d8 59 //Returns the status of the obstacle
el15ss 1:db9ff66f67c8 60 bool Obstacles::getObstacleStatus()
el15ss 1:db9ff66f67c8 61 {
el15ss 6:bf601a65cb27 62 //fprintf("in get obstacle status");
el15ss 6:bf601a65cb27 63
el15ss 6:bf601a65cb27 64 //fprintf("The value of obstacle status is (in 0/1) %d",obStatus);
el15ss 6:bf601a65cb27 65
el15ss 3:0c690f1c04d8 66 //Used to check when to initialise and render the obstacle
el15ss 1:db9ff66f67c8 67 return obStatus;
el15ss 0:12cfe63faa6a 68
el15ss 4:2fdafb53eac2 69 }
el15ss 0:12cfe63faa6a 70
el15ss 0:12cfe63faa6a 71