2012-04-19 14:35:52 +08:00
|
|
|
/****************************************************************************
|
2014-01-07 11:25:07 +08:00
|
|
|
Copyright (c) 2009 On-Core
|
2012-09-24 21:22:20 +08:00
|
|
|
Copyright (c) 2010-2012 cocos2d-x.org
|
2014-01-07 11:25:07 +08:00
|
|
|
Copyright (c) 2013-2014 Chukong Technologies Inc.
|
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
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.
|
|
|
|
****************************************************************************/
|
2014-04-27 01:11:22 +08:00
|
|
|
#include "2d/CCActionGrid.h"
|
|
|
|
#include "2d/CCDirector.h"
|
2013-10-14 14:01:00 +08:00
|
|
|
#include "CCGrid.h"
|
2013-12-16 14:21:05 +08:00
|
|
|
#include "CCNodeGrid.h"
|
2012-04-19 14:35:52 +08:00
|
|
|
|
|
|
|
NS_CC_BEGIN
|
2013-06-20 14:13:12 +08:00
|
|
|
// implementation of GridAction
|
2012-04-19 14:35:52 +08:00
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
bool GridAction::initWithDuration(float duration, const Size& gridSize)
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
2013-06-20 14:13:12 +08:00
|
|
|
if (ActionInterval::initWithDuration(duration))
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
_gridSize = gridSize;
|
2012-04-19 14:35:52 +08:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2013-07-18 07:56:19 +08:00
|
|
|
void GridAction::startWithTarget(Node *target)
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
2013-07-18 07:56:19 +08:00
|
|
|
ActionInterval::startWithTarget(target);
|
2013-12-12 16:20:52 +08:00
|
|
|
cacheTargetAsGridNode();
|
2012-04-19 14:35:52 +08:00
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
GridBase *newgrid = this->getGrid();
|
2012-04-19 14:35:52 +08:00
|
|
|
|
2013-12-16 14:21:05 +08:00
|
|
|
GridBase *targetGrid = _gridNodeTarget->getGrid();
|
2012-04-19 14:35:52 +08:00
|
|
|
|
|
|
|
if (targetGrid && targetGrid->getReuseGrid() > 0)
|
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
if (targetGrid->isActive() && targetGrid->getGridSize().width == _gridSize.width
|
2013-12-18 17:47:20 +08:00
|
|
|
&& targetGrid->getGridSize().height == _gridSize.height /*&& dynamic_cast<GridBase*>(targetGrid) != nullptr*/)
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
|
|
|
targetGrid->reuse();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2013-07-20 13:01:27 +08:00
|
|
|
CCASSERT(0, "");
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (targetGrid && targetGrid->isActive())
|
|
|
|
{
|
|
|
|
targetGrid->setActive(false);
|
|
|
|
}
|
|
|
|
|
2013-12-16 14:21:05 +08:00
|
|
|
_gridNodeTarget->setGrid(newgrid);
|
|
|
|
_gridNodeTarget->getGrid()->setActive(true);
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-12-12 16:20:52 +08:00
|
|
|
void GridAction::cacheTargetAsGridNode()
|
|
|
|
{
|
2013-12-16 14:21:05 +08:00
|
|
|
_gridNodeTarget = dynamic_cast<NodeGrid*> (_target);
|
|
|
|
CCASSERT(_gridNodeTarget, "GridActions can only used on NodeGrid");
|
2013-12-12 16:20:52 +08:00
|
|
|
}
|
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
GridAction* GridAction::reverse() const
|
2013-06-16 09:54:34 +08:00
|
|
|
{
|
2013-07-10 14:17:42 +08:00
|
|
|
// FIXME: This conversion isn't safe.
|
2013-06-20 14:13:12 +08:00
|
|
|
return (GridAction*)ReverseTime::create( this->clone() );
|
2013-06-16 09:54:34 +08:00
|
|
|
}
|
|
|
|
|
2013-11-16 21:08:00 +08:00
|
|
|
GridBase* GridAction::getGrid()
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
|
|
|
// Abstract class needs implementation
|
2013-07-20 13:01:27 +08:00
|
|
|
CCASSERT(0, "");
|
2012-04-19 14:35:52 +08:00
|
|
|
|
2013-11-16 21:08:00 +08:00
|
|
|
return nullptr;
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// implementation of Grid3DAction
|
|
|
|
|
2013-11-16 21:08:00 +08:00
|
|
|
GridBase* Grid3DAction::getGrid()
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
2013-06-20 14:13:12 +08:00
|
|
|
return Grid3D::create(_gridSize);
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
|
|
|
|
2014-04-15 18:13:57 +08:00
|
|
|
Vector3 Grid3DAction::getVertex(const Vector2& position) const
|
2013-07-08 15:12:06 +08:00
|
|
|
{
|
2013-12-16 14:21:05 +08:00
|
|
|
Grid3D *g = (Grid3D*)_gridNodeTarget->getGrid();
|
2013-07-08 15:12:06 +08:00
|
|
|
return g->getVertex(position);
|
|
|
|
}
|
|
|
|
|
2014-04-15 18:13:57 +08:00
|
|
|
Vector3 Grid3DAction::getOriginalVertex(const Vector2& position) const
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
2013-12-16 14:21:05 +08:00
|
|
|
Grid3D *g = (Grid3D*)_gridNodeTarget->getGrid();
|
2013-07-08 15:12:06 +08:00
|
|
|
return g->getOriginalVertex(position);
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
|
|
|
|
2014-04-15 18:13:57 +08:00
|
|
|
void Grid3DAction::setVertex(const Vector2& position, const Vector3& vertex)
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
2013-12-16 14:21:05 +08:00
|
|
|
Grid3D *g = (Grid3D*)_gridNodeTarget->getGrid();
|
2012-12-26 18:59:31 +08:00
|
|
|
g->setVertex(position, vertex);
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// implementation of TiledGrid3DAction
|
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
GridBase* TiledGrid3DAction::getGrid(void)
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
2013-06-20 14:13:12 +08:00
|
|
|
return TiledGrid3D::create(_gridSize);
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
|
|
|
|
2014-04-15 18:13:57 +08:00
|
|
|
Quad3 TiledGrid3DAction::getTile(const Vector2& pos) const
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
2013-12-16 14:21:05 +08:00
|
|
|
TiledGrid3D *g = (TiledGrid3D*)_gridNodeTarget->getGrid();
|
2013-07-10 14:17:42 +08:00
|
|
|
return g->getTile(pos);
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
|
|
|
|
2014-04-15 18:13:57 +08:00
|
|
|
Quad3 TiledGrid3DAction::getOriginalTile(const Vector2& pos) const
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
2013-12-16 14:21:05 +08:00
|
|
|
TiledGrid3D *g = (TiledGrid3D*)_gridNodeTarget->getGrid();
|
2013-07-10 14:17:42 +08:00
|
|
|
return g->getOriginalTile(pos);
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
|
|
|
|
2014-04-15 18:13:57 +08:00
|
|
|
void TiledGrid3DAction::setTile(const Vector2& pos, const Quad3& coords)
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
2013-12-16 14:21:05 +08:00
|
|
|
TiledGrid3D *g = (TiledGrid3D*)_gridNodeTarget->getGrid();
|
2012-04-19 14:35:52 +08:00
|
|
|
return g->setTile(pos, coords);
|
|
|
|
}
|
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
// implementation AccelDeccelAmplitude
|
2012-04-19 14:35:52 +08:00
|
|
|
|
2013-11-16 21:08:00 +08:00
|
|
|
AccelDeccelAmplitude* AccelDeccelAmplitude::create(Action *action, float duration)
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
2013-11-16 21:08:00 +08:00
|
|
|
AccelDeccelAmplitude *ret = new AccelDeccelAmplitude();
|
|
|
|
if (ret)
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
2013-11-16 21:08:00 +08:00
|
|
|
if (ret->initWithAction(action, duration))
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
2013-11-16 21:08:00 +08:00
|
|
|
ret->autorelease();
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2013-11-16 21:08:00 +08:00
|
|
|
CC_SAFE_DELETE(ret);
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-11-16 21:08:00 +08:00
|
|
|
return ret;
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
|
|
|
|
2013-11-16 21:08:00 +08:00
|
|
|
bool AccelDeccelAmplitude::initWithAction(Action *action, float duration)
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
2013-06-20 14:13:12 +08:00
|
|
|
if (ActionInterval::initWithDuration(duration))
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
_rate = 1.0f;
|
2013-11-16 21:08:00 +08:00
|
|
|
_other = (ActionInterval*)(action);
|
|
|
|
action->retain();
|
2012-04-19 14:35:52 +08:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
AccelDeccelAmplitude* AccelDeccelAmplitude::clone() const
|
2013-06-16 03:38:32 +08:00
|
|
|
{
|
2013-06-19 06:06:53 +08:00
|
|
|
// no copy constructor
|
2013-06-20 14:13:12 +08:00
|
|
|
auto a = new AccelDeccelAmplitude();
|
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;
|
|
|
|
}
|
|
|
|
|
2013-11-16 21:08:00 +08:00
|
|
|
AccelDeccelAmplitude::~AccelDeccelAmplitude()
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
CC_SAFE_RELEASE(_other);
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
|
|
|
|
2013-07-18 07:56:19 +08:00
|
|
|
void AccelDeccelAmplitude::startWithTarget(Node *target)
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
2013-07-18 07:56:19 +08:00
|
|
|
ActionInterval::startWithTarget(target);
|
|
|
|
_other->startWithTarget(target);
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
void AccelDeccelAmplitude::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-20 14:13:12 +08:00
|
|
|
((AccelDeccelAmplitude*)(_other))->setAmplitudeRate(powf(f, _rate));
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
AccelDeccelAmplitude* AccelDeccelAmplitude::reverse() const
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
2013-06-20 14:13:12 +08:00
|
|
|
return AccelDeccelAmplitude::create(_other->reverse(), _duration);
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// implementation of AccelAmplitude
|
|
|
|
|
2013-11-16 21:08:00 +08:00
|
|
|
AccelAmplitude* AccelAmplitude::create(Action *action, float duration)
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
2013-11-16 21:08:00 +08:00
|
|
|
AccelAmplitude *ret = new AccelAmplitude();
|
|
|
|
if (ret)
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
2013-11-16 21:08:00 +08:00
|
|
|
if (ret->initWithAction(action, duration))
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
2013-11-16 21:08:00 +08:00
|
|
|
ret->autorelease();
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2013-11-16 21:08:00 +08:00
|
|
|
CC_SAFE_DELETE(ret);
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-11-16 21:08:00 +08:00
|
|
|
return ret;
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
|
|
|
|
2013-11-16 21:08:00 +08:00
|
|
|
bool AccelAmplitude::initWithAction(Action *action, float duration)
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
2013-06-20 14:13:12 +08:00
|
|
|
if (ActionInterval::initWithDuration(duration))
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
_rate = 1.0f;
|
2013-11-16 21:08:00 +08:00
|
|
|
_other = (ActionInterval*)(action);
|
|
|
|
action->retain();
|
2012-04-19 14:35:52 +08:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
AccelAmplitude* AccelAmplitude::clone() const
|
2013-06-16 03:38:32 +08:00
|
|
|
{
|
2013-06-19 06:06:53 +08:00
|
|
|
// no copy constructor
|
2013-06-20 14:13:12 +08:00
|
|
|
auto a = new AccelAmplitude();
|
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;
|
|
|
|
}
|
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
AccelAmplitude::~AccelAmplitude(void)
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
CC_SAFE_DELETE(_other);
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
|
|
|
|
2013-07-18 07:56:19 +08:00
|
|
|
void AccelAmplitude::startWithTarget(Node *target)
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
2013-07-18 07:56:19 +08:00
|
|
|
ActionInterval::startWithTarget(target);
|
|
|
|
_other->startWithTarget(target);
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
void AccelAmplitude::update(float time)
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
2013-06-20 14:13:12 +08:00
|
|
|
((AccelAmplitude*)(_other))->setAmplitudeRate(powf(time, _rate));
|
2013-06-15 14:03:30 +08:00
|
|
|
_other->update(time);
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
AccelAmplitude* AccelAmplitude::reverse() const
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
2013-06-20 14:13:12 +08:00
|
|
|
return AccelAmplitude::create(_other->reverse(), _duration);
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// DeccelAmplitude
|
|
|
|
|
2013-11-16 21:08:00 +08:00
|
|
|
DeccelAmplitude* DeccelAmplitude::create(Action *action, float duration)
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
2013-11-16 21:08:00 +08:00
|
|
|
DeccelAmplitude *ret = new DeccelAmplitude();
|
|
|
|
if (ret)
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
2013-11-16 21:08:00 +08:00
|
|
|
if (ret->initWithAction(action, duration))
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
2013-11-16 21:08:00 +08:00
|
|
|
ret->autorelease();
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2013-11-16 21:08:00 +08:00
|
|
|
CC_SAFE_DELETE(ret);
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-11-16 21:08:00 +08:00
|
|
|
return ret;
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
|
|
|
|
2013-11-16 21:08:00 +08:00
|
|
|
bool DeccelAmplitude::initWithAction(Action *action, float duration)
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
2013-06-20 14:13:12 +08:00
|
|
|
if (ActionInterval::initWithDuration(duration))
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
_rate = 1.0f;
|
2013-11-16 21:08:00 +08:00
|
|
|
_other = (ActionInterval*)(action);
|
|
|
|
action->retain();
|
2012-04-19 14:35:52 +08:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2013-11-16 21:08:00 +08:00
|
|
|
DeccelAmplitude::~DeccelAmplitude()
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
CC_SAFE_RELEASE(_other);
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
|
|
|
|
2013-07-18 07:56:19 +08:00
|
|
|
void DeccelAmplitude::startWithTarget(Node *target)
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
2013-07-18 07:56:19 +08:00
|
|
|
ActionInterval::startWithTarget(target);
|
|
|
|
_other->startWithTarget(target);
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
void DeccelAmplitude::update(float time)
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
2013-06-20 14:13:12 +08:00
|
|
|
((DeccelAmplitude*)(_other))->setAmplitudeRate(powf((1 - time), _rate));
|
2013-06-15 14:03:30 +08:00
|
|
|
_other->update(time);
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
DeccelAmplitude* DeccelAmplitude::clone() const
|
2013-06-16 10:44:39 +08:00
|
|
|
{
|
2013-06-19 06:06:53 +08:00
|
|
|
// no copy constructor
|
2013-06-20 14:13:12 +08:00
|
|
|
auto a = new DeccelAmplitude();
|
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-20 14:13:12 +08:00
|
|
|
DeccelAmplitude* DeccelAmplitude::reverse() const
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
2013-06-20 14:13:12 +08:00
|
|
|
return DeccelAmplitude::create(_other->reverse(), _duration);
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// implementation of StopGrid
|
|
|
|
|
2013-07-18 07:56:19 +08:00
|
|
|
void StopGrid::startWithTarget(Node *target)
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
2013-07-18 07:56:19 +08:00
|
|
|
ActionInstant::startWithTarget(target);
|
2013-12-12 16:20:52 +08:00
|
|
|
cacheTargetAsGridNode();
|
2013-12-16 14:21:05 +08:00
|
|
|
GridBase *grid = _gridNodeTarget->getGrid();
|
2013-11-16 21:08:00 +08:00
|
|
|
if (grid && grid->isActive())
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
2013-11-16 21:08:00 +08:00
|
|
|
grid->setActive(false);
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-12-12 16:20:52 +08:00
|
|
|
void StopGrid::cacheTargetAsGridNode()
|
|
|
|
{
|
2013-12-16 14:21:05 +08:00
|
|
|
_gridNodeTarget = dynamic_cast<NodeGrid*> (_target);
|
|
|
|
CCASSERT(_gridNodeTarget, "GridActions can only used on NodeGrid");
|
2013-12-12 16:20:52 +08:00
|
|
|
}
|
|
|
|
|
2013-11-16 21:08:00 +08:00
|
|
|
StopGrid* StopGrid::create()
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
2013-06-20 14:13:12 +08:00
|
|
|
StopGrid* pAction = new StopGrid();
|
2012-04-19 14:35:52 +08:00
|
|
|
pAction->autorelease();
|
|
|
|
|
|
|
|
return pAction;
|
|
|
|
}
|
2013-06-16 10:44:39 +08:00
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
StopGrid* StopGrid::clone() const
|
2013-06-16 10:44:39 +08:00
|
|
|
{
|
2013-06-20 14:13:12 +08:00
|
|
|
return StopGrid::create();
|
2013-06-16 10:44:39 +08:00
|
|
|
}
|
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
StopGrid* StopGrid::reverse() const
|
2013-06-16 10:44:39 +08:00
|
|
|
{
|
|
|
|
// no reverse, just clone it
|
|
|
|
return this->clone();
|
|
|
|
}
|
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
// implementation of ReuseGrid
|
2012-04-19 14:35:52 +08:00
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
ReuseGrid* ReuseGrid::create(int times)
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
2013-11-16 21:08:00 +08:00
|
|
|
ReuseGrid *action = new ReuseGrid();
|
|
|
|
if (action)
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
2013-11-16 21:08:00 +08:00
|
|
|
if (action->initWithTimes(times))
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
2013-11-16 21:08:00 +08:00
|
|
|
action->autorelease();
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2013-11-16 21:08:00 +08:00
|
|
|
CC_SAFE_DELETE(action);
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-11-16 21:08:00 +08:00
|
|
|
return action;
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
bool ReuseGrid::initWithTimes(int times)
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
_times = times;
|
2012-04-19 14:35:52 +08:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2013-07-18 07:56:19 +08:00
|
|
|
void ReuseGrid::startWithTarget(Node *target)
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
2013-07-18 07:56:19 +08:00
|
|
|
ActionInstant::startWithTarget(target);
|
2013-12-12 16:20:52 +08:00
|
|
|
cacheTargetAsGridNode();
|
2012-04-19 14:35:52 +08:00
|
|
|
|
2013-12-16 14:21:05 +08:00
|
|
|
if (_gridNodeTarget->getGrid() && _gridNodeTarget->getGrid()->isActive())
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
2013-12-16 14:21:05 +08:00
|
|
|
_gridNodeTarget->getGrid()->setReuseGrid(_gridNodeTarget->getGrid()->getReuseGrid() + _times);
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-12-12 16:20:52 +08:00
|
|
|
void ReuseGrid::cacheTargetAsGridNode()
|
|
|
|
{
|
2013-12-16 14:21:05 +08:00
|
|
|
_gridNodeTarget = dynamic_cast<NodeGrid*> (_target);
|
|
|
|
CCASSERT(_gridNodeTarget, "GridActions can only used on NodeGrid");
|
2013-12-12 16:20:52 +08:00
|
|
|
}
|
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
ReuseGrid* ReuseGrid::clone() const
|
2013-06-16 10:44:39 +08:00
|
|
|
{
|
2013-06-20 14:13:12 +08:00
|
|
|
return ReuseGrid::create(_times);
|
2013-06-16 10:44:39 +08:00
|
|
|
}
|
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
ReuseGrid* ReuseGrid::reverse() const
|
2013-06-16 10:44:39 +08:00
|
|
|
{
|
|
|
|
// no reverse, just clone it
|
|
|
|
return this->clone();
|
|
|
|
}
|
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
NS_CC_END
|