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:
- 21:6b5d2d75e083
- Parent:
- 20:3ca430241df0
- Child:
- 22:236319885874
--- a/Game/Game.cpp Mon Apr 01 17:11:40 2019 +0000 +++ b/Game/Game.cpp Tue Apr 02 17:40:59 2019 +0000 @@ -1,14 +1,12 @@ #include "Game.h" -Serial pc(USBTX, USBRX); // tx, rx Game::Game(){ - noOfCubes = 10; + noOfCubes = 18; homeSelection = 0; gamepad.init(); renderer.init(); - timer.start(); for(int i = 0; i < noOfCubes; i++){ cubeArray[i].translate(rand()%100-50,0,20+ i*10); } @@ -18,19 +16,17 @@ score = 0; selection = true; playing = true; - timer.reset(); - + //ticker.attach(this, &Game::addScore, 0.1); while(1) { Vector2D coord = gamepad.get_coord(); renderer.clear(); renderer.drawHorizon(coord.x/15); - //pc.printf("a"); for (int c = 0; c< noOfCubes; c++){ if(playing){ - if(score < 1500) - cubeArray[c].translate((float)-coord.x*1.4,0,-2-(float)score/500); + if(score < 2000) + cubeArray[c].translate(-coord.x*1.4f,0,-2.5f-(float)score/500); else{ - cubeArray[c].translate((float)-coord.x*1.4,0,-3.5); + cubeArray[c].translate(-coord.x*1.4f,0,-4.5f); } } else{ @@ -42,21 +38,19 @@ } if (cubeArray[c].despawn()){ cubeArray[c].resetPos(); - cubeArray[c].translate(rand()%100-50,0,90); + cubeArray[c].translate(rand()%180-90,0,140); } if (cubeArray[c].tooClose()){ playing = false; + //ticker.detach(); cubeArray[c].resetPos(); - cubeArray[c].translate(rand()%100-50,0,90); + cubeArray[c].translate(rand()%180-90,0,140); } } renderer.drawAllFaces(faceArray, noOfCubes, coord.x);//faceArray, noOfCubes, coord.x); - if(playing){ - score = timer.read_ms()/200; - } - else{ + if(!playing){ deathScreen(); if(deathButtonSelections()){ break; @@ -70,10 +64,17 @@ memset(buf, 0, sizeof buf); renderer.refresh(); - wait_ms(1000/28); + wait_ms(1000/30); } } +void Game::addScore(){ + score++; +} + +void Game::resetScore(){ + score = 0; +} bool Game::deathButtonSelections(){ if(gamepad.check_event(Gamepad::Y_PRESSED) == true){ selection = true; @@ -84,10 +85,11 @@ if (selection == true && gamepad.check_event(Gamepad::B_PRESSED) == true){ playing = true; score = 0; - timer.reset(); + resetScore(); + //ticker.attach(this, &Game::addScore, 0.5); } else if(selection == false && gamepad.check_event(Gamepad::B_PRESSED) == true){ - timer.reset(); + resetScore(); return true; } return false; @@ -109,7 +111,6 @@ } void Game::deathScreen(){ - //int selection = 1; renderer.drawDeathScreen(selection); } @@ -119,7 +120,7 @@ homeButtonSelections(); renderer.drawHomeScreen(homeSelection); renderer.refresh(); - wait_ms(1000/28); + wait_ms(1000/30); } } \ No newline at end of file