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: main.cpp
- Revision:
- 14:885915260e25
- Parent:
- 13:f4de03202477
- Child:
- 15:8fbbdefbe720
--- a/main.cpp Sun Mar 24 17:53:25 2019 +0000
+++ b/main.cpp Sun Mar 31 13:55:51 2019 +0000
@@ -20,59 +20,58 @@
Ticker ticker;
Gamepad gamepad;
+Rasturizer renderer;
std::vector<Cube> cubeVector;
std::vector<Face> faceVector;
+bool playing = true;
+
+void resetScreen(){
+ //renderer.normalMode();
+ playing = true;
+}
int main()
{
int score = 0;
gamepad.init();
- Rasturizer renderer;
- for(int i = 0; i < 1; i++){
+ for(int i = 0; i < 7; i++){
Cube cube(rand()%80-40,0,30+ i*20,5);
cubeVector.push_back(cube);
}
while(1) {
- score++;
+
Vector2D coord = gamepad.get_coord();
renderer.clear();
- renderer.drawHorizon(coord.x/15);
- bool rotate1 = false;
- if(gamepad.check_event(Gamepad::B_PRESSED) == true){
- Cube cube(rand()%80-40,0,30,5);
- cubeVector.push_back(cube);
+
+ if(playing){
+ score++;
}
- bool rotate2 = false;
- if(gamepad.check_event(Gamepad::X_PRESSED) == true){
- rotate2 = true;
- }
-
+
+ renderer.drawHorizon(coord.x/15);
for (int c = 0; c< cubeVector.size(); c++)
{
- if(rotate1){
- cubeVector[c].rotateZ(0.2);
- }
- if(rotate2){
- cubeVector[c].rotateZ(-0.2);
+ if(playing){
+ cubeVector[c].translate(-coord.x*1.4,0,-3);
}
for (int i = 0; i < 6; i++){
faceVector.push_back(cubeVector[c].getFace(i));
}
- cubeVector[c].translate(-coord.x*2,0,coord.y*2);
-
if (cubeVector[c].despawn()){
cubeVector.erase(cubeVector.begin() + c);
- Cube cube(rand()%160-80,0,90,5);
+ Cube cube(rand()%80-40,0,90,5);
cubeVector.push_back(cube);
}
if (cubeVector[c].tooClose()){
+ cubeVector.erase(cubeVector.begin() + c);
+ playing = false;
+ //renderer.invertMode();
score = 0;
+ ticker.attach(&resetScreen,0.1);
+ Cube cube(rand()%80-40,0,90,5);
+ cubeVector.push_back(cube);
}
}
-
-
-
for (int f = 0; f< faceVector.size(); f++){
for (int f2 = 0; f2< faceVector.size(); f2++){
if(faceVector[f2].getAvgZ() < faceVector[f2+1].getAvgZ()){
@@ -89,11 +88,17 @@
//wait_ms(1000/1);
}
- //char buf[10];
- //sprintf(buf, "%d", score);
- //renderer.print(buf);
+ char buf[10];
+ sprintf(buf, "%d", score);
+ renderer.print(buf);
+ memset(buf, 0, sizeof buf);
renderer.refresh();
faceVector.clear();
+
+
+
+
+
// refresh the LCD so the pixels appear
// this gives a refresh rate of 10 frames per second