Пример #1
0
CCActionInterval* CCCardinalSplineBy::reverse()
{
    CCPointArray *copyConfig = (CCPointArray*)m_pPoints->copy();
	
	//
	// convert "absolutes" to "diffs"
	//
    CCPoint p = copyConfig->getControlPointAtIndex(0);
    for (unsigned int i = 1; i < copyConfig->count(); ++i)
    {
        CCPoint current = copyConfig->getControlPointAtIndex(i);
        CCPoint diff = ccpSub(current, p);
        copyConfig->replaceControlPoint(diff, i);
        
        p = current;
    }
	
	
	// convert to "diffs" to "reverse absolute"
	
    CCPointArray *pReverse = copyConfig->reverse();
    copyConfig->release();
	
	// 1st element (which should be 0,0) should be here too
    
    p = pReverse->getControlPointAtIndex(pReverse->count()-1);
    pReverse->removeControlPointAtIndex(pReverse->count()-1);
    
    p = ccpNeg(p);
    pReverse->insertControlPoint(p, 0);
    
    for (unsigned int i = 1; i < pReverse->count(); ++i)
    {
        CCPoint current = pReverse->getControlPointAtIndex(i);
        current = ccpNeg(current);
        CCPoint abs = ccpAdd(current, p);
        pReverse->replaceControlPoint(abs, i);
        
        p = abs;
    }
	
    return CCCardinalSplineBy::create(m_fDuration, pReverse, m_fTension);
}
Пример #2
0
// Breakable(破壊可能)のタイルを赤にする
void Game::setTileEffect(CCPoint position)
{
    // stage and area
    _hud->setStageLabel(1, 1);
    _hud->setLifeLabel(1);
    
    CCPoint tileCoord = this->tileCoordForPosition(position);
    // キャラクターの上下左右の座標
    CCPointArray *pointArray = CCPointArray::create(4);
    pointArray->addControlPoint(ccp(0,1));
    pointArray->addControlPoint(ccp(-1,0));
    pointArray->addControlPoint(ccp(1,0));
    pointArray->addControlPoint(ccp(0,-1));
    
    for(int i = 0; i < pointArray->count(); i++){
        CCPoint point = pointArray->getControlPointAtIndex(i);
        //CCLog("(%f,%f)", point.x, point.y);
            
        CCPoint tmpTileCoord = ccp(tileCoord.x + point.x, tileCoord.y + point.y);
        if(tmpTileCoord.x < 0 || tmpTileCoord.x > _tileMap->getMapSize().width -1 ||
           tmpTileCoord.y < 0 || tmpTileCoord.y > _tileMap->getMapSize().height - 1)
        {
            continue;
        }

        //CCLog("(%f,%f)", tmpTileCoord.x, tmpTileCoord.y);
        //CCLog("TileX %f, TileY %f", _tileMap->getMapSize().width, _tileMap->getMapSize().height);
        
        int tileGid = _meta->tileGIDAt(tmpTileCoord);
        
        if (tileGid) {
            CCDictionary *properties = _tileMap->propertiesForGID(tileGid);
            if (properties) {
                // obstacle
                CCString *collision = new CCString();
                // Breakableを赤
                *collision = *properties->valueForKey("Breakable");
            
                if (collision && (collision->compare("True") == 0)) {
                    CCSprite *sprite = _background->tileAt(tmpTileCoord);
                    //sprite->setTag(TAPPABLE);
                    // red
                    sprite->setColor(ccRED);
                }
            }
        }
    }
    
    // 白に戻す
    // まず詰める
    /*
      ◯は赤なので変化させない
      |6,0|6,1|6,2|6,3|6,4|6,5|6,6|
      |5,0|5,1|5,2|5,3|5,4|5,5|5,6|
      |4,0|4,1|4,2|◯4,3|4,4|4,5|4,6|
      |3,0|3,1|◯3,2|3,3|◯3,4|3,5|3,6|
      |2,0|2,1|2,2|◯2,3|2,4|2,5|2,6|
      |1,0|1,1|1,2|1,3|1,4|1,5|1,6|
      |0,0|0,1|0,2|0,3|0,4|0,5|0,6|
    */
    CCPointArray *revertPointArray = CCPointArray::create(255);
    for (int i = 0; i < 7; i++) {
        for (int j = 0; j < 7; j++) {
            if((i == 3 && j == 2) || (i == 3 && j == 4) ||
               (i == 2 && j == 3) || (i == 4 && j == 3)
            )
            {
                continue;
            }
            revertPointArray->addControlPoint(ccp(-3 + j, -3 + i));
        }
    }

    // 詰めたものから適用
    for(int i = 0; i < revertPointArray->count(); i++) {
        CCPoint point = revertPointArray->getControlPointAtIndex(i);
        //CCLog("(%f,%f)", point.x, point.y);
        
        CCPoint tmpTileCoord = ccp(tileCoord.x + point.x, tileCoord.y + point.y);
        
        // 画面端はエラーになるので適用させない
        if(tmpTileCoord.x < 0 || tmpTileCoord.x > _tileMap->getMapSize().width - 1||
           tmpTileCoord.y < 0 || tmpTileCoord.y > _tileMap->getMapSize().height - 1)
        {
            continue;
        }
        
        //CCLog("(%f,%f)", tmpTileCoord.x, tmpTileCoord.y);
        
        int tileGid = _meta->tileGIDAt(tmpTileCoord);
        
        if (tileGid) {
            CCDictionary *properties = _tileMap->propertiesForGID(tileGid);
            if (properties) {
                // obstacle
                CCString *collision = new CCString();
                // Breakableのみ戻す
                *collision = *properties->valueForKey("Breakable");
                
                if (collision && (collision->compare("True") == 0)) {
                    CCSprite *sprite = _background->tileAt(tmpTileCoord);
                    // 白で塗る
                    sprite->setColor(ccWHITE);
                    //sprite->setTag(NOT_TAPPABLE);
                }
            }
        }
    }
}