Esempio n. 1
0
void ObstacleManager::GenerateObstaclePattern(std::string patternArray)
{
    for (int j = 0 ; j < ARRAY_X_LIMIT1 ; j++)
    {
        if (patternArray[j] == 'T') //trashcan
        {
            Obstacle *obstacleObj = new Obstacle();
            obstacleObj->initWithType(trashCan , j);
            allObstacles->addObject(obstacleObj);
            this->addChild(obstacleObj , 2);
        }
        else if (patternArray[j] == 'L') //Letterbox
        {
            Obstacle *obstacleObj = new Obstacle();
            obstacleObj->initWithType(letterBox , j);
            allObstacles->addObject(obstacleObj);
            this->addChild(obstacleObj , 2);
        }
        else if (patternArray[j] == 'C') //ChopTree
        {
            Obstacle *obstacleObj = new Obstacle();
            obstacleObj->initWithType(chopTree , j);
            allObstacles->addObject(obstacleObj);
            this->addChild(obstacleObj , 2);
        }
        else if (patternArray[j] == 'B') //Bicycle
        {
            Obstacle *obstacleObj = new Obstacle();
            obstacleObj->initWithType(cycle , j);
            allObstacles->addObject(obstacleObj);
            this->addChild(obstacleObj , 2);
        }
        else if (patternArray[j] == 'H') //Hydrant
        {
            Obstacle *obstacleObj = new Obstacle();
            obstacleObj->initWithType(hydrant , j);
            allObstacles->addObject(obstacleObj);
            this->addChild(obstacleObj , 2);
        }
        else if (patternArray[j] == 'D') //Tree Log
        {
            Obstacle *obstacleObj = new Obstacle();
            obstacleObj->initWithType(treeLog , j);
            allObstacles->addObject(obstacleObj);
            this->addChild(obstacleObj , 2);
        }
        else if (patternArray[j] == 'R') //crow
        {
            Obstacle *obstacleObj = new Obstacle();
            obstacleObj->initWithType(crow , j);
            allObstacles->addObject(obstacleObj);
            this->addChild(obstacleObj , 2);
        }
        else if (patternArray[j] == 'G') // coins
        {
            spawnCoinPattern = true;
        }
    }
}
Esempio n. 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();
}