jj
main.cpp
- Committer:
- schizzlewizzle
- Date:
- 2019-02-04
- Revision:
- 0:f7377a7aa985
File content as of revision 0:f7377a7aa985:
#include "MicroBit.h" int pLocationX; int pLocationY; int xPos = 4; bool gameOver = false; int y = 0; int obstacleX = 0; int score = 0; int playX; MicroBit uBit; int getXPos(){ playX = uBit.accelerometer.getX(); if(playX > 0){ xPos++; }else{ xPos--; } } void checkCollision(){ //if (xPos == obstacleX || xPos == obstacleX - 1 && y == 4){ // gameOver = true; //} gameOver = false; } void displayPlayerLocation(){ getXPos(); if( xPos <= 4) { uBit.display.image.setPixelValue(xPos - 1, 4, 0); } if(xPos >= 0) { uBit.display.image.setPixelValue(xPos + 1, 4, 0); } if (xPos < 0){ xPos = 0; } else if(xPos > 4) { xPos = 4; } checkCollision(); uBit.display.image.setPixelValue(xPos, 4, 255); } void displayObs(){ obstacleX = uBit.random(4); for (y = 1; y >= 4; y++){ 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(); uBit.display.image.setPixelValue(obstacleX, y, 0); if (obstacleX > 0){ uBit.display.image.setPixelValue(obstacleX - 1, y, 0); } y = 0; score += 5; } int main(){ uBit.init(); while(gameOver == false){ displayObs(); } uBit.display.scroll("Gsme Over, Score: "); uBit.display.scroll(score); } /* void drawTheDot(){ int pointX = uBit.random(4); int pointY = uBit.random(4); uBit.display.image.setPixelValue(pointX, pointY, 255); } int main() { uBit.init(); //int pointX = uBit.random(4); // int pointY = uBit.random(4); // uBit.display.scroll("Test"); // uBit.display.image.setPixelValue(pointX, pointY, 255); drawTheDot(); release_fiber(); // uBit.display.image.setPixelValue(2,2, 255); } */