IoT Challenge 1

Dependencies:   microbit-dal

Dependents:   IoTChallengeGame1

Files at this revision

API Documentation at this revision

Comitter:
schizzlewizzle
Date:
Mon Feb 11 12:07:51 2019 +0000
Parent:
15:138fa7c00834
Commit message:
finished

Changed in this revision

test.txt Show diff for this revision Revisions of this file
--- a/test.txt	Mon Feb 11 11:34:34 2019 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,100 +0,0 @@
-#include "MicroBit.h"
- 
-int pLocationX;
-int pLocationY;
-int xPos = 2;
-bool gameOver = false;
-int y;
-int obstacleX;
-int score = 0;
-int playX;
-int direction = 0;
-MicroBit uBit;
-
-void getXPos(){
-    playX = uBit.accelerometer.getX();
-    if(playX > 250){
-        xPos++;
-        direction = 1;
-    }else if (playX < -250) {
-        xPos--;
-        direction = 0;
-    }
-    
-}
-    
-void checkCollision(){
-    if (xPos == obstacleX || xPos == obstacleX - 1 && y == 4){
-        gameOver = true;    
-    }else{
-            
-        gameOver = false;
-        }
-        
-}
-void displayPlayerLocation(){
-    getXPos();
-    if (xPos < 0){
-        xPos = 0;
-    } else if(xPos > 4) {
-        xPos = 4;
-    } 
-    if(direction == 1) {
-        uBit.display.image.setPixelValue(xPos - 1, 4, 0);
-    } else if(direction == 0) {
-        uBit.display.image.setPixelValue(xPos + 1, 4, 0);
-    }
-    
-    checkCollision();
-    uBit.display.image.setPixelValue(xPos, 4, 255);
-}
-void displayObs(){
-    uBit.display.image.setPixelValue(obstacleX, y, 0);
-    obstacleX = uBit.random(5);
-
-    for (y = 0; y  < 5; y++){ // descends the obstacles based on y value
-        uBit.display.image.setPixelValue(obstacleX, y, 255);
-        if (obstacleX > 0)
-        {
-            uBit.display.image.setPixelValue(obstacleX - 1, y, 255); 
-        }
-        if (y > 0)
-        {
-            uBit.display.image.setPixelValue(obstacleX, y - 1, 0);
-        }
-        if (obstacleX > 0 && y > 0)
-        {
-            uBit.display.image.setPixelValue(obstacleX - 1, y - 1, 0);
-        }
-        if (score > 0)
-        {
-            uBit.sleep(500 - score);
-        }else if (score >= 500)
-        {
-            uBit.sleep(0);
-        }else{
-            uBit.sleep(500);
-        }
-        checkCollision();
-        displayPlayerLocation();
-    }
-    y = 4;
-    uBit.display.image.setPixelValue(obstacleX, y, 0);
-    uBit.display.image.setPixelValue(obstacleX - 1, y, 0);    
-    score += 5;
-}
-
-
-
-
-int main(){
-    uBit.init();
-    while(gameOver == false){
-        displayObs();
-    }
-    uBit.display.scroll("Game Over, Score: ");
-    uBit.display.scroll(score);
-}
-
-
-