2011-04-11 11:24:10 +08:00
|
|
|
|
/****************************************************************************
|
|
|
|
|
Copyright (c) 2010<EFBFBD><EFBFBD>2011 cocos2d-x.org
|
|
|
|
|
Copyright (c) 2009 On-Core
|
|
|
|
|
|
|
|
|
|
http://www.cocos2d-x.org
|
|
|
|
|
|
|
|
|
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
|
|
|
of this software and associated documentation files (the "Software"), to deal
|
|
|
|
|
in the Software without restriction, including without limitation the rights
|
|
|
|
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
|
|
|
copies of the Software, and to permit persons to whom the Software is
|
|
|
|
|
furnished to do so, subject to the following conditions:
|
|
|
|
|
|
|
|
|
|
The above copyright notice and this permission notice shall be included in
|
|
|
|
|
all copies or substantial portions of the Software.
|
|
|
|
|
|
|
|
|
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
|
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
|
|
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
|
|
|
THE SOFTWARE.
|
|
|
|
|
****************************************************************************/
|
|
|
|
|
#include "CCActionTiledGrid.h"
|
|
|
|
|
#include "CCDirector.h"
|
|
|
|
|
#include "ccMacros.h"
|
2012-06-19 16:20:46 +08:00
|
|
|
|
#include "support/CCPointExtension.h"
|
2011-04-11 11:24:10 +08:00
|
|
|
|
#include "effects/CCGrid.h"
|
2012-06-19 16:20:46 +08:00
|
|
|
|
#include "cocoa/CCZone.h"
|
2011-04-11 11:24:10 +08:00
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
|
2012-04-18 18:43:45 +08:00
|
|
|
|
NS_CC_BEGIN
|
|
|
|
|
|
|
|
|
|
struct Tile
|
2011-04-11 11:24:10 +08:00
|
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
|
CCPoint position;
|
|
|
|
|
CCPoint startPosition;
|
2012-12-26 18:59:31 +08:00
|
|
|
|
CCSize delta;
|
2012-04-18 18:43:45 +08:00
|
|
|
|
};
|
2011-04-11 11:24:10 +08:00
|
|
|
|
|
2012-04-18 18:43:45 +08:00
|
|
|
|
// implementation of ShakyTiles3D
|
2011-04-11 11:24:10 +08:00
|
|
|
|
|
2012-12-26 18:59:31 +08:00
|
|
|
|
CCShakyTiles3D* CCShakyTiles3D::create(float duration, const CCSize& gridSize, int nRange, bool bShakeZ)
|
2012-04-18 18:43:45 +08:00
|
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
|
CCShakyTiles3D *pAction = new CCShakyTiles3D();
|
|
|
|
|
|
|
|
|
|
if (pAction)
|
|
|
|
|
{
|
2012-12-26 18:59:31 +08:00
|
|
|
|
if (pAction->initWithDuration(duration, gridSize, nRange, bShakeZ))
|
2012-04-19 14:35:52 +08:00
|
|
|
|
{
|
|
|
|
|
pAction->autorelease();
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
CC_SAFE_RELEASE_NULL(pAction);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return pAction;
|
2012-04-18 18:43:45 +08:00
|
|
|
|
}
|
|
|
|
|
|
2012-12-26 18:59:31 +08:00
|
|
|
|
bool CCShakyTiles3D::initWithDuration(float duration, const CCSize& gridSize, int nRange, bool bShakeZ)
|
2012-04-18 18:43:45 +08:00
|
|
|
|
{
|
2012-12-26 18:59:31 +08:00
|
|
|
|
if (CCTiledGrid3DAction::initWithDuration(duration, gridSize))
|
2012-04-19 14:35:52 +08:00
|
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
|
_randrange = nRange;
|
|
|
|
|
_shakeZ = bShakeZ;
|
2012-04-18 18:43:45 +08:00
|
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
|
return true;
|
|
|
|
|
}
|
2012-04-18 18:43:45 +08:00
|
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
|
return false;
|
2012-04-18 18:43:45 +08:00
|
|
|
|
}
|
|
|
|
|
|
2013-06-16 10:44:39 +08:00
|
|
|
|
CCShakyTiles3D* CCShakyTiles3D::clone() const
|
|
|
|
|
{
|
|
|
|
|
auto a = new CCShakyTiles3D(*this);
|
2013-06-19 00:59:34 +08:00
|
|
|
|
a->initWithDuration(_duration, _gridSize, _randrange, _shakeZ);
|
2013-06-16 10:44:39 +08:00
|
|
|
|
a->autorelease();
|
|
|
|
|
return a;
|
|
|
|
|
}
|
|
|
|
|
|
2012-04-18 18:43:45 +08:00
|
|
|
|
CCObject* CCShakyTiles3D::copyWithZone(CCZone *pZone)
|
|
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
|
CCZone* pNewZone = NULL;
|
|
|
|
|
CCShakyTiles3D* pCopy = NULL;
|
2013-06-15 14:03:30 +08:00
|
|
|
|
if(pZone && pZone->_copyObject)
|
2012-04-19 14:35:52 +08:00
|
|
|
|
{
|
|
|
|
|
//in case of being called at sub class
|
2013-06-15 14:03:30 +08:00
|
|
|
|
pCopy = (CCShakyTiles3D*)(pZone->_copyObject);
|
2012-04-19 14:35:52 +08:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
pCopy = new CCShakyTiles3D();
|
|
|
|
|
pZone = pNewZone = new CCZone(pCopy);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
CCTiledGrid3DAction::copyWithZone(pZone);
|
|
|
|
|
|
2013-06-15 14:03:30 +08:00
|
|
|
|
pCopy->initWithDuration(_duration, _gridSize, _randrange, _shakeZ);
|
2012-04-19 14:35:52 +08:00
|
|
|
|
|
|
|
|
|
CC_SAFE_DELETE(pNewZone);
|
|
|
|
|
return pCopy;
|
2012-04-18 18:43:45 +08:00
|
|
|
|
}
|
2011-04-11 11:24:10 +08:00
|
|
|
|
|
2012-06-08 13:55:28 +08:00
|
|
|
|
void CCShakyTiles3D::update(float time)
|
2012-04-18 18:43:45 +08:00
|
|
|
|
{
|
|
|
|
|
CC_UNUSED_PARAM(time);
|
2012-04-19 14:35:52 +08:00
|
|
|
|
int i, j;
|
|
|
|
|
|
2013-06-15 14:03:30 +08:00
|
|
|
|
for (i = 0; i < _gridSize.width; ++i)
|
2012-04-19 14:35:52 +08:00
|
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
|
for (j = 0; j < _gridSize.height; ++j)
|
2012-04-19 14:35:52 +08:00
|
|
|
|
{
|
2012-12-26 18:59:31 +08:00
|
|
|
|
ccQuad3 coords = originalTile(ccp(i, j));
|
2012-04-19 14:35:52 +08:00
|
|
|
|
|
|
|
|
|
// X
|
2013-06-15 14:03:30 +08:00
|
|
|
|
coords.bl.x += ( rand() % (_randrange*2) ) - _randrange;
|
|
|
|
|
coords.br.x += ( rand() % (_randrange*2) ) - _randrange;
|
|
|
|
|
coords.tl.x += ( rand() % (_randrange*2) ) - _randrange;
|
|
|
|
|
coords.tr.x += ( rand() % (_randrange*2) ) - _randrange;
|
2012-04-19 14:35:52 +08:00
|
|
|
|
|
|
|
|
|
// Y
|
2013-06-15 14:03:30 +08:00
|
|
|
|
coords.bl.y += ( rand() % (_randrange*2) ) - _randrange;
|
|
|
|
|
coords.br.y += ( rand() % (_randrange*2) ) - _randrange;
|
|
|
|
|
coords.tl.y += ( rand() % (_randrange*2) ) - _randrange;
|
|
|
|
|
coords.tr.y += ( rand() % (_randrange*2) ) - _randrange;
|
2012-04-19 14:35:52 +08:00
|
|
|
|
|
2013-06-15 14:03:30 +08:00
|
|
|
|
if (_shakeZ)
|
2012-04-19 14:35:52 +08:00
|
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
|
coords.bl.z += ( rand() % (_randrange*2) ) - _randrange;
|
|
|
|
|
coords.br.z += ( rand() % (_randrange*2) ) - _randrange;
|
|
|
|
|
coords.tl.z += ( rand() % (_randrange*2) ) - _randrange;
|
|
|
|
|
coords.tr.z += ( rand() % (_randrange*2) ) - _randrange;
|
2012-04-19 14:35:52 +08:00
|
|
|
|
}
|
|
|
|
|
|
2012-12-26 18:59:31 +08:00
|
|
|
|
setTile(ccp(i, j), coords);
|
2012-04-19 14:35:52 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
2012-04-18 18:43:45 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// implementation of CCShatteredTiles3D
|
|
|
|
|
|
2012-12-26 18:59:31 +08:00
|
|
|
|
CCShatteredTiles3D* CCShatteredTiles3D::create(float duration, const CCSize& gridSize, int nRange, bool bShatterZ)
|
2012-04-18 18:43:45 +08:00
|
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
|
CCShatteredTiles3D *pAction = new CCShatteredTiles3D();
|
|
|
|
|
|
|
|
|
|
if (pAction)
|
|
|
|
|
{
|
2012-12-26 18:59:31 +08:00
|
|
|
|
if (pAction->initWithDuration(duration, gridSize, nRange, bShatterZ))
|
2012-04-19 14:35:52 +08:00
|
|
|
|
{
|
|
|
|
|
pAction->autorelease();
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
CC_SAFE_RELEASE_NULL(pAction);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return pAction;
|
2012-04-18 18:43:45 +08:00
|
|
|
|
}
|
|
|
|
|
|
2012-12-26 18:59:31 +08:00
|
|
|
|
bool CCShatteredTiles3D::initWithDuration(float duration, const CCSize& gridSize, int nRange, bool bShatterZ)
|
2012-04-18 18:43:45 +08:00
|
|
|
|
{
|
2012-12-26 18:59:31 +08:00
|
|
|
|
if (CCTiledGrid3DAction::initWithDuration(duration, gridSize))
|
2012-04-19 14:35:52 +08:00
|
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
|
_once = false;
|
|
|
|
|
_randrange = nRange;
|
|
|
|
|
_shatterZ = bShatterZ;
|
2012-04-18 18:43:45 +08:00
|
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
|
return true;
|
|
|
|
|
}
|
2011-04-11 11:24:10 +08:00
|
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
|
return false;
|
2012-04-18 18:43:45 +08:00
|
|
|
|
}
|
|
|
|
|
|
2013-06-16 10:44:39 +08:00
|
|
|
|
CCShatteredTiles3D* CCShatteredTiles3D::clone() const
|
|
|
|
|
{
|
|
|
|
|
auto a = new CCShatteredTiles3D(*this);
|
2013-06-19 00:59:34 +08:00
|
|
|
|
a->initWithDuration(_duration, _gridSize, _randrange, _shatterZ);
|
2013-06-16 10:44:39 +08:00
|
|
|
|
a->autorelease();
|
|
|
|
|
return a;
|
|
|
|
|
}
|
|
|
|
|
|
2012-04-18 18:43:45 +08:00
|
|
|
|
CCObject* CCShatteredTiles3D::copyWithZone(CCZone *pZone)
|
|
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
|
CCZone* pNewZone = NULL;
|
|
|
|
|
CCShatteredTiles3D* pCopy = NULL;
|
2013-06-15 14:03:30 +08:00
|
|
|
|
if(pZone && pZone->_copyObject)
|
2012-04-19 14:35:52 +08:00
|
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
|
pCopy = (CCShatteredTiles3D*)(pZone->_copyObject);
|
2012-04-19 14:35:52 +08:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
pCopy = new CCShatteredTiles3D();
|
|
|
|
|
pZone = pNewZone = new CCZone(pCopy);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//copy super class's member
|
|
|
|
|
CCTiledGrid3DAction::copyWithZone(pZone);
|
|
|
|
|
|
2013-06-15 14:03:30 +08:00
|
|
|
|
pCopy->initWithDuration(_duration, _gridSize, _randrange, _shatterZ);
|
2012-04-19 14:35:52 +08:00
|
|
|
|
|
|
|
|
|
CC_SAFE_DELETE(pNewZone);
|
|
|
|
|
return pCopy;
|
2012-04-18 18:43:45 +08:00
|
|
|
|
}
|
|
|
|
|
|
2012-06-08 13:55:28 +08:00
|
|
|
|
void CCShatteredTiles3D::update(float time)
|
2012-04-18 18:43:45 +08:00
|
|
|
|
{
|
|
|
|
|
CC_UNUSED_PARAM(time);
|
2012-04-19 14:35:52 +08:00
|
|
|
|
int i, j;
|
|
|
|
|
|
2013-06-15 14:03:30 +08:00
|
|
|
|
if (_once == false)
|
2012-04-19 14:35:52 +08:00
|
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
|
for (i = 0; i < _gridSize.width; ++i)
|
2012-04-19 14:35:52 +08:00
|
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
|
for (j = 0; j < _gridSize.height; ++j)
|
2012-04-19 14:35:52 +08:00
|
|
|
|
{
|
2012-12-26 18:59:31 +08:00
|
|
|
|
ccQuad3 coords = originalTile(ccp(i ,j));
|
2012-04-19 14:35:52 +08:00
|
|
|
|
|
|
|
|
|
// X
|
2013-06-15 14:03:30 +08:00
|
|
|
|
coords.bl.x += ( rand() % (_randrange*2) ) - _randrange;
|
|
|
|
|
coords.br.x += ( rand() % (_randrange*2) ) - _randrange;
|
|
|
|
|
coords.tl.x += ( rand() % (_randrange*2) ) - _randrange;
|
|
|
|
|
coords.tr.x += ( rand() % (_randrange*2) ) - _randrange;
|
2012-04-19 14:35:52 +08:00
|
|
|
|
|
|
|
|
|
// Y
|
2013-06-15 14:03:30 +08:00
|
|
|
|
coords.bl.y += ( rand() % (_randrange*2) ) - _randrange;
|
|
|
|
|
coords.br.y += ( rand() % (_randrange*2) ) - _randrange;
|
|
|
|
|
coords.tl.y += ( rand() % (_randrange*2) ) - _randrange;
|
|
|
|
|
coords.tr.y += ( rand() % (_randrange*2) ) - _randrange;
|
2012-04-19 14:35:52 +08:00
|
|
|
|
|
2013-06-15 14:03:30 +08:00
|
|
|
|
if (_shatterZ)
|
2012-04-19 14:35:52 +08:00
|
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
|
coords.bl.z += ( rand() % (_randrange*2) ) - _randrange;
|
|
|
|
|
coords.br.z += ( rand() % (_randrange*2) ) - _randrange;
|
|
|
|
|
coords.tl.z += ( rand() % (_randrange*2) ) - _randrange;
|
|
|
|
|
coords.tr.z += ( rand() % (_randrange*2) ) - _randrange;
|
2012-04-19 14:35:52 +08:00
|
|
|
|
}
|
|
|
|
|
|
2012-12-26 18:59:31 +08:00
|
|
|
|
setTile(ccp(i, j), coords);
|
2012-04-19 14:35:52 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2013-06-15 14:03:30 +08:00
|
|
|
|
_once = true;
|
2012-04-19 14:35:52 +08:00
|
|
|
|
}
|
2012-04-18 18:43:45 +08:00
|
|
|
|
}
|
2011-04-11 11:24:10 +08:00
|
|
|
|
|
2012-04-18 18:43:45 +08:00
|
|
|
|
// implementation of CCShuffleTiles
|
2011-04-11 11:24:10 +08:00
|
|
|
|
|
2012-12-26 18:59:31 +08:00
|
|
|
|
CCShuffleTiles* CCShuffleTiles::create(float duration, const CCSize& gridSize, unsigned int seed)
|
2012-04-18 18:43:45 +08:00
|
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
|
CCShuffleTiles *pAction = new CCShuffleTiles();
|
|
|
|
|
|
|
|
|
|
if (pAction)
|
|
|
|
|
{
|
2012-12-26 18:59:31 +08:00
|
|
|
|
if (pAction->initWithDuration(duration, gridSize, seed))
|
2012-04-19 14:35:52 +08:00
|
|
|
|
{
|
|
|
|
|
pAction->autorelease();
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
CC_SAFE_RELEASE_NULL(pAction);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return pAction;
|
2012-04-18 18:43:45 +08:00
|
|
|
|
}
|
|
|
|
|
|
2012-12-26 18:59:31 +08:00
|
|
|
|
bool CCShuffleTiles::initWithDuration(float duration, const CCSize& gridSize, unsigned int seed)
|
2012-04-18 18:43:45 +08:00
|
|
|
|
{
|
2012-12-26 18:59:31 +08:00
|
|
|
|
if (CCTiledGrid3DAction::initWithDuration(duration, gridSize))
|
2012-04-19 14:35:52 +08:00
|
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
|
_seed = seed;
|
|
|
|
|
_tilesOrder = NULL;
|
|
|
|
|
_tiles = NULL;
|
2012-04-18 18:43:45 +08:00
|
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
|
return true;
|
|
|
|
|
}
|
2011-04-11 11:24:10 +08:00
|
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
|
return false;
|
2012-04-18 18:43:45 +08:00
|
|
|
|
}
|
2011-04-11 11:24:10 +08:00
|
|
|
|
|
2013-06-16 10:44:39 +08:00
|
|
|
|
CCShuffleTiles* CCShuffleTiles::clone() const
|
|
|
|
|
{
|
|
|
|
|
auto a = new CCShuffleTiles(*this);
|
2013-06-19 00:59:34 +08:00
|
|
|
|
a->initWithDuration(_duration, _gridSize, _seed);
|
2013-06-16 10:44:39 +08:00
|
|
|
|
a->autorelease();
|
|
|
|
|
return a;
|
|
|
|
|
}
|
|
|
|
|
|
2012-04-18 18:43:45 +08:00
|
|
|
|
CCObject* CCShuffleTiles::copyWithZone(CCZone *pZone)
|
|
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
|
CCZone* pNewZone = NULL;
|
|
|
|
|
CCShuffleTiles* pCopy = NULL;
|
2013-06-15 14:03:30 +08:00
|
|
|
|
if(pZone && pZone->_copyObject)
|
2012-04-19 14:35:52 +08:00
|
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
|
pCopy = (CCShuffleTiles*)(pZone->_copyObject);
|
2012-04-19 14:35:52 +08:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
pCopy = new CCShuffleTiles();
|
|
|
|
|
pZone = pNewZone = new CCZone(pCopy);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
CCTiledGrid3DAction::copyWithZone(pZone);
|
|
|
|
|
|
2013-06-15 14:03:30 +08:00
|
|
|
|
pCopy->initWithDuration(_duration, _gridSize, _seed);
|
2012-04-19 14:35:52 +08:00
|
|
|
|
|
|
|
|
|
CC_SAFE_DELETE(pNewZone);
|
|
|
|
|
return pCopy;
|
2012-04-18 18:43:45 +08:00
|
|
|
|
}
|
2011-04-11 11:24:10 +08:00
|
|
|
|
|
2012-04-18 18:43:45 +08:00
|
|
|
|
CCShuffleTiles::~CCShuffleTiles(void)
|
|
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
|
CC_SAFE_DELETE_ARRAY(_tilesOrder);
|
|
|
|
|
CC_SAFE_DELETE_ARRAY(_tiles);
|
2012-04-18 18:43:45 +08:00
|
|
|
|
}
|
2011-04-11 11:24:10 +08:00
|
|
|
|
|
2012-12-26 18:59:31 +08:00
|
|
|
|
void CCShuffleTiles::shuffle(unsigned int *pArray, unsigned int nLen)
|
2012-04-18 18:43:45 +08:00
|
|
|
|
{
|
2012-12-27 10:55:25 +08:00
|
|
|
|
int i;
|
2012-04-19 14:35:52 +08:00
|
|
|
|
for( i = nLen - 1; i >= 0; i-- )
|
|
|
|
|
{
|
|
|
|
|
unsigned int j = rand() % (i+1);
|
2012-12-26 18:59:31 +08:00
|
|
|
|
unsigned int v = pArray[i];
|
2012-04-19 14:35:52 +08:00
|
|
|
|
pArray[i] = pArray[j];
|
|
|
|
|
pArray[j] = v;
|
|
|
|
|
}
|
2012-04-18 18:43:45 +08:00
|
|
|
|
}
|
2011-04-11 11:24:10 +08:00
|
|
|
|
|
2012-12-26 18:59:31 +08:00
|
|
|
|
CCSize CCShuffleTiles::getDelta(const CCSize& pos)
|
2012-04-18 18:43:45 +08:00
|
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
|
CCPoint pos2;
|
2011-04-11 11:24:10 +08:00
|
|
|
|
|
2013-06-15 14:03:30 +08:00
|
|
|
|
unsigned int idx = pos.width * _gridSize.height + pos.height;
|
2011-04-11 11:24:10 +08:00
|
|
|
|
|
2013-06-15 14:03:30 +08:00
|
|
|
|
pos2.x = (float)(_tilesOrder[idx] / (int)_gridSize.height);
|
|
|
|
|
pos2.y = (float)(_tilesOrder[idx] % (int)_gridSize.height);
|
2011-04-11 11:24:10 +08:00
|
|
|
|
|
2012-12-26 18:59:31 +08:00
|
|
|
|
return CCSizeMake((int)(pos2.x - pos.width), (int)(pos2.y - pos.height));
|
2012-04-18 18:43:45 +08:00
|
|
|
|
}
|
2011-04-11 11:24:10 +08:00
|
|
|
|
|
2012-12-26 18:59:31 +08:00
|
|
|
|
void CCShuffleTiles::placeTile(const CCPoint& pos, Tile *t)
|
2012-04-18 18:43:45 +08:00
|
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
|
ccQuad3 coords = originalTile(pos);
|
2011-04-11 11:24:10 +08:00
|
|
|
|
|
2013-06-15 14:03:30 +08:00
|
|
|
|
CCPoint step = _target->getGrid()->getStep();
|
2012-04-19 14:35:52 +08:00
|
|
|
|
coords.bl.x += (int)(t->position.x * step.x);
|
|
|
|
|
coords.bl.y += (int)(t->position.y * step.y);
|
2011-04-11 11:24:10 +08:00
|
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
|
coords.br.x += (int)(t->position.x * step.x);
|
|
|
|
|
coords.br.y += (int)(t->position.y * step.y);
|
2011-04-11 11:24:10 +08:00
|
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
|
coords.tl.x += (int)(t->position.x * step.x);
|
|
|
|
|
coords.tl.y += (int)(t->position.y * step.y);
|
2011-04-11 11:24:10 +08:00
|
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
|
coords.tr.x += (int)(t->position.x * step.x);
|
|
|
|
|
coords.tr.y += (int)(t->position.y * step.y);
|
2011-04-11 11:24:10 +08:00
|
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
|
setTile(pos, coords);
|
2012-04-18 18:43:45 +08:00
|
|
|
|
}
|
2011-04-11 11:24:10 +08:00
|
|
|
|
|
2012-04-18 18:43:45 +08:00
|
|
|
|
void CCShuffleTiles::startWithTarget(CCNode *pTarget)
|
|
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
|
CCTiledGrid3DAction::startWithTarget(pTarget);
|
|
|
|
|
|
2013-06-15 14:03:30 +08:00
|
|
|
|
if (_seed != (unsigned int)-1)
|
2012-04-19 14:35:52 +08:00
|
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
|
srand(_seed);
|
2012-04-19 14:35:52 +08:00
|
|
|
|
}
|
|
|
|
|
|
2013-06-15 14:03:30 +08:00
|
|
|
|
_tilesCount = _gridSize.width * _gridSize.height;
|
|
|
|
|
_tilesOrder = new unsigned int[_tilesCount];
|
2012-04-19 14:35:52 +08:00
|
|
|
|
int i, j;
|
|
|
|
|
unsigned int k;
|
|
|
|
|
|
|
|
|
|
/**
|
2013-06-15 14:03:30 +08:00
|
|
|
|
* Use k to loop. Because _tilesCount is unsigned int,
|
2012-04-19 14:35:52 +08:00
|
|
|
|
* and i is used later for int.
|
|
|
|
|
*/
|
2013-06-15 14:03:30 +08:00
|
|
|
|
for (k = 0; k < _tilesCount; ++k)
|
2012-04-19 14:35:52 +08:00
|
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
|
_tilesOrder[k] = k;
|
2012-04-19 14:35:52 +08:00
|
|
|
|
}
|
|
|
|
|
|
2013-06-15 14:03:30 +08:00
|
|
|
|
shuffle(_tilesOrder, _tilesCount);
|
2012-04-19 14:35:52 +08:00
|
|
|
|
|
2013-06-15 14:03:30 +08:00
|
|
|
|
_tiles = (struct Tile *)new Tile[_tilesCount];
|
|
|
|
|
Tile *tileArray = (Tile*) _tiles;
|
2012-04-19 14:35:52 +08:00
|
|
|
|
|
2013-06-15 14:03:30 +08:00
|
|
|
|
for (i = 0; i < _gridSize.width; ++i)
|
2012-04-19 14:35:52 +08:00
|
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
|
for (j = 0; j < _gridSize.height; ++j)
|
2012-04-19 14:35:52 +08:00
|
|
|
|
{
|
|
|
|
|
tileArray->position = ccp((float)i, (float)j);
|
|
|
|
|
tileArray->startPosition = ccp((float)i, (float)j);
|
2012-12-26 18:59:31 +08:00
|
|
|
|
tileArray->delta = getDelta(CCSizeMake(i, j));
|
2012-04-19 14:35:52 +08:00
|
|
|
|
++tileArray;
|
|
|
|
|
}
|
|
|
|
|
}
|
2012-04-18 18:43:45 +08:00
|
|
|
|
}
|
2011-04-11 11:24:10 +08:00
|
|
|
|
|
2012-06-08 13:55:28 +08:00
|
|
|
|
void CCShuffleTiles::update(float time)
|
2012-04-18 18:43:45 +08:00
|
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
|
int i, j;
|
|
|
|
|
|
2013-06-15 14:03:30 +08:00
|
|
|
|
Tile *tileArray = (Tile*)_tiles;
|
2012-04-19 14:35:52 +08:00
|
|
|
|
|
2013-06-15 14:03:30 +08:00
|
|
|
|
for (i = 0; i < _gridSize.width; ++i)
|
2012-04-19 14:35:52 +08:00
|
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
|
for (j = 0; j < _gridSize.height; ++j)
|
2012-04-19 14:35:52 +08:00
|
|
|
|
{
|
2012-12-26 18:59:31 +08:00
|
|
|
|
tileArray->position = ccpMult(ccp((float)tileArray->delta.width, (float)tileArray->delta.height), time);
|
|
|
|
|
placeTile(ccp(i, j), tileArray);
|
2012-04-19 14:35:52 +08:00
|
|
|
|
++tileArray;
|
|
|
|
|
}
|
|
|
|
|
}
|
2012-04-18 18:43:45 +08:00
|
|
|
|
}
|
2011-04-11 11:24:10 +08:00
|
|
|
|
|
2012-04-18 18:43:45 +08:00
|
|
|
|
// implementation of CCFadeOutTRTiles
|
2011-04-11 11:24:10 +08:00
|
|
|
|
|
2012-12-26 18:59:31 +08:00
|
|
|
|
CCFadeOutTRTiles* CCFadeOutTRTiles::create(float duration, const CCSize& gridSize)
|
2012-04-18 18:43:45 +08:00
|
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
|
CCFadeOutTRTiles *pAction = new CCFadeOutTRTiles();
|
|
|
|
|
|
|
|
|
|
if (pAction)
|
|
|
|
|
{
|
2012-12-26 18:59:31 +08:00
|
|
|
|
if (pAction->initWithDuration(duration, gridSize))
|
2012-04-19 14:35:52 +08:00
|
|
|
|
{
|
|
|
|
|
pAction->autorelease();
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
CC_SAFE_RELEASE_NULL(pAction);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return pAction;
|
2012-04-18 18:43:45 +08:00
|
|
|
|
}
|
2011-04-11 11:24:10 +08:00
|
|
|
|
|
2013-06-16 10:44:39 +08:00
|
|
|
|
CCFadeOutTRTiles* CCFadeOutTRTiles::clone() const
|
|
|
|
|
{
|
|
|
|
|
auto a = new CCFadeOutTRTiles(*this);
|
2013-06-19 00:59:34 +08:00
|
|
|
|
a->initWithDuration(_duration, _gridSize);
|
2013-06-16 10:44:39 +08:00
|
|
|
|
a->autorelease();
|
|
|
|
|
return a;
|
|
|
|
|
}
|
|
|
|
|
|
2012-12-26 18:59:31 +08:00
|
|
|
|
float CCFadeOutTRTiles::testFunc(const CCSize& pos, float time)
|
2012-04-18 18:43:45 +08:00
|
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
|
CCPoint n = ccpMult(ccp((float)_gridSize.width, (float)_gridSize.height), time);
|
2012-04-19 14:35:52 +08:00
|
|
|
|
if ((n.x + n.y) == 0.0f)
|
|
|
|
|
{
|
|
|
|
|
return 1.0f;
|
|
|
|
|
}
|
2011-04-11 11:24:10 +08:00
|
|
|
|
|
2012-12-26 18:59:31 +08:00
|
|
|
|
return powf((pos.width + pos.height) / (n.x + n.y), 6);
|
2012-04-18 18:43:45 +08:00
|
|
|
|
}
|
2011-04-11 11:24:10 +08:00
|
|
|
|
|
2012-12-26 18:59:31 +08:00
|
|
|
|
void CCFadeOutTRTiles::turnOnTile(const CCPoint& pos)
|
2012-04-18 18:43:45 +08:00
|
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
|
setTile(pos, originalTile(pos));
|
2012-04-18 18:43:45 +08:00
|
|
|
|
}
|
2011-04-11 11:24:10 +08:00
|
|
|
|
|
2012-12-26 18:59:31 +08:00
|
|
|
|
void CCFadeOutTRTiles::turnOffTile(const CCPoint& pos)
|
2012-04-18 18:43:45 +08:00
|
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
|
ccQuad3 coords;
|
|
|
|
|
memset(&coords, 0, sizeof(ccQuad3));
|
|
|
|
|
setTile(pos, coords);
|
2012-04-18 18:43:45 +08:00
|
|
|
|
}
|
2011-04-11 11:24:10 +08:00
|
|
|
|
|
2012-12-26 18:59:31 +08:00
|
|
|
|
void CCFadeOutTRTiles::transformTile(const CCPoint& pos, float distance)
|
2012-04-18 18:43:45 +08:00
|
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
|
ccQuad3 coords = originalTile(pos);
|
2013-06-15 14:03:30 +08:00
|
|
|
|
CCPoint step = _target->getGrid()->getStep();
|
2011-04-11 11:24:10 +08:00
|
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
|
coords.bl.x += (step.x / 2) * (1.0f - distance);
|
|
|
|
|
coords.bl.y += (step.y / 2) * (1.0f - distance);
|
2011-04-11 11:24:10 +08:00
|
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
|
coords.br.x -= (step.x / 2) * (1.0f - distance);
|
|
|
|
|
coords.br.y += (step.y / 2) * (1.0f - distance);
|
2011-04-11 11:24:10 +08:00
|
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
|
coords.tl.x += (step.x / 2) * (1.0f - distance);
|
|
|
|
|
coords.tl.y -= (step.y / 2) * (1.0f - distance);
|
2011-04-11 11:24:10 +08:00
|
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
|
coords.tr.x -= (step.x / 2) * (1.0f - distance);
|
|
|
|
|
coords.tr.y -= (step.y / 2) * (1.0f - distance);
|
2011-04-11 11:24:10 +08:00
|
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
|
setTile(pos, coords);
|
2012-04-18 18:43:45 +08:00
|
|
|
|
}
|
2011-04-11 11:24:10 +08:00
|
|
|
|
|
2012-06-08 13:55:28 +08:00
|
|
|
|
void CCFadeOutTRTiles::update(float time)
|
2012-04-18 18:43:45 +08:00
|
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
|
int i, j;
|
|
|
|
|
|
2013-06-15 14:03:30 +08:00
|
|
|
|
for (i = 0; i < _gridSize.width; ++i)
|
2012-04-19 14:35:52 +08:00
|
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
|
for (j = 0; j < _gridSize.height; ++j)
|
2012-04-19 14:35:52 +08:00
|
|
|
|
{
|
2012-12-26 18:59:31 +08:00
|
|
|
|
float distance = testFunc(CCSizeMake(i, j), time);
|
2012-04-19 14:35:52 +08:00
|
|
|
|
if ( distance == 0 )
|
|
|
|
|
{
|
2012-12-26 18:59:31 +08:00
|
|
|
|
turnOffTile(ccp(i, j));
|
2012-04-19 14:35:52 +08:00
|
|
|
|
} else
|
|
|
|
|
if (distance < 1)
|
|
|
|
|
{
|
2012-12-26 18:59:31 +08:00
|
|
|
|
transformTile(ccp(i, j), distance);
|
2012-04-19 14:35:52 +08:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2012-12-26 18:59:31 +08:00
|
|
|
|
turnOnTile(ccp(i, j));
|
2012-04-19 14:35:52 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2012-04-18 18:43:45 +08:00
|
|
|
|
}
|
2011-04-11 11:24:10 +08:00
|
|
|
|
|
2012-04-18 18:43:45 +08:00
|
|
|
|
// implementation of CCFadeOutBLTiles
|
2012-06-14 15:13:16 +08:00
|
|
|
|
|
2012-12-26 18:59:31 +08:00
|
|
|
|
CCFadeOutBLTiles* CCFadeOutBLTiles::create(float duration, const CCSize& gridSize)
|
2012-04-18 18:43:45 +08:00
|
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
|
CCFadeOutBLTiles *pAction = new CCFadeOutBLTiles();
|
|
|
|
|
|
|
|
|
|
if (pAction)
|
|
|
|
|
{
|
2012-12-26 18:59:31 +08:00
|
|
|
|
if (pAction->initWithDuration(duration, gridSize))
|
2012-04-19 14:35:52 +08:00
|
|
|
|
{
|
|
|
|
|
pAction->autorelease();
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
CC_SAFE_RELEASE_NULL(pAction);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return pAction;
|
2012-04-18 18:43:45 +08:00
|
|
|
|
}
|
2011-04-11 11:24:10 +08:00
|
|
|
|
|
2013-06-16 10:44:39 +08:00
|
|
|
|
CCFadeOutBLTiles* CCFadeOutBLTiles::clone() const
|
|
|
|
|
{
|
|
|
|
|
auto a = new CCFadeOutBLTiles(*this);
|
2013-06-19 00:59:34 +08:00
|
|
|
|
a->initWithDuration(_duration, _gridSize);
|
2013-06-16 10:44:39 +08:00
|
|
|
|
a->autorelease();
|
|
|
|
|
return a;
|
|
|
|
|
}
|
|
|
|
|
|
2012-12-26 18:59:31 +08:00
|
|
|
|
float CCFadeOutBLTiles::testFunc(const CCSize& pos, float time)
|
2012-04-18 18:43:45 +08:00
|
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
|
CCPoint n = ccpMult(ccp((float)_gridSize.width, (float)_gridSize.height), (1.0f - time));
|
2012-12-26 18:59:31 +08:00
|
|
|
|
if ((pos.width + pos.height) == 0)
|
2012-04-19 14:35:52 +08:00
|
|
|
|
{
|
|
|
|
|
return 1.0f;
|
|
|
|
|
}
|
2011-04-11 11:24:10 +08:00
|
|
|
|
|
2012-12-26 18:59:31 +08:00
|
|
|
|
return powf((n.x + n.y) / (pos.width + pos.height), 6);
|
2012-04-18 18:43:45 +08:00
|
|
|
|
}
|
2011-04-11 11:24:10 +08:00
|
|
|
|
|
2012-04-18 18:43:45 +08:00
|
|
|
|
// implementation of CCFadeOutUpTiles
|
|
|
|
|
|
2012-12-26 18:59:31 +08:00
|
|
|
|
CCFadeOutUpTiles* CCFadeOutUpTiles::create(float duration, const CCSize& gridSize)
|
2012-04-18 18:43:45 +08:00
|
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
|
CCFadeOutUpTiles *pAction = new CCFadeOutUpTiles();
|
|
|
|
|
|
|
|
|
|
if (pAction)
|
|
|
|
|
{
|
2012-12-26 18:59:31 +08:00
|
|
|
|
if (pAction->initWithDuration(duration, gridSize))
|
2012-04-19 14:35:52 +08:00
|
|
|
|
{
|
|
|
|
|
pAction->autorelease();
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
CC_SAFE_RELEASE_NULL(pAction);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return pAction;
|
2012-04-18 18:43:45 +08:00
|
|
|
|
}
|
2011-04-11 11:24:10 +08:00
|
|
|
|
|
2013-06-16 10:44:39 +08:00
|
|
|
|
CCFadeOutUpTiles* CCFadeOutUpTiles::clone() const
|
|
|
|
|
{
|
|
|
|
|
auto a = new CCFadeOutUpTiles(*this);
|
2013-06-19 00:59:34 +08:00
|
|
|
|
a->initWithDuration(_duration, _gridSize);
|
2013-06-16 10:44:39 +08:00
|
|
|
|
a->autorelease();
|
|
|
|
|
return a;
|
|
|
|
|
}
|
|
|
|
|
|
2012-12-26 18:59:31 +08:00
|
|
|
|
float CCFadeOutUpTiles::testFunc(const CCSize& pos, float time)
|
2012-04-18 18:43:45 +08:00
|
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
|
CCPoint n = ccpMult(ccp((float)_gridSize.width, (float)_gridSize.height), time);
|
2012-04-19 14:35:52 +08:00
|
|
|
|
if (n.y == 0.0f)
|
|
|
|
|
{
|
|
|
|
|
return 1.0f;
|
|
|
|
|
}
|
2011-04-11 11:24:10 +08:00
|
|
|
|
|
2012-12-26 18:59:31 +08:00
|
|
|
|
return powf(pos.height / n.y, 6);
|
2012-04-18 18:43:45 +08:00
|
|
|
|
}
|
2011-04-11 11:24:10 +08:00
|
|
|
|
|
2012-12-26 18:59:31 +08:00
|
|
|
|
void CCFadeOutUpTiles::transformTile(const CCPoint& pos, float distance)
|
2012-04-18 18:43:45 +08:00
|
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
|
ccQuad3 coords = originalTile(pos);
|
2013-06-15 14:03:30 +08:00
|
|
|
|
CCPoint step = _target->getGrid()->getStep();
|
2011-04-11 11:24:10 +08:00
|
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
|
coords.bl.y += (step.y / 2) * (1.0f - distance);
|
|
|
|
|
coords.br.y += (step.y / 2) * (1.0f - distance);
|
|
|
|
|
coords.tl.y -= (step.y / 2) * (1.0f - distance);
|
|
|
|
|
coords.tr.y -= (step.y / 2) * (1.0f - distance);
|
2011-04-11 11:24:10 +08:00
|
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
|
setTile(pos, coords);
|
2012-04-18 18:43:45 +08:00
|
|
|
|
}
|
2011-04-11 11:24:10 +08:00
|
|
|
|
|
2012-04-18 18:43:45 +08:00
|
|
|
|
// implementation of CCFadeOutDownTiles
|
2012-06-14 15:13:16 +08:00
|
|
|
|
|
2012-12-26 18:59:31 +08:00
|
|
|
|
CCFadeOutDownTiles* CCFadeOutDownTiles::create(float duration, const CCSize& gridSize)
|
2012-04-18 18:43:45 +08:00
|
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
|
CCFadeOutDownTiles *pAction = new CCFadeOutDownTiles();
|
|
|
|
|
|
|
|
|
|
if (pAction)
|
|
|
|
|
{
|
2012-12-26 18:59:31 +08:00
|
|
|
|
if (pAction->initWithDuration(duration, gridSize))
|
2012-04-19 14:35:52 +08:00
|
|
|
|
{
|
|
|
|
|
pAction->autorelease();
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
CC_SAFE_RELEASE_NULL(pAction);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return pAction;
|
2012-04-18 18:43:45 +08:00
|
|
|
|
}
|
|
|
|
|
|
2013-06-16 10:44:39 +08:00
|
|
|
|
CCFadeOutDownTiles* CCFadeOutDownTiles::clone() const
|
|
|
|
|
{
|
|
|
|
|
auto a = new CCFadeOutDownTiles(*this);
|
2013-06-19 00:59:34 +08:00
|
|
|
|
a->initWithDuration(_duration, _gridSize);
|
2013-06-16 10:44:39 +08:00
|
|
|
|
a->autorelease();
|
|
|
|
|
return a;
|
|
|
|
|
}
|
|
|
|
|
|
2012-12-26 18:59:31 +08:00
|
|
|
|
float CCFadeOutDownTiles::testFunc(const CCSize& pos, float time)
|
2012-04-18 18:43:45 +08:00
|
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
|
CCPoint n = ccpMult(ccp((float)_gridSize.width, (float)_gridSize.height), (1.0f - time));
|
2012-12-26 18:59:31 +08:00
|
|
|
|
if (pos.height == 0)
|
2012-04-19 14:35:52 +08:00
|
|
|
|
{
|
|
|
|
|
return 1.0f;
|
|
|
|
|
}
|
2011-04-11 11:24:10 +08:00
|
|
|
|
|
2012-12-26 18:59:31 +08:00
|
|
|
|
return powf(n.y / pos.height, 6);
|
2012-04-18 18:43:45 +08:00
|
|
|
|
}
|
2011-04-11 11:24:10 +08:00
|
|
|
|
|
2012-04-18 18:43:45 +08:00
|
|
|
|
// implementation of TurnOffTiles
|
2012-06-14 15:13:16 +08:00
|
|
|
|
|
2012-12-26 18:59:31 +08:00
|
|
|
|
CCTurnOffTiles* CCTurnOffTiles::create(float duration, const CCSize& gridSize)
|
2012-04-18 18:43:45 +08:00
|
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
|
CCTurnOffTiles* pAction = new CCTurnOffTiles();
|
2012-12-26 18:59:31 +08:00
|
|
|
|
if (pAction->initWithDuration(duration, gridSize, 0))
|
2012-04-19 14:35:52 +08:00
|
|
|
|
{
|
|
|
|
|
pAction->autorelease();
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
CC_SAFE_RELEASE_NULL(pAction);
|
|
|
|
|
}
|
|
|
|
|
return pAction;
|
2012-04-18 18:43:45 +08:00
|
|
|
|
}
|
|
|
|
|
|
2012-12-26 18:59:31 +08:00
|
|
|
|
CCTurnOffTiles* CCTurnOffTiles::create(float duration, const CCSize& gridSize, unsigned int seed)
|
2012-04-18 18:43:45 +08:00
|
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
|
CCTurnOffTiles *pAction = new CCTurnOffTiles();
|
|
|
|
|
|
|
|
|
|
if (pAction)
|
|
|
|
|
{
|
2012-12-26 18:59:31 +08:00
|
|
|
|
if (pAction->initWithDuration(duration, gridSize, seed))
|
2012-04-19 14:35:52 +08:00
|
|
|
|
{
|
|
|
|
|
pAction->autorelease();
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
CC_SAFE_RELEASE_NULL(pAction);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return pAction;
|
2012-04-18 18:43:45 +08:00
|
|
|
|
}
|
2011-04-11 11:24:10 +08:00
|
|
|
|
|
2012-12-26 18:59:31 +08:00
|
|
|
|
bool CCTurnOffTiles::initWithDuration(float duration, const CCSize& gridSize, unsigned int seed)
|
2012-04-18 18:43:45 +08:00
|
|
|
|
{
|
2012-12-26 18:59:31 +08:00
|
|
|
|
if (CCTiledGrid3DAction::initWithDuration(duration, gridSize))
|
2012-04-19 14:35:52 +08:00
|
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
|
_seed = seed;
|
|
|
|
|
_tilesOrder = NULL;
|
2011-04-11 11:24:10 +08:00
|
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
|
return true;
|
|
|
|
|
}
|
2011-04-11 11:24:10 +08:00
|
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
|
return false;
|
2012-04-18 18:43:45 +08:00
|
|
|
|
}
|
2011-04-11 11:24:10 +08:00
|
|
|
|
|
2013-06-16 10:44:39 +08:00
|
|
|
|
CCTurnOffTiles* CCTurnOffTiles::clone() const
|
|
|
|
|
{
|
|
|
|
|
auto a = new CCTurnOffTiles(*this);
|
2013-06-19 00:59:34 +08:00
|
|
|
|
a->initWithDuration(_duration, _gridSize, _seed );
|
2013-06-16 10:44:39 +08:00
|
|
|
|
a->autorelease();
|
|
|
|
|
return a;
|
|
|
|
|
}
|
|
|
|
|
|
2012-04-18 18:43:45 +08:00
|
|
|
|
CCObject* CCTurnOffTiles::copyWithZone(CCZone *pZone)
|
|
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
|
CCZone* pNewZone = NULL;
|
|
|
|
|
CCTurnOffTiles* pCopy = NULL;
|
2013-06-15 14:03:30 +08:00
|
|
|
|
if(pZone && pZone->_copyObject)
|
2012-04-19 14:35:52 +08:00
|
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
|
pCopy = (CCTurnOffTiles*)(pZone->_copyObject);
|
2012-04-19 14:35:52 +08:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
pCopy = new CCTurnOffTiles();
|
|
|
|
|
pZone = pNewZone = new CCZone(pCopy);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
CCTiledGrid3DAction::copyWithZone(pZone);
|
|
|
|
|
|
2013-06-15 14:03:30 +08:00
|
|
|
|
pCopy->initWithDuration(_duration, _gridSize, _seed );
|
2012-04-19 14:35:52 +08:00
|
|
|
|
|
|
|
|
|
CC_SAFE_DELETE(pNewZone);
|
|
|
|
|
return pCopy;
|
2012-04-18 18:43:45 +08:00
|
|
|
|
}
|
2011-04-11 11:24:10 +08:00
|
|
|
|
|
2012-04-18 18:43:45 +08:00
|
|
|
|
CCTurnOffTiles::~CCTurnOffTiles(void)
|
|
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
|
CC_SAFE_DELETE_ARRAY(_tilesOrder);
|
2012-04-18 18:43:45 +08:00
|
|
|
|
}
|
|
|
|
|
|
2012-12-26 18:59:31 +08:00
|
|
|
|
void CCTurnOffTiles::shuffle(unsigned int *pArray, unsigned int nLen)
|
2012-04-18 18:43:45 +08:00
|
|
|
|
{
|
2012-12-27 10:55:25 +08:00
|
|
|
|
int i;
|
2012-04-19 14:35:52 +08:00
|
|
|
|
for (i = nLen - 1; i >= 0; i--)
|
|
|
|
|
{
|
|
|
|
|
unsigned int j = rand() % (i+1);
|
2012-12-26 18:59:31 +08:00
|
|
|
|
unsigned int v = pArray[i];
|
2012-04-19 14:35:52 +08:00
|
|
|
|
pArray[i] = pArray[j];
|
|
|
|
|
pArray[j] = v;
|
|
|
|
|
}
|
2012-04-18 18:43:45 +08:00
|
|
|
|
}
|
2011-04-11 11:24:10 +08:00
|
|
|
|
|
2012-12-26 18:59:31 +08:00
|
|
|
|
void CCTurnOffTiles::turnOnTile(const CCPoint& pos)
|
2012-04-18 18:43:45 +08:00
|
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
|
setTile(pos, originalTile(pos));
|
2012-04-18 18:43:45 +08:00
|
|
|
|
}
|
2011-04-11 11:24:10 +08:00
|
|
|
|
|
2012-12-26 18:59:31 +08:00
|
|
|
|
void CCTurnOffTiles::turnOffTile(const CCPoint& pos)
|
2012-04-18 18:43:45 +08:00
|
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
|
ccQuad3 coords;
|
2011-04-11 11:24:10 +08:00
|
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
|
memset(&coords, 0, sizeof(ccQuad3));
|
|
|
|
|
setTile(pos, coords);
|
2012-04-18 18:43:45 +08:00
|
|
|
|
}
|
2011-04-11 11:24:10 +08:00
|
|
|
|
|
2012-04-18 18:43:45 +08:00
|
|
|
|
void CCTurnOffTiles::startWithTarget(CCNode *pTarget)
|
|
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
|
unsigned int i;
|
2011-04-11 11:24:10 +08:00
|
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
|
CCTiledGrid3DAction::startWithTarget(pTarget);
|
2011-04-11 11:24:10 +08:00
|
|
|
|
|
2013-06-15 14:03:30 +08:00
|
|
|
|
if (_seed != (unsigned int)-1)
|
2012-04-19 14:35:52 +08:00
|
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
|
srand(_seed);
|
2012-04-19 14:35:52 +08:00
|
|
|
|
}
|
2011-04-11 11:24:10 +08:00
|
|
|
|
|
2013-06-15 14:03:30 +08:00
|
|
|
|
_tilesCount = _gridSize.width * _gridSize.height;
|
|
|
|
|
_tilesOrder = new unsigned int[_tilesCount];
|
2011-04-11 11:24:10 +08:00
|
|
|
|
|
2013-06-15 14:03:30 +08:00
|
|
|
|
for (i = 0; i < _tilesCount; ++i)
|
2012-04-19 14:35:52 +08:00
|
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
|
_tilesOrder[i] = i;
|
2012-04-19 14:35:52 +08:00
|
|
|
|
}
|
2011-04-11 11:24:10 +08:00
|
|
|
|
|
2013-06-15 14:03:30 +08:00
|
|
|
|
shuffle(_tilesOrder, _tilesCount);
|
2012-04-18 18:43:45 +08:00
|
|
|
|
}
|
2011-04-11 11:24:10 +08:00
|
|
|
|
|
2012-06-08 13:55:28 +08:00
|
|
|
|
void CCTurnOffTiles::update(float time)
|
2012-04-18 18:43:45 +08:00
|
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
|
unsigned int i, l, t;
|
|
|
|
|
|
2013-06-15 14:03:30 +08:00
|
|
|
|
l = (unsigned int)(time * (float)_tilesCount);
|
2012-04-19 14:35:52 +08:00
|
|
|
|
|
2013-06-15 14:03:30 +08:00
|
|
|
|
for( i = 0; i < _tilesCount; i++ )
|
2012-04-19 14:35:52 +08:00
|
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
|
t = _tilesOrder[i];
|
|
|
|
|
CCPoint tilePos = ccp( (unsigned int)(t / _gridSize.height), t % (unsigned int)_gridSize.height );
|
2012-04-19 14:35:52 +08:00
|
|
|
|
|
|
|
|
|
if ( i < l )
|
|
|
|
|
{
|
|
|
|
|
turnOffTile(tilePos);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
turnOnTile(tilePos);
|
|
|
|
|
}
|
|
|
|
|
}
|
2012-04-18 18:43:45 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// implementation of CCWavesTiles3D
|
|
|
|
|
|
2012-12-26 18:59:31 +08:00
|
|
|
|
CCWavesTiles3D* CCWavesTiles3D::create(float duration, const CCSize& gridSize, unsigned int waves, float amplitude)
|
2012-04-18 18:43:45 +08:00
|
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
|
CCWavesTiles3D *pAction = new CCWavesTiles3D();
|
|
|
|
|
|
|
|
|
|
if (pAction)
|
|
|
|
|
{
|
2012-12-26 18:59:31 +08:00
|
|
|
|
if (pAction->initWithDuration(duration, gridSize, waves, amplitude))
|
2012-04-19 14:35:52 +08:00
|
|
|
|
{
|
|
|
|
|
pAction->autorelease();
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
CC_SAFE_RELEASE_NULL(pAction);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return pAction;
|
2012-04-18 18:43:45 +08:00
|
|
|
|
}
|
|
|
|
|
|
2012-12-26 18:59:31 +08:00
|
|
|
|
bool CCWavesTiles3D::initWithDuration(float duration, const CCSize& gridSize, unsigned int waves, float amplitude)
|
2012-04-18 18:43:45 +08:00
|
|
|
|
{
|
2012-12-26 18:59:31 +08:00
|
|
|
|
if (CCTiledGrid3DAction::initWithDuration(duration, gridSize))
|
2012-04-19 14:35:52 +08:00
|
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
|
_waves = waves;
|
|
|
|
|
_amplitude = amplitude;
|
|
|
|
|
_amplitudeRate = 1.0f;
|
2011-04-11 11:24:10 +08:00
|
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
|
return true;
|
|
|
|
|
}
|
2011-04-11 11:24:10 +08:00
|
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
|
return false;
|
2012-04-18 18:43:45 +08:00
|
|
|
|
}
|
2011-04-11 11:24:10 +08:00
|
|
|
|
|
2013-06-16 10:44:39 +08:00
|
|
|
|
CCWavesTiles3D* CCWavesTiles3D::clone() const
|
|
|
|
|
{
|
|
|
|
|
auto a = new CCWavesTiles3D(*this);
|
2013-06-19 00:59:34 +08:00
|
|
|
|
a->initWithDuration(_duration, _gridSize, _waves, _amplitude);
|
2013-06-16 10:44:39 +08:00
|
|
|
|
a->autorelease();
|
|
|
|
|
return a;
|
|
|
|
|
}
|
|
|
|
|
|
2012-04-18 18:43:45 +08:00
|
|
|
|
CCObject* CCWavesTiles3D::copyWithZone(CCZone *pZone)
|
|
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
|
CCZone* pNewZone = NULL;
|
|
|
|
|
CCWavesTiles3D* pCopy = NULL;
|
2013-06-15 14:03:30 +08:00
|
|
|
|
if(pZone && pZone->_copyObject)
|
2012-04-19 14:35:52 +08:00
|
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
|
pCopy = (CCWavesTiles3D*)(pZone->_copyObject);
|
2012-04-19 14:35:52 +08:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
pCopy = new CCWavesTiles3D();
|
|
|
|
|
pZone = pNewZone = new CCZone(pCopy);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
CCTiledGrid3DAction::copyWithZone(pZone);
|
|
|
|
|
|
2013-06-15 14:03:30 +08:00
|
|
|
|
pCopy->initWithDuration(_duration, _gridSize, _waves, _amplitude);
|
2012-04-19 14:35:52 +08:00
|
|
|
|
|
|
|
|
|
CC_SAFE_DELETE(pNewZone);
|
|
|
|
|
return pCopy;
|
2012-04-18 18:43:45 +08:00
|
|
|
|
}
|
2011-04-11 11:24:10 +08:00
|
|
|
|
|
2012-06-08 13:55:28 +08:00
|
|
|
|
void CCWavesTiles3D::update(float time)
|
2012-04-18 18:43:45 +08:00
|
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
|
int i, j;
|
|
|
|
|
|
2013-06-15 14:03:30 +08:00
|
|
|
|
for( i = 0; i < _gridSize.width; i++ )
|
2012-04-19 14:35:52 +08:00
|
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
|
for( j = 0; j < _gridSize.height; j++ )
|
2012-04-19 14:35:52 +08:00
|
|
|
|
{
|
2012-12-26 18:59:31 +08:00
|
|
|
|
ccQuad3 coords = originalTile(ccp(i, j));
|
2012-04-19 14:35:52 +08:00
|
|
|
|
|
2013-06-15 14:03:30 +08:00
|
|
|
|
coords.bl.z = (sinf(time * (float)M_PI *_waves * 2 +
|
|
|
|
|
(coords.bl.y+coords.bl.x) * .01f) * _amplitude * _amplitudeRate );
|
2012-04-19 14:35:52 +08:00
|
|
|
|
coords.br.z = coords.bl.z;
|
|
|
|
|
coords.tl.z = coords.bl.z;
|
|
|
|
|
coords.tr.z = coords.bl.z;
|
|
|
|
|
|
2012-12-26 18:59:31 +08:00
|
|
|
|
setTile(ccp(i, j), coords);
|
2012-04-19 14:35:52 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
2012-04-18 18:43:45 +08:00
|
|
|
|
}
|
2011-04-11 11:24:10 +08:00
|
|
|
|
|
2012-04-18 18:43:45 +08:00
|
|
|
|
// implementation of CCJumpTiles3D
|
|
|
|
|
|
2012-12-26 18:59:31 +08:00
|
|
|
|
CCJumpTiles3D* CCJumpTiles3D::create(float duration, const CCSize& gridSize, unsigned int numberOfJumps, float amplitude)
|
2012-04-18 18:43:45 +08:00
|
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
|
CCJumpTiles3D *pAction = new CCJumpTiles3D();
|
|
|
|
|
|
|
|
|
|
if (pAction)
|
|
|
|
|
{
|
2012-12-26 18:59:31 +08:00
|
|
|
|
if (pAction->initWithDuration(duration, gridSize, numberOfJumps, amplitude))
|
2012-04-19 14:35:52 +08:00
|
|
|
|
{
|
|
|
|
|
pAction->autorelease();
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
CC_SAFE_RELEASE_NULL(pAction);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return pAction;
|
2012-04-18 18:43:45 +08:00
|
|
|
|
}
|
2011-04-11 11:24:10 +08:00
|
|
|
|
|
2012-12-26 18:59:31 +08:00
|
|
|
|
bool CCJumpTiles3D::initWithDuration(float duration, const CCSize& gridSize, unsigned int numberOfJumps, float amplitude)
|
2012-04-18 18:43:45 +08:00
|
|
|
|
{
|
2012-12-26 18:59:31 +08:00
|
|
|
|
if (CCTiledGrid3DAction::initWithDuration(duration, gridSize))
|
2012-04-19 14:35:52 +08:00
|
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
|
_jumps = numberOfJumps;
|
|
|
|
|
_amplitude = amplitude;
|
|
|
|
|
_amplitudeRate = 1.0f;
|
2011-04-11 11:24:10 +08:00
|
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
|
return true;
|
|
|
|
|
}
|
2011-04-11 11:24:10 +08:00
|
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
|
return false;
|
2012-04-18 18:43:45 +08:00
|
|
|
|
}
|
2011-04-11 11:24:10 +08:00
|
|
|
|
|
2013-06-16 10:44:39 +08:00
|
|
|
|
CCJumpTiles3D* CCJumpTiles3D::clone() const
|
|
|
|
|
{
|
|
|
|
|
auto a = new CCJumpTiles3D(*this);
|
2013-06-19 00:59:34 +08:00
|
|
|
|
a->initWithDuration(_duration, _gridSize, _jumps, _amplitude);
|
2013-06-16 10:44:39 +08:00
|
|
|
|
a->autorelease();
|
|
|
|
|
return a;
|
|
|
|
|
}
|
|
|
|
|
|
2012-04-18 18:43:45 +08:00
|
|
|
|
CCObject* CCJumpTiles3D::copyWithZone(CCZone *pZone)
|
|
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
|
CCZone* pNewZone = NULL;
|
|
|
|
|
CCJumpTiles3D* pCopy = NULL;
|
2013-06-15 14:03:30 +08:00
|
|
|
|
if(pZone && pZone->_copyObject)
|
2012-04-19 14:35:52 +08:00
|
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
|
pCopy = (CCJumpTiles3D*)(pZone->_copyObject);
|
2012-04-19 14:35:52 +08:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
pCopy = new CCJumpTiles3D();
|
|
|
|
|
pZone = pNewZone = new CCZone(pCopy);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
CCTiledGrid3DAction::copyWithZone(pZone);
|
2013-06-15 14:03:30 +08:00
|
|
|
|
pCopy->initWithDuration(_duration, _gridSize, _jumps, _amplitude);
|
2012-04-19 14:35:52 +08:00
|
|
|
|
|
|
|
|
|
CC_SAFE_DELETE(pNewZone);
|
|
|
|
|
return pCopy;
|
2012-04-18 18:43:45 +08:00
|
|
|
|
}
|
2011-04-11 11:24:10 +08:00
|
|
|
|
|
2012-06-08 13:55:28 +08:00
|
|
|
|
void CCJumpTiles3D::update(float time)
|
2012-04-18 18:43:45 +08:00
|
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
|
int i, j;
|
|
|
|
|
|
2013-06-15 14:03:30 +08:00
|
|
|
|
float sinz = (sinf((float)M_PI * time * _jumps * 2) * _amplitude * _amplitudeRate );
|
|
|
|
|
float sinz2 = (sinf((float)M_PI * (time * _jumps * 2 + 1)) * _amplitude * _amplitudeRate );
|
2012-04-19 14:35:52 +08:00
|
|
|
|
|
2013-06-15 14:03:30 +08:00
|
|
|
|
for( i = 0; i < _gridSize.width; i++ )
|
2012-04-19 14:35:52 +08:00
|
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
|
for( j = 0; j < _gridSize.height; j++ )
|
2012-04-19 14:35:52 +08:00
|
|
|
|
{
|
2012-12-26 18:59:31 +08:00
|
|
|
|
ccQuad3 coords = originalTile(ccp(i, j));
|
2012-04-19 14:35:52 +08:00
|
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
|
2012-12-26 18:59:31 +08:00
|
|
|
|
setTile(ccp(i, j), coords);
|
2012-04-19 14:35:52 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
2012-04-18 18:43:45 +08:00
|
|
|
|
}
|
2011-04-11 11:24:10 +08:00
|
|
|
|
|
2012-04-18 18:43:45 +08:00
|
|
|
|
// implementation of CCSplitRows
|
2011-04-11 11:24:10 +08:00
|
|
|
|
|
2012-12-26 18:59:31 +08:00
|
|
|
|
CCSplitRows* CCSplitRows::create(float duration, unsigned int nRows)
|
2012-04-18 18:43:45 +08:00
|
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
|
CCSplitRows *pAction = new CCSplitRows();
|
|
|
|
|
|
|
|
|
|
if (pAction)
|
|
|
|
|
{
|
2012-12-26 18:59:31 +08:00
|
|
|
|
if (pAction->initWithDuration(duration, nRows))
|
2012-04-19 14:35:52 +08:00
|
|
|
|
{
|
|
|
|
|
pAction->autorelease();
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
CC_SAFE_RELEASE_NULL(pAction);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return pAction;
|
2012-04-18 18:43:45 +08:00
|
|
|
|
}
|
2011-04-11 11:24:10 +08:00
|
|
|
|
|
2012-12-26 18:59:31 +08:00
|
|
|
|
bool CCSplitRows::initWithDuration(float duration, unsigned int nRows)
|
2012-04-18 18:43:45 +08:00
|
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
|
_rows = nRows;
|
2011-04-11 11:24:10 +08:00
|
|
|
|
|
2012-12-26 18:59:31 +08:00
|
|
|
|
return CCTiledGrid3DAction::initWithDuration(duration, CCSizeMake(1, nRows));
|
2012-04-18 18:43:45 +08:00
|
|
|
|
}
|
2011-04-11 11:24:10 +08:00
|
|
|
|
|
2013-06-16 10:44:39 +08:00
|
|
|
|
CCSplitRows* CCSplitRows::clone() const
|
|
|
|
|
{
|
|
|
|
|
auto a = new CCSplitRows(*this);
|
2013-06-19 00:59:34 +08:00
|
|
|
|
a->initWithDuration(_duration, _rows);
|
2013-06-16 10:44:39 +08:00
|
|
|
|
a->autorelease();
|
|
|
|
|
return a;
|
|
|
|
|
}
|
|
|
|
|
|
2012-04-18 18:43:45 +08:00
|
|
|
|
CCObject* CCSplitRows::copyWithZone(CCZone *pZone)
|
|
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
|
CCZone* pNewZone = NULL;
|
|
|
|
|
CCSplitRows* pCopy = NULL;
|
2013-06-15 14:03:30 +08:00
|
|
|
|
if(pZone && pZone->_copyObject)
|
2012-04-19 14:35:52 +08:00
|
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
|
pCopy = (CCSplitRows*)(pZone->_copyObject);
|
2012-04-19 14:35:52 +08:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
pCopy = new CCSplitRows();
|
|
|
|
|
pZone = pNewZone = new CCZone(pCopy);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
CCTiledGrid3DAction::copyWithZone(pZone);
|
|
|
|
|
|
2013-06-15 14:03:30 +08:00
|
|
|
|
pCopy->initWithDuration(_duration, _rows);
|
2012-04-19 14:35:52 +08:00
|
|
|
|
|
|
|
|
|
CC_SAFE_DELETE(pNewZone);
|
|
|
|
|
return pCopy;
|
2012-04-18 18:43:45 +08:00
|
|
|
|
}
|
2011-04-11 11:24:10 +08:00
|
|
|
|
|
2012-04-18 18:43:45 +08:00
|
|
|
|
void CCSplitRows::startWithTarget(CCNode *pTarget)
|
|
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
|
CCTiledGrid3DAction::startWithTarget(pTarget);
|
2013-06-15 14:03:30 +08:00
|
|
|
|
_winSize = CCDirector::sharedDirector()->getWinSizeInPixels();
|
2012-04-18 18:43:45 +08:00
|
|
|
|
}
|
2011-04-11 11:24:10 +08:00
|
|
|
|
|
2012-06-08 13:55:28 +08:00
|
|
|
|
void CCSplitRows::update(float time)
|
2012-04-18 18:43:45 +08:00
|
|
|
|
{
|
2012-12-26 18:59:31 +08:00
|
|
|
|
unsigned int j;
|
2011-04-11 11:24:10 +08:00
|
|
|
|
|
2013-06-15 14:03:30 +08:00
|
|
|
|
for (j = 0; j < _gridSize.height; ++j)
|
2012-04-19 14:35:52 +08:00
|
|
|
|
{
|
2012-12-26 18:59:31 +08:00
|
|
|
|
ccQuad3 coords = originalTile(ccp(0, j));
|
2012-04-19 14:35:52 +08:00
|
|
|
|
float direction = 1;
|
2011-04-11 11:24:10 +08:00
|
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
|
if ( (j % 2 ) == 0 )
|
|
|
|
|
{
|
|
|
|
|
direction = -1;
|
|
|
|
|
}
|
2011-04-11 11:24:10 +08:00
|
|
|
|
|
2013-06-15 14:03:30 +08:00
|
|
|
|
coords.bl.x += direction * _winSize.width * time;
|
|
|
|
|
coords.br.x += direction * _winSize.width * time;
|
|
|
|
|
coords.tl.x += direction * _winSize.width * time;
|
|
|
|
|
coords.tr.x += direction * _winSize.width * time;
|
2011-04-11 11:24:10 +08:00
|
|
|
|
|
2012-12-26 18:59:31 +08:00
|
|
|
|
setTile(ccp(0, j), coords);
|
2012-04-19 14:35:52 +08:00
|
|
|
|
}
|
2012-04-18 18:43:45 +08:00
|
|
|
|
}
|
2011-04-11 11:24:10 +08:00
|
|
|
|
|
2012-04-18 18:43:45 +08:00
|
|
|
|
// implementation of CCSplitCols
|
|
|
|
|
|
2012-12-26 18:59:31 +08:00
|
|
|
|
CCSplitCols* CCSplitCols::create(float duration, unsigned int nCols)
|
2012-04-18 18:43:45 +08:00
|
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
|
CCSplitCols *pAction = new CCSplitCols();
|
|
|
|
|
|
|
|
|
|
if (pAction)
|
|
|
|
|
{
|
2012-12-26 18:59:31 +08:00
|
|
|
|
if (pAction->initWithDuration(duration, nCols))
|
2012-04-19 14:35:52 +08:00
|
|
|
|
{
|
|
|
|
|
pAction->autorelease();
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
CC_SAFE_RELEASE_NULL(pAction);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return pAction;
|
2012-04-18 18:43:45 +08:00
|
|
|
|
}
|
2011-04-11 11:24:10 +08:00
|
|
|
|
|
2012-12-26 18:59:31 +08:00
|
|
|
|
bool CCSplitCols::initWithDuration(float duration, unsigned int nCols)
|
2012-04-18 18:43:45 +08:00
|
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
|
_cols = nCols;
|
2012-12-26 18:59:31 +08:00
|
|
|
|
return CCTiledGrid3DAction::initWithDuration(duration, CCSizeMake(nCols, 1));
|
2012-04-18 18:43:45 +08:00
|
|
|
|
}
|
2011-04-11 11:24:10 +08:00
|
|
|
|
|
2013-06-16 10:44:39 +08:00
|
|
|
|
CCSplitCols* CCSplitCols::clone() const
|
|
|
|
|
{
|
|
|
|
|
auto a = new CCSplitCols(*this);
|
2013-06-19 00:59:34 +08:00
|
|
|
|
a->initWithDuration(_duration, _cols);
|
2013-06-16 10:44:39 +08:00
|
|
|
|
a->autorelease();
|
|
|
|
|
return a;
|
|
|
|
|
}
|
|
|
|
|
|
2012-04-18 18:43:45 +08:00
|
|
|
|
CCObject* CCSplitCols::copyWithZone(CCZone *pZone)
|
|
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
|
CCZone* pNewZone = NULL;
|
|
|
|
|
CCSplitCols* pCopy = NULL;
|
2013-06-15 14:03:30 +08:00
|
|
|
|
if(pZone && pZone->_copyObject)
|
2012-04-19 14:35:52 +08:00
|
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
|
pCopy = (CCSplitCols*)(pZone->_copyObject);
|
2012-04-19 14:35:52 +08:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
pCopy = new CCSplitCols();
|
|
|
|
|
pZone = pNewZone = new CCZone(pCopy);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
CCTiledGrid3DAction::copyWithZone(pZone);
|
2013-06-15 14:03:30 +08:00
|
|
|
|
pCopy->initWithDuration(_duration, _cols);
|
2012-04-19 14:35:52 +08:00
|
|
|
|
|
|
|
|
|
CC_SAFE_DELETE(pNewZone);
|
|
|
|
|
return pCopy;
|
2012-04-18 18:43:45 +08:00
|
|
|
|
}
|
2011-04-11 11:24:10 +08:00
|
|
|
|
|
2012-04-18 18:43:45 +08:00
|
|
|
|
void CCSplitCols::startWithTarget(CCNode *pTarget)
|
|
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
|
CCTiledGrid3DAction::startWithTarget(pTarget);
|
2013-06-15 14:03:30 +08:00
|
|
|
|
_winSize = CCDirector::sharedDirector()->getWinSizeInPixels();
|
2012-04-18 18:43:45 +08:00
|
|
|
|
}
|
|
|
|
|
|
2012-06-08 13:55:28 +08:00
|
|
|
|
void CCSplitCols::update(float time)
|
2012-04-18 18:43:45 +08:00
|
|
|
|
{
|
2012-12-26 18:59:31 +08:00
|
|
|
|
unsigned int i;
|
2011-04-11 11:24:10 +08:00
|
|
|
|
|
2013-06-15 14:03:30 +08:00
|
|
|
|
for (i = 0; i < _gridSize.width; ++i)
|
2012-04-19 14:35:52 +08:00
|
|
|
|
{
|
2012-12-26 18:59:31 +08:00
|
|
|
|
ccQuad3 coords = originalTile(ccp(i, 0));
|
2012-04-19 14:35:52 +08:00
|
|
|
|
float direction = 1;
|
2012-04-18 18:43:45 +08:00
|
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
|
if ( (i % 2 ) == 0 )
|
|
|
|
|
{
|
|
|
|
|
direction = -1;
|
|
|
|
|
}
|
2011-04-11 11:24:10 +08:00
|
|
|
|
|
2013-06-15 14:03:30 +08:00
|
|
|
|
coords.bl.y += direction * _winSize.height * time;
|
|
|
|
|
coords.br.y += direction * _winSize.height * time;
|
|
|
|
|
coords.tl.y += direction * _winSize.height * time;
|
|
|
|
|
coords.tr.y += direction * _winSize.height * time;
|
2012-04-18 18:43:45 +08:00
|
|
|
|
|
2012-12-26 18:59:31 +08:00
|
|
|
|
setTile(ccp(i, 0), coords);
|
2012-04-19 14:35:52 +08:00
|
|
|
|
}
|
2012-04-18 18:43:45 +08:00
|
|
|
|
}
|
2011-04-11 11:24:10 +08:00
|
|
|
|
|
2013-03-03 10:32:09 +08:00
|
|
|
|
NS_CC_END
|