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:
- 15:8fbbdefbe720
- Parent:
- 14:885915260e25
- Child:
- 18:8256546a3cbf
--- a/main.cpp Sun Mar 31 13:55:51 2019 +0000
+++ b/main.cpp Sun Mar 31 14:56:55 2019 +0000
@@ -9,99 +9,13 @@
*/
#include "mbed.h"
-#include <vector>
-#ifndef FACE_H
-#define FACE_H
-#include "Face.h"
-#endif
-#include "Rasturizer.h"
-#include "Cube.h"
-#include "Gamepad.h"
+#include "Game.h"
-Ticker ticker;
-Gamepad gamepad;
-Rasturizer renderer;
-std::vector<Cube> cubeVector;
-std::vector<Face> faceVector;
-
-bool playing = true;
-
-void resetScreen(){
- //renderer.normalMode();
- playing = true;
-}
+Serial pc(USBTX, USBRX); // tx, rx
int main()
{
- int score = 0;
- gamepad.init();
- for(int i = 0; i < 7; i++){
- Cube cube(rand()%80-40,0,30+ i*20,5);
- cubeVector.push_back(cube);
- }
- while(1) {
-
- Vector2D coord = gamepad.get_coord();
- renderer.clear();
-
- if(playing){
- score++;
- }
-
- renderer.drawHorizon(coord.x/15);
- for (int c = 0; c< cubeVector.size(); c++)
- {
- 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));
- }
- if (cubeVector[c].despawn()){
- cubeVector.erase(cubeVector.begin() + c);
- 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()){
- Face temp = faceVector[f2+1];
- faceVector[f2+1] = faceVector[f2];
- faceVector[f2] = temp;
- }
- }
- }
-
- for (int f = 0; f< faceVector.size() ; f++){
- //pc.printf("%f\n", faceVector[f].getAvgZ());
- renderer.drawFace(faceVector[f], coord.x/15);
- //wait_ms(1000/1);
-
- }
- 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
-
- wait_ms(1000/30);
- }
+ pc.printf("Hello World!\n");
+ Game game;
+ game.run();
}