#include #include #include #include #include #include #include "ship.h" #include "obs.h" #include "Planner.h" int main() { window w(600,600,"Asteroid Motion Strategy - Nicholas Lovell and Joel Varney"); obs o; Ship ship (30, 30, 0, 0, 0); Planner RRT; random_source R; list path; float angle, tempx, tempy; bool fire; vector v; float t; int col; point goal (75, 75); int fileNum = 0; char myFile[15]; w.display(); for(int t = 0; t < 20; t++) { o.AddAsteroid (); } for(t=0;;t++) { angle = 0; fire = false; if (path.size () > 0) { v = path.pop (); angle = v[0]; fire = v[1]; } ship.NewPosition (angle, fire, 1); if ((int(t) == 0) || (path.size () == 0) || ((int(goal.xcoord () - 1) <= int(ship.GetPosition ()[0])) && (int(goal.xcoord () + 1) >= int(ship.GetPosition ()[0])) && (int(goal.ycoord () - 1) <= int(ship.GetPosition ()[1])) && (int(goal.ycoord () + 1) >= int(ship.GetPosition ()[1])))) { if (path.size () != 0 || int (t) == 0) { R >> tempx; R >> tempy; tempx *= 100; tempy *= 100; goal = point(tempx, tempy); cout << "(" << goal << ")" << endl; } fileNum = RRT.Plan(goal, path, ship, t, o, w, fileNum); } col = o.InFree (ship.GetPosition()[0], ship.GetPosition()[1], t); w.clear(); w.draw_circle (ship.GetShape(), 1, 3 - col); o.Display (w, t); w.draw_point (goal); if (int(t) % 7 == 0) { sprintf (myFile, "ast%.3d.ps", fileNum); ps_file myps (10, 10, myFile); o.Display (myps, t); myps.draw_circle (ship.GetShape(), 1, 3 - col); myps.draw_point (goal); fileNum++; myps.close (); } for (int abcde=0;abcde<1000000;abcde++); // Wait so that we can // see the animation } return 0; }