//Constructor creates 2 caves, 3 coral reefs and 2 fish //Also creates 4 dynamic arrays to hold pointers to all these objects Model::Model() { time = 0; //Initialize objects cave_ptrs.push_back(new Cave(1, CartPoint(5, 1))); cave_ptrs.push_back(new Cave(2, CartPoint(6, 2))); reef_ptrs.push_back(new CoralReef(1, CartPoint(1, 20))); reef_ptrs.push_back(new CoralReef(2, CartPoint(20, 1))); reef_ptrs.push_back(new CoralReef(3, CartPoint(20, 20))); fish_ptrs.push_back(new Tuna(1, get_Cave_ptr(1), this)); fish_ptrs.push_back(new Tuna(2, get_Cave_ptr(2), this)); fish_ptrs.push_back(new Tuna(3, get_Cave_ptr(2), this)); fish_ptrs.push_back(new Shark(4, this)); fish_ptrs.push_back(new Shark(5, this)); //Put all objects in object_ptrs list and active_ptrs list for (std::list<Cave*>::iterator cave = cave_ptrs.begin(); cave != cave_ptrs.end(); ++cave) object_ptrs.push_back(*cave); for (std::list<CoralReef*>::iterator reef = reef_ptrs.begin(); reef != reef_ptrs.end(); ++reef) object_ptrs.push_back(*reef); for (std::list<Fish*>::iterator fish = fish_ptrs.begin(); fish != fish_ptrs.end(); ++fish) object_ptrs.push_back(*fish); for (std::list<GameObject*>::iterator ob = object_ptrs.begin(); ob != object_ptrs.end(); ++ob) if ((*ob)->get_state() != 'x') active_ptrs.push_back(*ob); //Sharknado only put in active_ptrs list active_ptrs.push_back(Sharknado::getInstance(this)); std::cout << "Model default constructed" << std::endl; }
CartPoint operator+(CartPoint p1, CartVector v1) { double new_x = p1.x + v1.x; double new_y = p1.y + v1.y; return CartPoint(new_x, new_y); };
//Returns a random point (seeded by the model's time) CartPoint Shark::rand_cartpoint(Model* model) { srand(model->time); return CartPoint(rand() % 20, rand() % 20); //return CartPoint(6, 3); }