Exemplo n.º 1
0
void Architecture::update(b2Vec2 vTarget)
{
	list<Zombie*>::iterator it;

	for(it = zombieManager->zombies.begin(); it != zombieManager->zombies.end();it++)
	{
		Zombie* z = *it;

		int mark = 1;

		if(z->zDirection == Zombie::left)
			mark = -1;

		if(z->getPositionWithCocos().x < getPosition().x - getWidth()*0.5 - 0.001)
		{
			z->directionChange(Zombie::right);
			mark = 1;
		}
		else if(z->getPositionWithCocos().x > getPosition().x + getWidth()*0.5 + 0.001)
		{
			z->directionChange(Zombie::left);
			mark = -1;
		}
		b2Vec2 moveVec = b2Vec2(z->speed*mark/PTM_RATIO,0);

		z->updateMoveDelta(moveVec);
	}
	
	zombieManager->update(Timer::getDt(),vTarget);

	for(int i=0;i<components.size();i++)
	{
		if(NULL != ((UserDataInBody*)components[i]->getBody()->GetUserData())->mSprite)
		{
			CCSprite* spr = ((UserDataInBody*)components[i]->getBody()->GetUserData())->mSprite;

			float x = components[i]->getBody()->GetPosition().x;
			float y = components[i]->getBody()->GetPosition().y;

			spr->setPosition(ccp(x*PTM_RATIO,y*PTM_RATIO));
			spr->setRotation(-1*CC_RADIANS_TO_DEGREES(components[i]->getBody()->GetAngle()));
		}
	}
}
Exemplo n.º 2
0
void ZombieManager::walkAlongGround(GroundManager* gm)
{
	list<Zombie*>::iterator it;

	for(it = zombies.begin();it!=zombies.end();it++)
	{
		Zombie* z = (*it);
		CCPoint moveDelta;
		int mark = 1;

		if(z->zDirection == Zombie::left)
			mark = -1;
		else
			mark = 1;

		moveDelta = gm->getMoveVecFromGround(z->getPositionWithCocos().x,z->speed*mark);

		z->updateMoveDelta(b2Vec2(moveDelta.x/PTM_RATIO,moveDelta.y/PTM_RATIO));
	}
}