void TreeGeneratorApp::update() { screenRotation += (dRotation-screenRotation) / 16.0f; Vec3f centerOfEverything = Vec3f(0,0,0); if(turtles.size()>0){ for(int i=0;i<turtles.size();i++){ centerOfEverything += turtles.at(i).curPos; } } centerOfEverything /= turtles.size(); // console() << "CENTER: " << centerOfEverything.x << ", " << centerOfEverything.y << "." << endl; for(int i=0;i<turtles.size();i++) { turtles.at(i).update(); if(turtles.at(i).forwardVelocity<0.05f && turtles.at(i).forwardVelocity>0.0f){ turtles.at(i).forwardVelocity=0.0f; for(int j=0;j<2;j++){ if(turtles.size()<maxNum){ Turtle newTurtle = Turtle(); newTurtle.setup(turtles.at(i).curPos,centerOfEverything); turtles.push_back(newTurtle); } } } } }
Turtle* Turtle::create() { Turtle *sprite = new Turtle(); if (sprite && sprite->initWithFile("turtle_1.png")){ sprite->setup(); sprite->autorelease(); return sprite; } CC_SAFE_DELETE(sprite); return nullptr; }