Beispiel #1
0
void sv::ObstacleManager::Update(ulong deltaTime)
{
	Iterator iter = First();
	while(iter)
	{
		Obstacle* obstacle = Get(iter);
		iter = Next(iter);

		obstacle->Update(deltaTime);
		if( obstacle->IsEdge() )
			HandleCollision(obstacle);
		if( obstacle->GetPos() == Grid::InvalidPos )
			DeleteObstacle(obstacle);
	}

	UpdateLevel(deltaTime);
}
Beispiel #2
0
void ObstacleManager::Update(float dt)
{
    if (spawnTrashCan)
    {
        Obstacle *obstacleObj = new Obstacle();
        obstacleObj->initWithType(trashCan , 1);
        allObstacles->addObject(obstacleObj);
        this->addChild(obstacleObj , 2);
        spawnTrashCan = false;
    }
    
    if (spawnCrow)
    {
        Obstacle *obstacleObj = new Obstacle();
        obstacleObj->initWithType(crow , 1);
        allObstacles->addObject(obstacleObj);
        this->addChild(obstacleObj , 2);
        spawnCrow = false;
    }
    
    if (spawnObstaclePattern && !destroyAll)
    {
        int pattern = 1;
        
        //CCLog("Background is : %d" , currentBg);
        if (currentBg == jungleBg)
        {
            pattern = arc4random() % 2;
            pattern = clampf(pattern , 0, 1 );
            
            //CCLog("Jungle Pattern : %d" , pattern + 1);
            //CCLog("Jungle Pattern is: %s" , allObstacleChunks[pattern].obstaclePattern.c_str());
            
            GenerateObstaclePattern(jungleObstacles[pattern].obstaclePattern);
            currentPatternDistance = jungleObstacles[pattern].patternDistance;
        }
        else
        {
            
            pattern = arc4random() % EASY_CHUNK_COUNT ;
            pattern = clampf(pattern , 0, EASY_CHUNK_COUNT);
            
            //pattern = 5;
            //pattern = 4;
            //CCLog("Pattern : %d" , pattern + 1);
            //CCLog("Pattern is: %s" , allObstacleChunks[pattern].obstaclePattern.c_str());
            
            GenerateObstaclePattern(allObstacleChunks[pattern].obstaclePattern);
            currentPatternDistance = allObstacleChunks[pattern].patternDistance;
        }
        
        patternStartDistance = currentDistance;
        
        spawnObstaclePattern = false;
    }
    
    for (unsigned int i = 0 ; i < allObstacles->count() ; i++)
    {
        Obstacle *obstacleObj = (Obstacle*)allObstacles->objectAtIndex(i);
        obstacleObj->Update(dt);
        
        if (obstacleObj->GetRemoveMe())
        {
            obstaclesToDelete->addObject(obstacleObj);
        }
    }
    
    for (unsigned int i = 0 ; i < obstaclesToDelete->count() ; i++)
    {
        Obstacle *obstacleObj = (Obstacle*)obstaclesToDelete->objectAtIndex(i);
        allObstacles->removeObject(obstacleObj);
        this->removeChild(obstacleObj, false);
        obstacleObj->release();
        obstacleObj = NULL;
    }
    obstaclesToDelete->removeAllObjects();
}