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.
Dependencies: mbed
Diff: Game/Game.cpp
- Revision:
- 22:236319885874
- Parent:
- 21:6b5d2d75e083
- Child:
- 25:3995271e411c
--- a/Game/Game.cpp Tue Apr 02 17:40:59 2019 +0000 +++ b/Game/Game.cpp Wed Apr 03 15:11:12 2019 +0000 @@ -1,14 +1,12 @@ #include "Game.h" - - Game::Game(){ - noOfCubes = 18; + noOfCubes = 25; homeSelection = 0; gamepad.init(); renderer.init(); for(int i = 0; i < noOfCubes; i++){ - cubeArray[i].translate(rand()%100-50,0,20+ i*10); + cubeArray[i].translate(rand()%250-125,0,20+ i*10); } } @@ -16,39 +14,39 @@ score = 0; selection = true; playing = true; - //ticker.attach(this, &Game::addScore, 0.1); + while(1) { - Vector2D coord = gamepad.get_coord(); renderer.clear(); + coord = gamepad.get_coord(); + renderer.drawHorizon(coord.x/15); + for (int c = 0; c< noOfCubes; c++){ if(playing){ if(score < 2000) - cubeArray[c].translate(-coord.x*1.4f,0,-2.5f-(float)score/500); + cubeArray[c].translate(-coord.x*1.4f,0,-1-(float)score/1000); else{ - cubeArray[c].translate(-coord.x*1.4f,0,-4.5f); + cubeArray[c].translate(-coord.x*1.4f,0,-3); } } else{ coord.x = 0; - coord.y = 0; } for (int i = 0; i < 6; i++){ faceArray[c*6 + i] = cubeArray[c].getFace(i); } if (cubeArray[c].despawn()){ cubeArray[c].resetPos(); - cubeArray[c].translate(rand()%180-90,0,140); + cubeArray[c].translate(rand()%250-125,0,140); } if (cubeArray[c].tooClose()){ playing = false; - //ticker.detach(); cubeArray[c].resetPos(); - cubeArray[c].translate(rand()%180-90,0,140); + cubeArray[c].translate(rand()%250-125,0,140); } } - renderer.drawAllFaces(faceArray, noOfCubes, coord.x);//faceArray, noOfCubes, coord.x); + renderer.drawAllFaces(faceArray, noOfCubes, coord.x); if(!playing){ deathScreen(); @@ -56,15 +54,17 @@ break; } } + else{ + addScore(); + } char buf[5]; - sprintf(buf, "%d", score); + sprintf(buf, "%d", score/3); renderer.print(buf, 0, 0); memset(buf, 0, sizeof buf); renderer.refresh(); - - wait_ms(1000/30); + wait_ms(1000/60); } } @@ -75,6 +75,7 @@ void Game::resetScore(){ score = 0; } + bool Game::deathButtonSelections(){ if(gamepad.check_event(Gamepad::Y_PRESSED) == true){ selection = true; @@ -86,7 +87,6 @@ playing = true; score = 0; resetScore(); - //ticker.attach(this, &Game::addScore, 0.5); } else if(selection == false && gamepad.check_event(Gamepad::B_PRESSED) == true){ resetScore(); @@ -120,7 +120,7 @@ homeButtonSelections(); renderer.drawHomeScreen(homeSelection); renderer.refresh(); - wait_ms(1000/30); + wait_ms(1000/60); } } \ No newline at end of file