World In the Balance
Dependencies: mbed 4DGL-uLCD-SE PinDetect
main.cpp
00001 #include "mbed.h" 00002 #include "WITB.h" 00003 00004 int main() { 00005 srand(time(0)); 00006 EarthSS A; 00007 A.setBaud(); 00008 A.draw(); 00009 GameTimer B; 00010 B.draw(); 00011 00012 ScreenObject * ActiveAsteroids[] = {new ConcreteAsteroid1(), new ConcreteAsteroid2(), new ConcreteAsteroid3(), new ConcreteAsteroid4()}; 00013 for (int i = 0; i < 4; i++) 00014 { 00015 (*ActiveAsteroids[i]).setYPos(10); 00016 (*ActiveAsteroids[i]).setXPos(rand() % 110); 00017 (*ActiveAsteroids[i]).setdx(rand()%5 + 3); 00018 (*ActiveAsteroids[i]).setdy(rand()%10 - 5); 00019 (*ActiveAsteroids[i]).draw(); 00020 } 00021 00022 double x = 0, y = 0, z = 0; 00023 00024 MMA8452 acc(p28, p27, 40000); //instantiate an acc object! 00025 00026 //set parameters -- use these and don't change 00027 acc.setBitDepth(MMA8452::BIT_DEPTH_12); 00028 acc.setDynamicRange(MMA8452::DYNAMIC_RANGE_4G); 00029 acc.setDataRate(MMA8452::RATE_100); 00030 00031 00032 00033 while(1) 00034 { 00035 wait(0.1); 00036 clear(); 00037 acc.readXYZGravity(&x,&y,&z); 00038 int dx = floor(12 * x + 1); 00039 A.setdx(dx); 00040 A.update(); 00041 B.update(); 00042 00043 for (int i = 0; i < 4; i++) 00044 { 00045 if ((*ActiveAsteroids[i]).getYPos() > 110) 00046 { 00047 (*ActiveAsteroids[i]).setYPos(10); 00048 (*ActiveAsteroids[i]).setXPos(rand() % 110); 00049 (*ActiveAsteroids[i]).setdx(rand()%5 + 3); 00050 (*ActiveAsteroids[i]).setdy(rand()%10 - 5); 00051 } 00052 (*ActiveAsteroids[i]).update(); 00053 } 00054 for (int i = 0; i < 4; i++) 00055 { 00056 if (overlap(A, (*ActiveAsteroids[i]))) 00057 { 00058 loseGame(A); 00059 break; 00060 } 00061 } 00062 } 00063 }
Generated on Thu Jul 28 2022 04:59:05 by
1.7.2