WITB2
Dependencies: mbed 4DGL-uLCD-SE PinDetect
Diff: main.cpp
- Revision:
- 4:d128df681d05
- Parent:
- 3:462904d1c1a9
- Child:
- 5:ed52ac77cdf9
--- a/main.cpp Mon Nov 13 22:45:56 2017 +0000 +++ b/main.cpp Tue Nov 14 17:33:09 2017 +0000 @@ -229,6 +229,10 @@ else return false; } + + /* + + */ }; @@ -302,11 +306,16 @@ deltaY = -1*(rand() % 3 + 1); break; } - } + } bool boundaryCheck() { - if(((x_pos == 0) || (x_pos == 126)) || ((y_pos == 0) || (y_pos == 126))) + bool c1 = (deltaX > 1) && (x_pos >= 126); //if moving towards right side of screen + bool c2 = (deltaX < 1) && (x_pos + ASTEROID_WIDTH <= 0); //if moving towards left side of screen + bool c3 = (deltaY > 1) && (y_pos >= 126); //if moving towards bottom of screen + bool c4 = (deltaY < 1) && (y_pos + ASTEROID_HEIGHT <= 0); //if moving towards top of screen + + if(c1 || c2 || c3 || c4) return true; else return false; @@ -479,7 +488,7 @@ 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 + SpaceShipEarth ship; //instantiate a SpaceShipEarth object Asteroid1 rock1(1); @@ -488,6 +497,9 @@ //Asteroid4 rock4(4); ActiveAsteroids[0] = &rock1; + //ActiveAsteroids[1] = &rock2; + //ActiveAsteroids[2] = &rock3; + //ActiveAsteroids[3] = &rock4; //set parameters -- use these and don't change acc.setBitDepth(MMA8452::BIT_DEPTH_12); @@ -496,30 +508,69 @@ while(1) { - //ship.update(); + ship.update(); - //ship.draw(); + ship.draw(); - if(ActiveAsteroids[0]->boundaryCheck() == true) - { - //delete ActiveAsteroids[0]; - Asteroid1 newRock; - ActiveAsteroids[0] = &newRock; - ActiveAsteroids[0]->draw(); - } ActiveAsteroids[0]->update(); + if(ActiveAsteroids[0]->boundaryCheck()) + { + wait(0.2); + delete ActiveAsteroids[0]; + ActiveAsteroids[0] = NULL; + Asteroid1 rock1; + ActiveAsteroids[0] = &rock1; + } + ActiveAsteroids[0]->draw(); - //rock2.update(); - //rock2.draw(); + + /* + ActiveAsteroids[1]->update(); + + if(ActiveAsteroids[1]->boundaryCheck()) + { + wait(0.2); + delete ActiveAsteroids[1]; + ActiveAsteroids[1] = NULL; + Asteroid1 rock2; + ActiveAsteroids[1] = &rock2; + } + + ActiveAsteroids[1]->draw(); + + + ActiveAsteroids[2]->update(); - //rock3.update(); - //rock3.draw(); + if(ActiveAsteroids[2->boundaryCheck()) + { + wait(0.2); + delete ActiveAsteroids[2]; + ActiveAsteroids[2] = NULL; + Asteroid1 rock3; + ActiveAsteroids[2] = &rock3; + } + + ActiveAsteroids[2]->draw(); + + + ActiveAsteroids[3]->update(); - //rock4.update(); - //rock4.draw(); + if(ActiveAsteroids[3]->boundaryCheck()) + { + wait(0.2); + delete ActiveAsteroids[3]; + ActiveAsteroids[3] = NULL; + Asteroid1 rock4; + ActiveAsteroids[3] = &rock4; + } + + + ActiveAsteroids[3]->draw(); + */ + } //end infinite while loop } //end main