2012-04-19 14:35:52 +08:00
|
|
|
/****************************************************************************
|
2012-09-24 21:22:20 +08:00
|
|
|
Copyright (c) 2010-2012 cocos2d-x.org
|
2012-04-19 14:35:52 +08:00
|
|
|
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 "CCActionGrid.h"
|
|
|
|
#include "CCDirector.h"
|
|
|
|
#include "effects/CCGrid.h"
|
2012-06-19 16:20:46 +08:00
|
|
|
#include "cocoa/CCZone.h"
|
2012-04-19 14:35:52 +08:00
|
|
|
|
|
|
|
NS_CC_BEGIN
|
|
|
|
// implementation of CCGridAction
|
|
|
|
|
2012-12-26 18:59:31 +08:00
|
|
|
bool CCGridAction::initWithDuration(float duration, const CCSize& gridSize)
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
|
|
|
if (CCActionInterval::initWithDuration(duration))
|
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
_gridSize = gridSize;
|
2012-04-19 14:35:52 +08:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
void CCGridAction::startWithTarget(CCNode *pTarget)
|
|
|
|
{
|
|
|
|
CCActionInterval::startWithTarget(pTarget);
|
|
|
|
|
|
|
|
CCGridBase *newgrid = this->getGrid();
|
|
|
|
|
2013-06-15 14:03:30 +08:00
|
|
|
CCNode *t = _target;
|
2012-04-19 14:35:52 +08:00
|
|
|
CCGridBase *targetGrid = t->getGrid();
|
|
|
|
|
|
|
|
if (targetGrid && targetGrid->getReuseGrid() > 0)
|
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
if (targetGrid->isActive() && targetGrid->getGridSize().width == _gridSize.width
|
|
|
|
&& targetGrid->getGridSize().height == _gridSize.height /*&& dynamic_cast<CCGridBase*>(targetGrid) != NULL*/)
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
|
|
|
targetGrid->reuse();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
CCAssert(0, "");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (targetGrid && targetGrid->isActive())
|
|
|
|
{
|
|
|
|
targetGrid->setActive(false);
|
|
|
|
}
|
|
|
|
|
|
|
|
t->setGrid(newgrid);
|
|
|
|
t->getGrid()->setActive(true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-06-16 09:54:34 +08:00
|
|
|
CCGridAction* CCGridAction::reverse() const
|
|
|
|
{
|
|
|
|
return (CCGridAction*)CCReverseTime::create( this->clone() );
|
|
|
|
}
|
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
CCGridBase* CCGridAction::getGrid(void)
|
|
|
|
{
|
|
|
|
// Abstract class needs implementation
|
|
|
|
CCAssert(0, "");
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
// implementation of Grid3DAction
|
|
|
|
|
|
|
|
CCGridBase* CCGrid3DAction::getGrid(void)
|
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
return CCGrid3D::create(_gridSize);
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
|
|
|
|
2012-12-26 18:59:31 +08:00
|
|
|
ccVertex3F CCGrid3DAction::vertex(const CCPoint& position)
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
CCGrid3D *g = (CCGrid3D*)_target->getGrid();
|
2012-12-26 18:59:31 +08:00
|
|
|
return g->vertex(position);
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
|
|
|
|
2012-12-26 18:59:31 +08:00
|
|
|
ccVertex3F CCGrid3DAction::originalVertex(const CCPoint& position)
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
CCGrid3D *g = (CCGrid3D*)_target->getGrid();
|
2012-12-26 18:59:31 +08:00
|
|
|
return g->originalVertex(position);
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
|
|
|
|
2012-12-26 18:59:31 +08:00
|
|
|
void CCGrid3DAction::setVertex(const CCPoint& position, const ccVertex3F& vertex)
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
CCGrid3D *g = (CCGrid3D*)_target->getGrid();
|
2012-12-26 18:59:31 +08:00
|
|
|
g->setVertex(position, vertex);
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// implementation of TiledGrid3DAction
|
|
|
|
|
|
|
|
CCGridBase* CCTiledGrid3DAction::getGrid(void)
|
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
return CCTiledGrid3D::create(_gridSize);
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
|
|
|
|
2012-12-26 18:59:31 +08:00
|
|
|
ccQuad3 CCTiledGrid3DAction::tile(const CCPoint& pos)
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
CCTiledGrid3D *g = (CCTiledGrid3D*)_target->getGrid();
|
2012-04-19 14:35:52 +08:00
|
|
|
return g->tile(pos);
|
|
|
|
}
|
|
|
|
|
2012-12-26 18:59:31 +08:00
|
|
|
ccQuad3 CCTiledGrid3DAction::originalTile(const CCPoint& pos)
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
CCTiledGrid3D *g = (CCTiledGrid3D*)_target->getGrid();
|
2012-04-19 14:35:52 +08:00
|
|
|
return g->originalTile(pos);
|
|
|
|
}
|
|
|
|
|
2012-12-26 18:59:31 +08:00
|
|
|
void CCTiledGrid3DAction::setTile(const CCPoint& pos, const ccQuad3& coords)
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
CCTiledGrid3D *g = (CCTiledGrid3D*)_target->getGrid();
|
2012-04-19 14:35:52 +08:00
|
|
|
return g->setTile(pos, coords);
|
|
|
|
}
|
|
|
|
|
|
|
|
// implementation CCAccelDeccelAmplitude
|
|
|
|
|
2012-06-14 15:13:16 +08:00
|
|
|
CCAccelDeccelAmplitude* CCAccelDeccelAmplitude::create(CCAction *pAction, float duration)
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
|
|
|
CCAccelDeccelAmplitude *pRet = new CCAccelDeccelAmplitude();
|
|
|
|
if (pRet)
|
|
|
|
{
|
|
|
|
if (pRet->initWithAction(pAction, duration))
|
|
|
|
{
|
|
|
|
pRet->autorelease();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
CC_SAFE_DELETE(pRet);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return pRet;
|
|
|
|
}
|
|
|
|
|
2012-06-08 13:55:28 +08:00
|
|
|
bool CCAccelDeccelAmplitude::initWithAction(CCAction *pAction, float duration)
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
|
|
|
if (CCActionInterval::initWithDuration(duration))
|
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
_rate = 1.0f;
|
|
|
|
_other = (CCActionInterval*)(pAction);
|
2012-04-19 14:35:52 +08:00
|
|
|
pAction->retain();
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2013-06-16 03:38:32 +08:00
|
|
|
CCAccelDeccelAmplitude* CCAccelDeccelAmplitude::clone() const
|
|
|
|
{
|
|
|
|
auto a = new CCAccelDeccelAmplitude(*this);
|
2013-06-19 00:59:34 +08:00
|
|
|
a->initWithAction(_other->clone(), _rate);
|
2013-06-16 03:38:32 +08:00
|
|
|
a->autorelease();
|
|
|
|
return a;
|
|
|
|
}
|
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
CCAccelDeccelAmplitude::~CCAccelDeccelAmplitude(void)
|
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
CC_SAFE_RELEASE(_other);
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void CCAccelDeccelAmplitude::startWithTarget(CCNode *pTarget)
|
|
|
|
{
|
|
|
|
CCActionInterval::startWithTarget(pTarget);
|
2013-06-15 14:03:30 +08:00
|
|
|
_other->startWithTarget(pTarget);
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
|
|
|
|
2012-06-08 13:55:28 +08:00
|
|
|
void CCAccelDeccelAmplitude::update(float time)
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
|
|
|
float f = time * 2;
|
|
|
|
|
|
|
|
if (f > 1)
|
|
|
|
{
|
|
|
|
f -= 1;
|
|
|
|
f = 1 - f;
|
|
|
|
}
|
|
|
|
|
2013-06-15 14:03:30 +08:00
|
|
|
((CCAccelDeccelAmplitude*)(_other))->setAmplitudeRate(powf(f, _rate));
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
|
|
|
|
2013-06-16 09:54:34 +08:00
|
|
|
CCAccelDeccelAmplitude* CCAccelDeccelAmplitude::reverse() const
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
return CCAccelDeccelAmplitude::create(_other->reverse(), _duration);
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// implementation of AccelAmplitude
|
|
|
|
|
2012-06-14 15:13:16 +08:00
|
|
|
CCAccelAmplitude* CCAccelAmplitude::create(CCAction *pAction, float duration)
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
|
|
|
CCAccelAmplitude *pRet = new CCAccelAmplitude();
|
|
|
|
if (pRet)
|
|
|
|
{
|
|
|
|
if (pRet->initWithAction(pAction, duration))
|
|
|
|
{
|
|
|
|
pRet->autorelease();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
CC_SAFE_DELETE(pRet);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return pRet;
|
|
|
|
}
|
|
|
|
|
2012-06-08 13:55:28 +08:00
|
|
|
bool CCAccelAmplitude::initWithAction(CCAction *pAction, float duration)
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
|
|
|
if (CCActionInterval::initWithDuration(duration))
|
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
_rate = 1.0f;
|
|
|
|
_other = (CCActionInterval*)(pAction);
|
2012-04-19 14:35:52 +08:00
|
|
|
pAction->retain();
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2013-06-16 03:38:32 +08:00
|
|
|
CCAccelAmplitude* CCAccelAmplitude::clone() const
|
|
|
|
{
|
|
|
|
auto a = new CCAccelAmplitude(*this);
|
2013-06-19 00:59:34 +08:00
|
|
|
a->initWithAction(_other->clone(), _duration);
|
2013-06-16 03:38:32 +08:00
|
|
|
a->autorelease();
|
|
|
|
return a;
|
|
|
|
}
|
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
CCAccelAmplitude::~CCAccelAmplitude(void)
|
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
CC_SAFE_DELETE(_other);
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void CCAccelAmplitude::startWithTarget(CCNode *pTarget)
|
|
|
|
{
|
|
|
|
CCActionInterval::startWithTarget(pTarget);
|
2013-06-15 14:03:30 +08:00
|
|
|
_other->startWithTarget(pTarget);
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
|
|
|
|
2012-06-08 13:55:28 +08:00
|
|
|
void CCAccelAmplitude::update(float time)
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
((CCAccelAmplitude*)(_other))->setAmplitudeRate(powf(time, _rate));
|
|
|
|
_other->update(time);
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
|
|
|
|
2013-06-16 09:54:34 +08:00
|
|
|
CCAccelAmplitude* CCAccelAmplitude::reverse() const
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
return CCAccelAmplitude::create(_other->reverse(), _duration);
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// DeccelAmplitude
|
|
|
|
|
2012-06-14 15:13:16 +08:00
|
|
|
CCDeccelAmplitude* CCDeccelAmplitude::create(CCAction *pAction, float duration)
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
|
|
|
CCDeccelAmplitude *pRet = new CCDeccelAmplitude();
|
|
|
|
if (pRet)
|
|
|
|
{
|
|
|
|
if (pRet->initWithAction(pAction, duration))
|
|
|
|
{
|
|
|
|
pRet->autorelease();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
CC_SAFE_DELETE(pRet);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return pRet;
|
|
|
|
}
|
|
|
|
|
2012-06-08 13:55:28 +08:00
|
|
|
bool CCDeccelAmplitude::initWithAction(CCAction *pAction, float duration)
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
|
|
|
if (CCActionInterval::initWithDuration(duration))
|
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
_rate = 1.0f;
|
|
|
|
_other = (CCActionInterval*)(pAction);
|
2012-04-19 14:35:52 +08:00
|
|
|
pAction->retain();
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
CCDeccelAmplitude::~CCDeccelAmplitude(void)
|
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
CC_SAFE_RELEASE(_other);
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void CCDeccelAmplitude::startWithTarget(CCNode *pTarget)
|
|
|
|
{
|
|
|
|
CCActionInterval::startWithTarget(pTarget);
|
2013-06-15 14:03:30 +08:00
|
|
|
_other->startWithTarget(pTarget);
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
|
|
|
|
2012-06-08 13:55:28 +08:00
|
|
|
void CCDeccelAmplitude::update(float time)
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
((CCDeccelAmplitude*)(_other))->setAmplitudeRate(powf((1 - time), _rate));
|
|
|
|
_other->update(time);
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
|
|
|
|
2013-06-16 10:44:39 +08:00
|
|
|
CCDeccelAmplitude* CCDeccelAmplitude::clone() const
|
|
|
|
{
|
|
|
|
auto a = new CCDeccelAmplitude(*this);
|
2013-06-19 00:59:34 +08:00
|
|
|
a->initWithAction(_other->clone(), _duration);
|
2013-06-16 10:44:39 +08:00
|
|
|
a->autorelease();
|
|
|
|
return a;
|
|
|
|
}
|
|
|
|
|
2013-06-16 09:54:34 +08:00
|
|
|
CCDeccelAmplitude* CCDeccelAmplitude::reverse() const
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
return CCDeccelAmplitude::create(_other->reverse(), _duration);
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// implementation of StopGrid
|
|
|
|
|
|
|
|
void CCStopGrid::startWithTarget(CCNode *pTarget)
|
|
|
|
{
|
|
|
|
CCActionInstant::startWithTarget(pTarget);
|
|
|
|
|
2013-06-15 14:03:30 +08:00
|
|
|
CCGridBase *pGrid = _target->getGrid();
|
2012-04-19 14:35:52 +08:00
|
|
|
if (pGrid && pGrid->isActive())
|
|
|
|
{
|
|
|
|
pGrid->setActive(false);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-06-14 15:13:16 +08:00
|
|
|
CCStopGrid* CCStopGrid::create(void)
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
|
|
|
CCStopGrid* pAction = new CCStopGrid();
|
|
|
|
pAction->autorelease();
|
|
|
|
|
|
|
|
return pAction;
|
|
|
|
}
|
2013-06-16 10:44:39 +08:00
|
|
|
|
|
|
|
CCStopGrid* CCStopGrid::clone() const
|
|
|
|
{
|
|
|
|
return CCStopGrid::create();
|
|
|
|
}
|
|
|
|
|
|
|
|
CCStopGrid* CCStopGrid::reverse() const
|
|
|
|
{
|
|
|
|
// no reverse, just clone it
|
|
|
|
return this->clone();
|
|
|
|
}
|
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
// implementation of CCReuseGrid
|
|
|
|
|
2012-06-14 15:13:16 +08:00
|
|
|
CCReuseGrid* CCReuseGrid::create(int times)
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
|
|
|
CCReuseGrid *pAction = new CCReuseGrid();
|
|
|
|
if (pAction)
|
|
|
|
{
|
|
|
|
if (pAction->initWithTimes(times))
|
|
|
|
{
|
|
|
|
pAction->autorelease();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
CC_SAFE_DELETE(pAction);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return pAction;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CCReuseGrid::initWithTimes(int times)
|
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
_times = times;
|
2012-04-19 14:35:52 +08:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void CCReuseGrid::startWithTarget(CCNode *pTarget)
|
|
|
|
{
|
|
|
|
CCActionInstant::startWithTarget(pTarget);
|
|
|
|
|
2013-06-15 14:03:30 +08:00
|
|
|
if (_target->getGrid() && _target->getGrid()->isActive())
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
_target->getGrid()->setReuseGrid(_target->getGrid()->getReuseGrid() + _times);
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-06-16 10:44:39 +08:00
|
|
|
CCReuseGrid* CCReuseGrid::clone() const
|
|
|
|
{
|
2013-06-19 00:59:34 +08:00
|
|
|
return CCReuseGrid::create(_times);
|
2013-06-16 10:44:39 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
CCReuseGrid* CCReuseGrid::reverse() const
|
|
|
|
{
|
|
|
|
// no reverse, just clone it
|
|
|
|
return this->clone();
|
|
|
|
}
|
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
NS_CC_END
|