Beispiel #1
0
void TileMapEditTest::updateMap(float dt)
{
    // IMPORTANT
    //   The only limitation is that you cannot change an empty, or assign an empty tile to a tile
    //   The value 0 not rendered so don't assign or change a tile with value 0

    CCTileMapAtlas* tilemap = (CCTileMapAtlas*) getChildByTag(kTagTileMap);
    
    //
    // For example you can iterate over all the tiles
    // using this code, but try to avoid the iteration
    // over all your tiles in every frame. It's very expensive
    //    for(int x=0; x < tilemap.tgaInfo->width; x++) {
    //        for(int y=0; y < tilemap.tgaInfo->height; y++) {
    //            ccColor3B c =[tilemap tileAt:ccg(x,y));
    //            if( c.r != 0 ) {
    //                ////----UXLOG("%d,%d = %d", x,y,c.r);
    //            }
    //        }
    //    }
    
    // NEW since v0.7
    ccColor3B c = tilemap->tileAt(ccg(13,21));        
    c.r++;
    c.r %= 50;
    if( c.r==0)
        c.r=1;
    
    // NEW since v0.7
    tilemap->setTile(c, ccg(13,21) );             
}
Beispiel #2
0
	void CCShakyTiles3D::update(cocos2d::ccTime time)
	{
		int i, j;
	
		for (i = 0; i < m_sGridSize.x; ++i)
		{
			for (j = 0; j < m_sGridSize.y; ++j)
			{
				ccQuad3 coords = originalTile(ccg(i, j));

				// X
				coords.bl.x += ( rand() % (m_nRandrange*2) ) - m_nRandrange;
				coords.br.x += ( rand() % (m_nRandrange*2) ) - m_nRandrange;
				coords.tl.x += ( rand() % (m_nRandrange*2) ) - m_nRandrange;
				coords.tr.x += ( rand() % (m_nRandrange*2) ) - m_nRandrange;

				// Y
				coords.bl.y += ( rand() % (m_nRandrange*2) ) - m_nRandrange;
				coords.br.y += ( rand() % (m_nRandrange*2) ) - m_nRandrange;
				coords.tl.y += ( rand() % (m_nRandrange*2) ) - m_nRandrange;
				coords.tr.y += ( rand() % (m_nRandrange*2) ) - m_nRandrange;

				if (m_bShakeZ)
				{
					coords.bl.z += ( rand() % (m_nRandrange*2) ) - m_nRandrange;
					coords.br.z += ( rand() % (m_nRandrange*2) ) - m_nRandrange;
					coords.tl.z += ( rand() % (m_nRandrange*2) ) - m_nRandrange;
					coords.tr.z += ( rand() % (m_nRandrange*2) ) - m_nRandrange;
				}
							
				setTile(ccg(i, j), coords);
			}
		}
	}
Beispiel #3
0
	void CCJumpTiles3D::update(cocos2d::ccTime time)
	{
		int i, j;

		float sinz =  (sinf((CGFloat)M_PI * time * m_nJumps * 2) * m_fAmplitude * m_fAmplitudeRate );
		float sinz2 = (sinf((CGFloat)M_PI * (time * m_nJumps * 2 + 1)) * m_fAmplitude * m_fAmplitudeRate );

		for( i = 0; i < m_sGridSize.x; i++ )
		{
			for( j = 0; j < m_sGridSize.y; j++ )
			{
				ccQuad3 coords = originalTile(ccg(i, j));

				if ( ((i+j) % 2) == 0 )
				{
					coords.bl.z += sinz;
					coords.br.z += sinz;
					coords.tl.z += sinz;
					coords.tr.z += sinz;
				}
				else
				{
					coords.bl.z += sinz2;
					coords.br.z += sinz2;
					coords.tl.z += sinz2;
					coords.tr.z += sinz2;
				}

				setTile(ccg(i, j), coords);
			}
		}
	}
	/*
	* Update each tick
	* Time is the percentage of the way through the duration
	*/
	void CCPageTurn3D::update(ccTime time)
	{
		float tt = MAX(0, time - 0.25f);
		float deltaAy = (tt * tt * 500);
		float ay = -100 - deltaAy;

		float deltaTheta = - (float) M_PI_2 * sqrtf(time) ;
		float theta = /*0.01f */ + (float) M_PI_2 +deltaTheta;

		float sinTheta = sinf(theta);
		float cosTheta = cosf(theta);

		for (int i = 0; i <= m_sGridSize.x; ++i)
		{
			for (int j = 0; j <= m_sGridSize.y; ++j)
			{
				// Get original vertex
				ccVertex3F p = originalVertex(ccg(i ,j));

				float R = sqrtf((p.x * p.x) + ((p.y - ay) * (p.y - ay)));
				float r = R * sinTheta;
				float alpha = asinf(p.x / R);
				float beta = alpha / sinTheta;
				float cosBeta = cosf(beta);

				// If beta > PI then we've wrapped around the cone
				// Reduce the radius to stop these points interfering with others
				if (beta <= M_PI)
				{
					p.x = (r * sinf(beta));
				}
				else
				{
					// Force X = 0 to stop wrapped
					// points
					p.x = 0;
				}

				p.y = (R + ay - (r * (1 - cosBeta) * sinTheta));

				// We scale z here to avoid the animation being
				// too much bigger than the screen due to perspectve transform
				p.z = (r * (1 - cosBeta) * cosTheta) / 7;// "100" didn't work for

				//	Stop z coord from dropping beneath underlying page in a transition
				// issue #751
				if (p.z < 0.5f)
				{
					p.z = 0.5f;
				}

				// Set new coords
				setVertex(ccg(i, j), p);

			}
		}
	}
	void CCWaves3D::update(ccTime time)
	{
		int i, j;
		for (i = 0; i < m_sGridSize.x + 1; ++i)
		{
			for (j = 0; j < m_sGridSize.y + 1; ++j)
			{
				ccVertex3F v = originalVertex(ccg(i ,j));
				v.z += (sinf((CGFloat)M_PI * time * m_nWaves * 2 + (v.y+v.x) * .01f) * m_fAmplitude * m_fAmplitudeRate);
				CCLog("v.z offset is %f\n", (sinf((CGFloat)M_PI * time * m_nWaves * 2 + (v.y+v.x) * .01f) * m_fAmplitude * m_fAmplitudeRate));
				setVertex(ccg(i, j), v);
			}
		}
	}
	void CCLiquid::update(ccTime time)
	{
		int i, j;

		for (i = 1; i < m_sGridSize.x; ++i)
		{
			for (j = 1; j < m_sGridSize.y; ++j)
			{
				ccVertex3F v = originalVertex(ccg(i, j));
				v.x = (v.x + (sinf(time * (CGFloat)M_PI * m_nWaves * 2 + v.x * .01f) * m_fAmplitude * m_fAmplitudeRate));
				v.y = (v.y + (sinf(time * (CGFloat)M_PI * m_nWaves * 2 + v.y * .01f) * m_fAmplitude * m_fAmplitudeRate));
				setVertex(ccg(i, j), v);
			}
		}
	}
Beispiel #7
0
	void CCShuffleTiles::startWithTarget(CCNode *pTarget)
	{
		CCTiledGrid3DAction::startWithTarget(pTarget);

		if (m_nSeed != -1)
		{
			srand(m_nSeed);
		}

		m_nTilesCount = m_sGridSize.x * m_sGridSize.y;
		m_pTilesOrder = new int[m_nTilesCount];
		int i, j;

		for (i = 0; i < m_nTilesCount; ++i)
		{
			m_pTilesOrder[i] = i;
		}

		shuffle(m_pTilesOrder, m_nTilesCount);

		m_pTiles = (struct Tile *)new Tile[m_nTilesCount];
		Tile *tileArray = (Tile*) m_pTiles;

		for (i = 0; i < m_sGridSize.x; ++i)
		{
			for (j = 0; j < m_sGridSize.y; ++j)
			{
				tileArray->position = ccp((float)i, (float)j);
				tileArray->startPosition = ccp((float)i, (float)j);
				tileArray->delta = getDelta(ccg(i, j));
				++tileArray;
			}
		}
	}
Beispiel #8
0
	static CCActionInterval* actionWithDuration(ccTime t)
	{
		CCTurnOffTiles* fadeout = CCTurnOffTiles::actionWithSeed(25, ccg(48,32) , t);
		CCActionInterval* back = fadeout->reverse();
		CCDelayTime* delay = CCDelayTime::actionWithDuration(0.5f);

		return (CCActionInterval*)(CCSequence::actions(fadeout, delay, back, NULL));
	}
Beispiel #9
0
	static CCActionInterval* actionWithDuration(ccTime t)
	{
		CCFadeOutDownTiles* fadeout = CCFadeOutDownTiles::actionWithSize(ccg(16,12), t);
		CCActionInterval* back = fadeout->reverse();
		CCDelayTime* delay = CCDelayTime::actionWithDuration(0.5f);

		return (CCActionInterval*)(CCSequence::actions(fadeout, delay, back, NULL));
	}
Beispiel #10
0
	static CCActionInterval* actionWithDuration(ccTime t)
	{
		CCShuffleTiles* shuffle = CCShuffleTiles::actionWithSeed(25, ccg(16,12), t);
		CCActionInterval* shuffle_back = shuffle->reverse();
		CCDelayTime* delay = CCDelayTime::actionWithDuration(2);

		return (CCActionInterval*)(CCSequence::actions(shuffle, delay, shuffle_back, NULL));
	}
Beispiel #11
0
    static CCActionInterval* create(float t)
    {
        CCTurnOffTiles* fadeout = CCTurnOffTiles::create(25, ccg(48,32) , t);
        CCActionInterval* back = fadeout->reverse();
        CCDelayTime* delay = CCDelayTime::create(0.5f);

        return (CCActionInterval*)(CCSequence::create(fadeout, delay, back, NULL));
    }
Beispiel #12
0
    static CCActionInterval* create(float t)
    {
        CCFadeOutDownTiles* fadeout = CCFadeOutDownTiles::create(ccg(16,12), t);
        CCActionInterval* back = fadeout->reverse();
        CCDelayTime* delay = CCDelayTime::create(0.5f);

        return (CCActionInterval*)(CCSequence::create(fadeout, delay, back, NULL));
    }
Beispiel #13
0
    static CCActionInterval* create(float t)
    {
        CCShuffleTiles* shuffle = CCShuffleTiles::create(25, ccg(16,12), t);
        CCActionInterval* shuffle_back = shuffle->reverse();
        CCDelayTime* delay = CCDelayTime::create(2);

        return (CCActionInterval*)(CCSequence::create(shuffle, delay, shuffle_back, NULL));
    }
//------------------------------------------------------------------
//
// Effect3
//
//------------------------------------------------------------------
void Effect3::onEnter()
{
	EffectAdvanceTextLayer::onEnter();

	CCNode* bg = getChildByTag(kTagBackground);
	CCNode* target1 = bg->getChildByTag(kTagSprite1);
	CCNode* target2 = bg->getChildByTag(kTagSprite2);	
	
	CCActionInterval* waves = CCWaves::actionWithWaves(5, 20, true, false, ccg(15,10), 5);
	CCActionInterval* shaky = CCShaky3D::actionWithRange(4, false, ccg(15,10), 5);
	
	target1->runAction( CCRepeatForever::actionWithAction( waves ) );
	target2->runAction( CCRepeatForever::actionWithAction( shaky ) );
	
	// moving background. Testing issue #244
	CCActionInterval* move = CCMoveBy::actionWithDuration(3, ccp(200,0) );
	bg->runAction(CCRepeatForever::actionWithAction( (CCActionInterval *)(CCSequence::actions(move, move->reverse(), NULL) ) ) );	
}
Beispiel #15
0
	void CCLens3D::update(ccTime time)
	{
        CC_UNUSED_PARAM(time);
		if (m_bDirty)
		{
			int i, j;
			
			for (i = 0; i < m_sGridSize.x + 1; ++i)
			{
				for (j = 0; j < m_sGridSize.y + 1; ++j)
				{
					ccVertex3F v = originalVertex(ccg(i, j));
					CCPoint vect = ccpSub(m_positionInPixels, ccp(v.x, v.y));
					CGFloat r = ccpLength(vect);
					
					if (r < m_fRadius)
					{
						r = m_fRadius - r;
						CGFloat pre_log = r / m_fRadius;
						if ( pre_log == 0 ) 
						{
							pre_log = 0.001f;
						}

						float l = logf(pre_log) * m_fLensEffect;
						float new_r = expf( l ) * m_fRadius;
						
						if (ccpLength(vect) > 0)
						{
							vect = ccpNormalize(vect);
							CCPoint new_vect = ccpMult(vect, new_r);
							v.z += ccpLength(new_vect) * m_fLensEffect;
						}
					}
					
					setVertex(ccg(i, j), v);
				}
			}
			
			m_bDirty = false;
		}
	}
	void CCShaky3D::update(cocos2d::ccTime time)
	{
		int i, j;
	
		for (i = 0; i < (m_sGridSize.x+1); ++i)
		{
			for (j = 0; j < (m_sGridSize.y+1); ++j)
			{
				ccVertex3F v = originalVertex(ccg(i ,j));
				v.x += (rand() % (m_nRandrange*2)) - m_nRandrange;
				v.y += (rand() % (m_nRandrange*2)) - m_nRandrange;
				if (m_bShakeZ)
				{
					v.z += (rand() % (m_nRandrange*2)) - m_nRandrange;
				}
				
				setVertex(ccg(i, j), v);
			}
		}
	}
	ccGridSize CCShuffleTiles::getDelta(cocos2d::ccGridSize pos)
	{
		CGPoint	pos2;

		int idx = pos.x * m_sGridSize.y + pos.y;

		pos2.x = (float)(m_pTilesOrder[idx] / (int)m_sGridSize.y);
		pos2.y = (float)(m_pTilesOrder[idx] % (int)m_sGridSize.y);

		return ccg((int)(pos2.x - pos.x), (int)(pos2.y - pos.y));
	}
void CCWavesTiles3D::update(ccTime time)
{
    int i, j;

    for( i = 0; i < m_sGridSize.x; i++ )
    {
        for( j = 0; j < m_sGridSize.y; j++ )
        {
            ccQuad3 coords = originalTile(ccg(i, j));

            coords.bl.z = (sinf(time * (CGFloat)M_PI  *m_nWaves * 2 +
                                (coords.bl.y+coords.bl.x) * .01f) * m_fAmplitude * m_fAmplitudeRate );
            coords.br.z	= coords.bl.z;
            coords.tl.z = coords.bl.z;
            coords.tr.z = coords.bl.z;

            setTile(ccg(i, j), coords);
        }
    }
}
ccGridSize CCShuffleTiles::getDelta(const ccGridSize& pos)
{
    CCPoint	pos2;

    unsigned int idx = pos.x * m_sGridSize.y + pos.y;

    pos2.x = (float)(m_pTilesOrder[idx] / (int)m_sGridSize.y);
    pos2.y = (float)(m_pTilesOrder[idx] % (int)m_sGridSize.y);

    return ccg((int)(pos2.x - pos.x), (int)(pos2.y - pos.y));
}
void CCShaky3D::update(float time)
{
    CC_UNUSED_PARAM(time);
    int i, j;

    for (i = 0; i < (m_sGridSize.x+1); ++i)
    {
        for (j = 0; j < (m_sGridSize.y+1); ++j)
        {
            ccVertex3F v = originalVertex(ccg(i ,j));
            v.x += (rand() % (m_nRandrange*2)) - m_nRandrange;
            v.y += (rand() % (m_nRandrange*2)) - m_nRandrange;
            if (m_bShakeZ)
            {
                v.z += (rand() % (m_nRandrange*2)) - m_nRandrange;
            }
            
            setVertex(ccg(i, j), v);
        }
    }
}
Beispiel #21
0
void CCTransitionPageTurn::onEnter()
{
	CCTransitionScene::onEnter();
	// CustomRetina:
	CCSize s;
	if( CC_IS_CUSTOM_RETINA() )
		s = CCDirector::sharedDirector()->getWinSizeInPixels();
	else
		s = CCDirector::sharedDirector()->getWinSize();
	int x,y;
	if( s.width > s.height)
	{
		x=16;
        y=12;
	}
	else
	{
		x=12;
        y=16;
	}

	CCActionInterval *action  = this->actionWithSize(ccg(x,y));

	if(! m_bBack )
	{
		m_pOutScene->runAction
		(
			CCSequence::actions
			(
				action,
				CCCallFunc::actionWithTarget(this, callfunc_selector(CCTransitionScene::finish)),
				CCStopGrid::action(),
				NULL
			)
		);
	}
	else
	{
		// to prevent initial flicker
		m_pInScene->setIsVisible(false);
		m_pInScene->runAction
		(
			CCSequence::actions
			(
			    CCShow::action(),
				action,
				CCCallFunc::actionWithTarget(this, callfunc_selector(CCTransitionScene::finish)),
				CCStopGrid::action(),
				NULL
			)
		);
	}
}
void CCShatteredTiles3D::update(ccTime time)
{
    CC_UNUSED_PARAM(time);
    int i, j;

    if (m_bOnce == false)
    {
        for (i = 0; i < m_sGridSize.x; ++i)
        {
            for (j = 0; j < m_sGridSize.y; ++j)
            {
                ccQuad3 coords = originalTile(ccg(i ,j));

                // X
                coords.bl.x += ( rand() % (m_nRandrange*2) ) - m_nRandrange;
                coords.br.x += ( rand() % (m_nRandrange*2) ) - m_nRandrange;
                coords.tl.x += ( rand() % (m_nRandrange*2) ) - m_nRandrange;
                coords.tr.x += ( rand() % (m_nRandrange*2) ) - m_nRandrange;

                // Y
                coords.bl.y += ( rand() % (m_nRandrange*2) ) - m_nRandrange;
                coords.br.y += ( rand() % (m_nRandrange*2) ) - m_nRandrange;
                coords.tl.y += ( rand() % (m_nRandrange*2) ) - m_nRandrange;
                coords.tr.y += ( rand() % (m_nRandrange*2) ) - m_nRandrange;

                if (m_bShatterZ)
                {
                    coords.bl.z += ( rand() % (m_nRandrange*2) ) - m_nRandrange;
                    coords.br.z += ( rand() % (m_nRandrange*2) ) - m_nRandrange;
                    coords.tl.z += ( rand() % (m_nRandrange*2) ) - m_nRandrange;
                    coords.tr.z += ( rand() % (m_nRandrange*2) ) - m_nRandrange;
                }

                setTile(ccg(i, j), coords);
            }
        }

        m_bOnce = true;
    }
}
void CCSplitRows::update(ccTime time)
{
    int j;

    for (j = 0; j < m_sGridSize.y; ++j)
    {
        ccQuad3 coords = originalTile(ccg(0, j));
        float	direction = 1;

        if ( (j % 2 ) == 0 )
        {
            direction = -1;
        }

        coords.bl.x += direction * m_winSize.width * time;
        coords.br.x += direction * m_winSize.width * time;
        coords.tl.x += direction * m_winSize.width * time;
        coords.tr.x += direction * m_winSize.width * time;

        setTile(ccg(0, j), coords);
    }
}
void CCSplitCols::update(ccTime time)
{
    int i;

    for (i = 0; i < m_sGridSize.x; ++i)
    {
        ccQuad3 coords = originalTile(ccg(i, 0));
        float	direction = 1;

        if ( (i % 2 ) == 0 )
        {
            direction = -1;
        }

        coords.bl.y += direction * m_winSize.height * time;
        coords.br.y += direction * m_winSize.height * time;
        coords.tl.y += direction * m_winSize.height * time;
        coords.tr.y += direction * m_winSize.height * time;

        setTile(ccg(i, 0), coords);
    }
}
Beispiel #25
0
	void CCRipple3D::update(ccTime time)
	{
		int i, j;
	
		for (i = 0; i < (m_sGridSize.x+1); ++i)
		{
			for (j = 0; j < (m_sGridSize.y+1); ++j)
			{
				ccVertex3F v = originalVertex(ccg(i, j));
				CCPoint vect = ccpSub(m_positionInPixels, ccp(v.x,v.y));
				CGFloat r = ccpLength(vect);
				
				if (r < m_fRadius)
				{
					r = m_fRadius - r;
					CGFloat rate = powf(r / m_fRadius, 2);
					v.z += (sinf( time*(CGFloat)M_PI * m_nWaves * 2 + r * 0.1f) * m_fAmplitude * m_fAmplitudeRate * rate);
				}
				
				setVertex(ccg(i, j), v);
			}
		}
	}
void CCFadeOutTRTiles::update(ccTime time)
{
    int i, j;

    for (i = 0; i < m_sGridSize.x; ++i)
    {
        for (j = 0; j < m_sGridSize.y; ++j)
        {
            float distance = testFunc(ccg(i, j), time);
            if ( distance == 0 )
            {
                turnOffTile(ccg(i, j));
            } else if (distance < 1)
            {
                transformTile(ccg(i, j), distance);
            }
            else
            {
                turnOnTile(ccg(i, j));
            }
        }
    }
}
//------------------------------------------------------------------
//
// Effect1
//
//------------------------------------------------------------------
void Effect1::onEnter()
{
    EffectAdvanceTextLayer::onEnter();

    CCNode* target = getChildByTag(kTagBackground);
    
    // To reuse a grid the grid size and the grid type must be the same.
    // in this case:
    //     Lens3D is Grid3D and it's size is (15,10)
    //     Waves3D is Grid3D and it's size is (15,10)
    
    CCSize size = CCDirector::sharedDirector()->getWinSize();
    CCActionInterval* lens = CCLens3D::create(ccp(size.width/2,size.height/2), 240, ccg(15,10), 0.0f);
    CCActionInterval* waves = CCWaves3D::create(18, 15, ccg(15,10), 10);

    CCFiniteTimeAction* reuse = CCReuseGrid::create(1);
    CCActionInterval* delay = CCDelayTime::create(8);

    CCActionInterval* orbit = CCOrbitCamera::create(5, 1, 2, 0, 180, 0, -90);
    CCActionInterval* orbit_back = orbit->reverse();

    target->runAction( CCRepeatForever::create( (CCActionInterval *)(CCSequence::create( orbit, orbit_back, NULL) ) ) );
    target->runAction( CCSequence::create(lens, delay, reuse, waves, NULL) );
}
Beispiel #28
0
	void CCWaves::update(ccTime time)
	{
		int i, j;

		for (i = 0; i < m_sGridSize.x + 1; ++i)
		{
			for (j = 0; j < m_sGridSize.y + 1; ++j)
			{
				ccVertex3F v = originalVertex(ccg(i, j));

				if (m_bVertical)
				{
					v.x = (v.x + (sinf(time * (CGFloat)M_PI * m_nWaves * 2 + v.y * .01f) * m_fAmplitude * m_fAmplitudeRate));
				}

				if (m_bHorizontal)
				{
                    v.y = (v.y + (sinf(time * (CGFloat)M_PI * m_nWaves * 2 + v.x * .01f) * m_fAmplitude * m_fAmplitudeRate));
				}

				setVertex(ccg(i, j), v);
			}
		}
	}
void CCShuffleTiles::update(ccTime time)
{
    int i, j;

    Tile *tileArray = (Tile*)m_pTiles;

    for (i = 0; i < m_sGridSize.x; ++i)
    {
        for (j = 0; j < m_sGridSize.y; ++j)
        {
            tileArray->position = ccpMult(ccp((float)tileArray->delta.x, (float)tileArray->delta.y), time);
            placeTile(ccg(i, j), tileArray);
            ++tileArray;
        }
    }
}
//------------------------------------------------------------------
//
// Effect4
//
//------------------------------------------------------------------
void Effect4::onEnter()
{
	EffectAdvanceTextLayer::onEnter();

	CCActionInterval* lens = CCLens3D::actionWithPosition(ccp(100,180), 150, ccg(32,24), 10);
	//id move = [MoveBy::actionWithDuration:5 position:ccp(400,0)];

    /**
    @todo we only support CCNode run actions now.
    */
// 	CCActionInterval* move = CCJumpBy::actionWithDuration(5, ccp(380,0), 100, 4);
// 	CCActionInterval* move_back = move->reverse();
// 	CCActionInterval* seq = (CCActionInterval *)(CCSequence::actions( move, move_back, NULL));
//  CCActionManager::sharedManager()->addAction(seq, lens, false);

	runAction( lens );
}