Example #1
0
void Game::update(float dt) {
	//clean out out of bounds platforms
	int platCount = platforms.size();
	if(platCount > 0){
		GameObject *obj =  platforms.front();
		b2Vec2  pos = obj->getBody()->GetPosition();
		if(obj->isOffScreen()){
			Light* l = (Light*)obj;
			if(!l->IsTouched()){
				_stats.IncrementMultiplier(1);
				_stats.IncrementScore(10);
			}
			//obj->removeFromParentAndCleanup();
			platforms.erase(platforms.begin());
		}
	}
	_player->updateTrail(dt);
	//It is recommended that a fixed time step is used with Box2D for stability
	//of the simulation, however, we are using a variable time step here.
	//You need to make an informed choice, the following URL is useful
	//http://gafferongames.com/game-physics/fix-your-timestep/
 
	int32 velocityIterations = 8;
	int32 positionIterations = 1;
 
	// Instruct the world to perform a single step of simulation. It is
	// generally best to keep the time step and iterations fixed.
	world->Step(dt, velocityIterations, positionIterations);
	CleanWorld();
	if(move==false){
		spawnrate+=dt;
		if(spawnrate>=1){
			spawnrate=0.5;
			CCDirector::sharedDirector()->getActionManager()->resumeTarget(_boss->getSprite());
			move=true;
		}
	}
	else{
		spawnrate-=dt;
		if((spawnrate<=0)&&(_boss->getSprite()->getPositionY()<winSize.height*0.1+0.5*winSize.height)){//err:doesn't account for change in players height on new platform
			GameObject* test = GameObject::retainedObjectWithSprite(Light::retainedLight());
			test->getSprite()->setPosition(ccp(_boss->getSprite()->getPositionX()+50, _boss->getSprite()->getPositionY()));
			this->addChild(test->getSprite());	
			test->createBox2dObject(world);
			test->getBody()->SetLinearVelocity(b2Vec2(-5.0f, 0.0f));
			test->getBody()->SetType(b2_kinematicBody);
			//test->getSprite()->runAction(CCMoveBy::create( 4 ,ccp(-winSize.width*1.5, 0)));
			spawnrate=0;
			platforms.push_back(test);
			CCDirector::sharedDirector()->getActionManager()->pauseTarget(_boss->getSprite());
			move=false;
			CCLog("%i", _batchNode->getChildrenCount());//err:gameobjects arent autoreleased(coz it doesnt work dunno wtf- cocos releases them too early maybe?) so makesure to release when done - check/confirm memusage with this print
		}
	}
}