![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
WITB2
Dependencies: mbed 4DGL-uLCD-SE PinDetect
Diff: main.cpp
- Revision:
- 3:462904d1c1a9
- Parent:
- 2:9ece21082838
- Child:
- 4:d128df681d05
--- a/main.cpp Mon Nov 13 21:49:05 2017 +0000 +++ b/main.cpp Mon Nov 13 22:45:56 2017 +0000 @@ -185,6 +185,7 @@ //pure virtual virtual void draw() = 0; virtual void update() = 0; + virtual bool boundaryCheck() = 0; protected: int x_pos; int y_pos; @@ -220,6 +221,14 @@ } //end else }//end if + + bool boundaryCheck() + { + if(((x_pos == 0) || (x_pos == 126)) || ((y_pos == 0) || (y_pos == 126))) + return true; + else + return false; + } }; @@ -298,7 +307,9 @@ bool boundaryCheck() { if(((x_pos == 0) || (x_pos == 126)) || ((y_pos == 0) || (y_pos == 126))) - return true; + return true; + else + return false; } protected: @@ -342,12 +353,6 @@ time_t timeElapsed = time(0)-startTime; x_pos = x_pos + (deltaX * timeElapsed); y_pos = y_pos + (deltaY * timeElapsed); - - if(boundaryCheck() ) - { - delete this; - Asteroid1(); - } } protected: @@ -383,11 +388,6 @@ time_t timeElapsed = time(0)-startTime; x_pos = x_pos + (deltaX * timeElapsed); y_pos = y_pos + (deltaY * timeElapsed); - - if(boundaryCheck() ) - { - Asteroid2(); - } } protected: @@ -425,11 +425,6 @@ time_t timeElapsed = time(0)-startTime; x_pos = x_pos + (deltaX * timeElapsed); y_pos = y_pos + (deltaY * timeElapsed); - - if(boundaryCheck() ) - { - Asteroid3(); - } } protected: @@ -466,11 +461,6 @@ time_t timeElapsed = time(0)-startTime; x_pos = x_pos + (deltaX * timeElapsed); y_pos = y_pos + (deltaY * timeElapsed); - - if(boundaryCheck() ) - { - Asteroid4(); - } } protected: @@ -488,14 +478,16 @@ uLCD.baudrate(300000); wait(0.2); srand(time(0)); // do this srand call here ONLY... no where else in the code! - //ScreenObject * ActiveAsteroids[NUM_ASTEROIDS]; - SpaceShipEarth ship; //instantiate a SpaceShipEarth object + ScreenObject * ActiveAsteroids[NUM_ASTEROIDS]; + //SpaceShipEarth ship; //instantiate a SpaceShipEarth object Asteroid1 rock1(1); //Asteroid2 rock2(2); //Asteroid3 rock3(3); //Asteroid4 rock4(4); + + ActiveAsteroids[0] = &rock1; //set parameters -- use these and don't change acc.setBitDepth(MMA8452::BIT_DEPTH_12); @@ -504,12 +496,21 @@ while(1) { - ship.update(); + //ship.update(); - ship.draw(); + //ship.draw(); - rock1.update(); - rock1.draw(); + if(ActiveAsteroids[0]->boundaryCheck() == true) + { + //delete ActiveAsteroids[0]; + Asteroid1 newRock; + ActiveAsteroids[0] = &newRock; + ActiveAsteroids[0]->draw(); + } + + ActiveAsteroids[0]->update(); + + ActiveAsteroids[0]->draw(); //rock2.update(); //rock2.draw();