Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Revision 1:a308877d2475, committed 2019-02-11
- Comitter:
- schizzlewizzle
- Date:
- Mon Feb 11 13:39:58 2019 +0000
- Parent:
- 0:8680a1ea7711
- Child:
- 2:9b6d3e17f059
- Commit message:
- comments
Changed in this revision
| main.cpp | Show annotated file Show diff for this revision Revisions of this file |
--- 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);