Challenge number 1

Dependencies:   IoTChallenge1

Revision:
1:a308877d2475
Parent:
0:8680a1ea7711
Child:
2:9b6d3e17f059
diff -r 8680a1ea7711 -r a308877d2475 main.cpp
--- a/main.cpp	Mon Feb 11 12:13:52 2019 +0000
+++ b/main.cpp	Mon Feb 11 13:39:58 2019 +0000
@@ -1,5 +1,5 @@
 #include "MicroBit.h"
- 
+/ 
 int pLocationX;
 int pLocationY;
 int xPos = 2;
@@ -11,6 +11,7 @@
 int direction = 0;
 MicroBit uBit;
 
+//Gets X value from microbit
 void getXPos(){
     playX = uBit.accelerometer.getX();
     if(playX > 250){
@@ -22,7 +23,8 @@
     }
     
 }
-    
+
+//Compares player location with obstacle location to check collision.    
 void checkCollision(){
     if (xPos == obstacleX || xPos == obstacleX - 1 && y == 4){
         gameOver = true;    
@@ -32,6 +34,8 @@
         }
         
 }
+
+//Draws the player on screen, and ensures it cannot go off the side. Also clears lEDs as it moves.
 void displayPlayerLocation(){
     getXPos();
     if (xPos < 0){
@@ -48,6 +52,8 @@
     checkCollision();
     uBit.display.image.setPixelValue(xPos, 4, 255);
 }
+
+//Displays the falling leds, and also clears them afterwards
 void displayObs(){
     uBit.display.image.setPixelValue(obstacleX, y, 0);
     obstacleX = uBit.random(5);