int main () { srand(time(NULL)); FsOpenWindow(0,0,600, 800,1); glClearColor(0, 0, 0, 1); glShadeModel(GL_SMOOTH); glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); textureInit(); WeaponUpgrade::LoadTexture("pic/red.png", "pic/green.png", "pic/blue.png"); Plane *plane; plane = new WeaponUpgrade(); bool running = true; while(running) { glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT); FsPollDevice(); int key=FsInkey(); int lb, mb, rb, mx, my; int mouse = FsGetMouseEvent(lb, mb, rb, mx, my); if(FSKEY_ESC==key) { running=false; } plane->Draw(); plane->Move(1.0); if (((Prize *)plane)->Dead()) { delete plane; plane = new WeaponUpgrade(); } FsSwapBuffers(); FsSleep(25); } return 0; }
std::string Board::Timed() { std::string rv; In(); for (std::set<Plane *>::iterator it = planesIn.begin(); it != planesIn.end();) { Plane *plane = *it; int n = plane->GetDestination(); bool atFix; if (n >= 10) { navAids[n-10]->At(*plane); atFix = airports[n-10]->At(*plane); if (atFix) { if (plane->GetHeading() == airports[n-10]->GetHeading() ^ 4) { it = planesIn.erase(it); planesDone.insert(plane); continue; } } } else { atFix = fixes[n]->At(*plane); } if (plane->GetAltitude() == 0) { bool at = false; int x, y; int x1, y1; plane->GetPosition(x, y); airports[0]->GetPosition(x1,y1); if (x == x1 && y == y1) at = true; airports[1]->GetPosition(x1,y1); if (x == x1 && y == y1) at = true; if (at) { rv = "Skimmed airport without landing!"; } } if (plane->Move(time)) { if (atFix && plane->OffBoard()) { it = planesIn.erase(it); planesDone.insert(plane); continue; } else if (plane->OffBoard()) { // game over, exit in wrong place if (plane->GetAltitude() < 5) rv = std::string(plane->GetName()) + " left control area at wrong altitude"; else { if ((plane->GetDestination() < 10 && plane->GetHeading() != (fixes[plane->GetDestination()]->GetHeading() ^ 4)) || (plane->GetDestination() >9 && plane->GetHeading() != (airports[plane->GetDestination()-10]->GetHeading() ^ 4))) rv = std::string(plane->GetName()) + " left control area at wrong heading"; else rv = std::string(plane->GetName()) + " left control area at wrong place"; } } } ++it; } for (std::set<Plane *>::iterator it = planesDisplay.begin(); it != planesDisplay.end();) { Plane *plane = *it; if (plane->GetStartTime() <= time) { it = planesDisplay.erase(it); planesIn.insert(plane); continue; } ++it; } if (rv == "") { for (std::set<Plane *>::iterator it1 = planesIn.begin(); rv == "" && it1 != planesIn.end(); ++it1) { Plane *left = *it1; for (std::set<Plane *>::iterator it2 = it1; rv == "" && it2 != planesIn.end(); ++it2) { Plane *right = *it2; if (it1 != it2) { if (left->GetAltitude() == right->GetAltitude()) { int x,y; right->GetPosition(x, y); if (left->dist(x, y) < 4) rv = std::string("Conflict between ") + left->GetName() + " and " + right->GetName(); } } } } } if (rv == "") { for (std::set<Plane *>::iterator it = planesIn.begin(); rv == "" && it != planesIn.end(); ++it) { Plane *plane = *it; if (plane->GetFuel() < 0) { rv = std::string(plane->GetName()) + " out of fuel!"; } } } // game over, they win! if (rv == "" && planesIn.size() == 0 && planesOut.size() ==0 && planesDisplay.size() == 0) rv = "You Won!"; // game over, timeout if (rv == "" && ++time >= maxTime) rv = "Time is up!"; return rv; }
int main(){ Vector2 startPosition(300, 500); Vector2 startDirection(0, -1); /* This list is used to store all user emmitted active missiles */ MissileList enemy2Missiles; MissileList playerMissiles; /* Create the thunder */ Thunder thunder(startPosition, startDirection); thunder.setVelocity(5); thunder.SwitchWeapon(BULLET, playerMissiles); Plane *player; player = &thunder; /* Create the boss */ LazerEnemy enemy2(Vector2(300, 0), Vector2(0,1)); enemy2.Init(enemy2Missiles); enemy2.setVelocity(15); Plane *enemy; enemy = &enemy2; FsOpenWindow(0,0,WINDOW_WID,WINDOW_HEI,1); glClearColor(0.1, 0.1, 0.1, 1); bool running = true; int i = 0; int cntDown = 0; while(running) { glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT); FsPollDevice(); int key=FsInkey(); int lb, mb, rb, mx, my; int mouse = FsGetMouseEvent(lb, mb, rb, mx, my); if(FSKEY_ESC==key) { running=false; break; } else if (FSKEY_UP == key) { /* UP for power up */ ((Thunder *)player)->PowerUp(playerMissiles); } if (FSMOUSEEVENT_RBUTTONDOWN == mouse) { /* Right click for switch between 3 types of weapons */ i = (i+1) % 3; ((Thunder *)player)->SwitchWeapon((MissileType)i, playerMissiles); } /* Thunder: shoot and cool down weapon. */ player->Shoot(mouse, playerMissiles); player->CoolDown(); /* Thunder: move and draw. */ player->Move(1.0); player->Draw(); /* Draw the enemy */ enemy->Aim(player); printf("before move\n"); enemy->Move(0.4); printf("after move\n"); enemy->Draw(); /* Enemy fire */ ((LazerEnemy *)enemy)->Shoot(enemy2Missiles); enemy->CoolDown(); if (enemy->CheckHit(playerMissiles) == 1) { ((LazerEnemy *)enemy)->Disappear(enemy2Missiles); cntDown = 100; } /* Stay for a while after boss die */ if (cntDown > 0) { cntDown--; if (cntDown == 0) running = false; } /* traverse the missiles list, move missile */ MissileNode *node; node = enemy2Missiles.getFront(); while(node) { node->dat->Move(1.0); if (!node->dat->CheckInWindow()) { node = enemy2Missiles.Delete(node); } else { node = node->next; } } node = playerMissiles.getFront(); while(node) { node->dat->Move(1.0); if (!node->dat->CheckInWindow()) { node = playerMissiles.Delete(node); } else { node = node->next; } } FOR_EACH(node, enemy2Missiles) { node->dat->Draw(); } FOR_EACH(node, playerMissiles) { node->dat->Draw(); } PrintPower(((LazerEnemy *)enemy)->getLife()); FsSwapBuffers(); FsSleep(25); } return 0; }