2011-04-11 11:24:10 +08:00
|
|
|
/****************************************************************************
|
2014-01-07 11:25:07 +08:00
|
|
|
Copyright (c) 2009 On-Core
|
|
|
|
Copyright (c) 2010-2012 cocos2d-x.org
|
2016-04-08 13:40:36 +08:00
|
|
|
CopyRight (c) 2013-2016 Chukong Technologies Inc.
|
2011-04-11 11:24:10 +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/CCActionTiledGrid.h"
|
2014-05-01 10:09:13 +08:00
|
|
|
#include "2d/CCGrid.h"
|
|
|
|
#include "2d/CCNodeGrid.h"
|
2014-04-30 08:37:36 +08:00
|
|
|
#include "base/CCDirector.h"
|
|
|
|
#include "base/ccMacros.h"
|
2011-04-11 11:24:10 +08:00
|
|
|
|
2012-04-18 18:43:45 +08:00
|
|
|
NS_CC_BEGIN
|
|
|
|
|
|
|
|
struct Tile
|
2011-04-11 11:24:10 +08:00
|
|
|
{
|
2014-05-15 01:07:09 +08:00
|
|
|
Vec2 position;
|
|
|
|
Vec2 startPosition;
|
2013-06-20 14:13:12 +08:00
|
|
|
Size 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
|
|
|
|
2013-12-18 17:47:20 +08:00
|
|
|
ShakyTiles3D* ShakyTiles3D::create(float duration, const Size& gridSize, int range, bool shakeZ)
|
2012-04-18 18:43:45 +08:00
|
|
|
{
|
2014-08-28 07:31:57 +08:00
|
|
|
ShakyTiles3D *action = new (std::nothrow) ShakyTiles3D();
|
2012-04-19 14:35:52 +08:00
|
|
|
|
2016-04-08 13:40:36 +08:00
|
|
|
if (action && action->initWithDuration(duration, gridSize, range, shakeZ))
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
2016-04-08 13:40:36 +08:00
|
|
|
action->autorelease();
|
|
|
|
return action;
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
|
|
|
|
2016-04-08 13:40:36 +08:00
|
|
|
delete action;
|
|
|
|
return nullptr;
|
2012-04-18 18:43:45 +08:00
|
|
|
}
|
|
|
|
|
2013-12-18 17:47:20 +08:00
|
|
|
bool ShakyTiles3D::initWithDuration(float duration, const Size& gridSize, int range, bool shakeZ)
|
2012-04-18 18:43:45 +08:00
|
|
|
{
|
2013-06-20 14:13:12 +08:00
|
|
|
if (TiledGrid3DAction::initWithDuration(duration, gridSize))
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
2013-12-18 17:47:20 +08:00
|
|
|
_randrange = range;
|
|
|
|
_shakeZ = shakeZ;
|
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-20 14:13:12 +08:00
|
|
|
ShakyTiles3D* ShakyTiles3D::clone() const
|
2013-06-16 10:44:39 +08:00
|
|
|
{
|
2016-04-08 13:40:36 +08:00
|
|
|
// no copy constructor
|
2016-04-21 13:39:42 +08:00
|
|
|
return ShakyTiles3D::create(_duration, _gridSize, _randrange, _shakeZ);
|
2013-06-16 10:44:39 +08:00
|
|
|
}
|
|
|
|
|
2016-11-16 09:48:37 +08:00
|
|
|
void ShakyTiles3D::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
|
|
|
{
|
2014-05-15 01:07:09 +08:00
|
|
|
Quad3 coords = getOriginalTile(Vec2(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
|
|
|
}
|
|
|
|
|
2014-05-15 01:07:09 +08:00
|
|
|
setTile(Vec2(i, j), coords);
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
|
|
|
}
|
2012-04-18 18:43:45 +08:00
|
|
|
}
|
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
// implementation of ShatteredTiles3D
|
2012-04-18 18:43:45 +08:00
|
|
|
|
2013-12-18 17:47:20 +08:00
|
|
|
ShatteredTiles3D* ShatteredTiles3D::create(float duration, const Size& gridSize, int range, bool shatterZ)
|
2012-04-18 18:43:45 +08:00
|
|
|
{
|
2014-08-28 07:31:57 +08:00
|
|
|
ShatteredTiles3D *action = new (std::nothrow) ShatteredTiles3D();
|
2012-04-19 14:35:52 +08:00
|
|
|
|
2016-04-08 13:40:36 +08:00
|
|
|
if (action && action->initWithDuration(duration, gridSize, range, shatterZ))
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
2016-04-08 13:40:36 +08:00
|
|
|
action->autorelease();
|
|
|
|
return action;
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
|
|
|
|
2016-04-08 13:40:36 +08:00
|
|
|
delete action;
|
|
|
|
return nullptr;
|
2012-04-18 18:43:45 +08:00
|
|
|
}
|
|
|
|
|
2013-12-18 17:47:20 +08:00
|
|
|
bool ShatteredTiles3D::initWithDuration(float duration, const Size& gridSize, int range, bool shatterZ)
|
2012-04-18 18:43:45 +08:00
|
|
|
{
|
2013-06-20 14:13:12 +08:00
|
|
|
if (TiledGrid3DAction::initWithDuration(duration, gridSize))
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
_once = false;
|
2013-12-18 17:47:20 +08:00
|
|
|
_randrange = range;
|
|
|
|
_shatterZ = shatterZ;
|
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-20 14:13:12 +08:00
|
|
|
ShatteredTiles3D* ShatteredTiles3D::clone() const
|
2013-06-16 10:44:39 +08:00
|
|
|
{
|
2016-04-08 13:40:36 +08:00
|
|
|
// no copy constructor
|
|
|
|
return ShatteredTiles3D::create(_duration, _gridSize, _randrange, _shatterZ);
|
2013-06-16 10:44:39 +08:00
|
|
|
}
|
|
|
|
|
2016-11-16 09:48:37 +08:00
|
|
|
void ShatteredTiles3D::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
|
|
|
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
|
|
|
{
|
2014-05-15 01:07:09 +08:00
|
|
|
Quad3 coords = getOriginalTile(Vec2(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
|
|
|
}
|
|
|
|
|
2014-05-15 01:07:09 +08:00
|
|
|
setTile(Vec2(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
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
// implementation of ShuffleTiles
|
2011-04-11 11:24:10 +08:00
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
ShuffleTiles* ShuffleTiles::create(float duration, const Size& gridSize, unsigned int seed)
|
2012-04-18 18:43:45 +08:00
|
|
|
{
|
2014-08-28 07:31:57 +08:00
|
|
|
ShuffleTiles *action = new (std::nothrow) ShuffleTiles();
|
2012-04-19 14:35:52 +08:00
|
|
|
|
2016-04-08 13:40:36 +08:00
|
|
|
if (action && action->initWithDuration(duration, gridSize, seed))
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
2016-04-08 13:40:36 +08:00
|
|
|
action->autorelease();
|
|
|
|
return action;
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
|
|
|
|
2016-04-08 13:40:36 +08:00
|
|
|
delete action;
|
|
|
|
return nullptr;
|
2012-04-18 18:43:45 +08:00
|
|
|
}
|
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
bool ShuffleTiles::initWithDuration(float duration, const Size& gridSize, unsigned int seed)
|
2012-04-18 18:43:45 +08:00
|
|
|
{
|
2013-06-20 14:13:12 +08:00
|
|
|
if (TiledGrid3DAction::initWithDuration(duration, gridSize))
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
_seed = seed;
|
2013-12-18 17:47:20 +08:00
|
|
|
_tilesOrder = nullptr;
|
|
|
|
_tiles = nullptr;
|
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-20 14:13:12 +08:00
|
|
|
ShuffleTiles* ShuffleTiles::clone() const
|
2013-06-16 10:44:39 +08:00
|
|
|
{
|
2015-01-08 10:22:45 +08:00
|
|
|
// no copy constructor
|
2016-04-08 13:40:36 +08:00
|
|
|
return ShuffleTiles::create(_duration, _gridSize, _seed);
|
2013-06-16 10:44:39 +08:00
|
|
|
}
|
|
|
|
|
2014-05-28 17:41:34 +08:00
|
|
|
ShuffleTiles::~ShuffleTiles()
|
2012-04-18 18:43:45 +08:00
|
|
|
{
|
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
|
|
|
|
2013-12-18 17:47:20 +08:00
|
|
|
void ShuffleTiles::shuffle(unsigned int *array, unsigned int len)
|
2012-04-18 18:43:45 +08:00
|
|
|
{
|
2014-05-28 17:41:34 +08:00
|
|
|
for (int i = len - 1; i >= 0; i-- )
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
|
|
|
unsigned int j = rand() % (i+1);
|
2013-12-18 17:47:20 +08:00
|
|
|
unsigned int v = array[i];
|
|
|
|
array[i] = array[j];
|
|
|
|
array[j] = v;
|
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-07-07 13:01:21 +08:00
|
|
|
Size ShuffleTiles::getDelta(const Size& pos) const
|
2012-04-18 18:43:45 +08:00
|
|
|
{
|
2014-05-15 01:07:09 +08:00
|
|
|
Vec2 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
|
|
|
|
2013-07-12 14:30:26 +08:00
|
|
|
return Size((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
|
|
|
|
2014-05-15 01:07:09 +08:00
|
|
|
void ShuffleTiles::placeTile(const Vec2& pos, Tile *t)
|
2012-04-18 18:43:45 +08:00
|
|
|
{
|
2013-07-08 23:12:11 +08:00
|
|
|
Quad3 coords = getOriginalTile(pos);
|
2011-04-11 11:24:10 +08:00
|
|
|
|
2014-05-15 01:07:09 +08:00
|
|
|
Vec2 step = _gridNodeTarget->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
|
|
|
|
2013-07-18 07:56:19 +08:00
|
|
|
void ShuffleTiles::startWithTarget(Node *target)
|
2012-04-18 18:43:45 +08:00
|
|
|
{
|
2013-07-18 07:56:19 +08:00
|
|
|
TiledGrid3DAction::startWithTarget(target);
|
2012-04-19 14:35:52 +08:00
|
|
|
|
2013-06-15 14:03:30 +08:00
|
|
|
if (_seed != (unsigned int)-1)
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
2016-07-11 11:17:28 +08:00
|
|
|
std::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
|
|
|
|
|
|
|
/**
|
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.
|
|
|
|
*/
|
2014-05-28 17:41:34 +08:00
|
|
|
for (unsigned int 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
|
|
|
|
2014-05-28 17:41:34 +08:00
|
|
|
for (int i = 0; i < _gridSize.width; ++i)
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
2014-05-28 17:41:34 +08:00
|
|
|
for ( int j = 0; j < _gridSize.height; ++j)
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
2015-04-20 01:40:52 +08:00
|
|
|
tileArray->position.set((float)i, (float)j);
|
|
|
|
tileArray->startPosition.set((float)i, (float)j);
|
2013-07-12 14:30:26 +08:00
|
|
|
tileArray->delta = getDelta(Size(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
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
void ShuffleTiles::update(float time)
|
2012-04-18 18:43:45 +08:00
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
Tile *tileArray = (Tile*)_tiles;
|
2012-04-19 14:35:52 +08:00
|
|
|
|
2014-05-28 17:41:34 +08:00
|
|
|
for (int i = 0; i < _gridSize.width; ++i)
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
2014-05-28 17:41:34 +08:00
|
|
|
for (int j = 0; j < _gridSize.height; ++j)
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
2014-05-15 01:07:09 +08:00
|
|
|
tileArray->position = Vec2((float)tileArray->delta.width, (float)tileArray->delta.height) * time;
|
|
|
|
placeTile(Vec2(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
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
// implementation of FadeOutTRTiles
|
2011-04-11 11:24:10 +08:00
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
FadeOutTRTiles* FadeOutTRTiles::create(float duration, const Size& gridSize)
|
2012-04-18 18:43:45 +08:00
|
|
|
{
|
2014-08-28 07:31:57 +08:00
|
|
|
FadeOutTRTiles *action = new (std::nothrow) FadeOutTRTiles();
|
2012-04-19 14:35:52 +08:00
|
|
|
|
2016-04-08 13:40:36 +08:00
|
|
|
if (action && action->initWithDuration(duration, gridSize))
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
2016-04-08 13:40:36 +08:00
|
|
|
action->autorelease();
|
|
|
|
return action;
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
|
|
|
|
2016-04-08 13:40:36 +08:00
|
|
|
delete action;
|
|
|
|
return nullptr;
|
2012-04-18 18:43:45 +08:00
|
|
|
}
|
2011-04-11 11:24:10 +08:00
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
FadeOutTRTiles* FadeOutTRTiles::clone() const
|
2013-06-16 10:44:39 +08:00
|
|
|
{
|
2015-01-08 10:22:45 +08:00
|
|
|
// no copy constructor
|
2016-04-08 13:40:36 +08:00
|
|
|
return FadeOutTRTiles::create(_duration, _gridSize);
|
2013-06-16 10:44:39 +08:00
|
|
|
}
|
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
float FadeOutTRTiles::testFunc(const Size& pos, float time)
|
2012-04-18 18:43:45 +08:00
|
|
|
{
|
2014-05-15 01:07:09 +08:00
|
|
|
Vec2 n = Vec2((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
|
|
|
|
2014-05-15 01:07:09 +08:00
|
|
|
void FadeOutTRTiles::turnOnTile(const Vec2& pos)
|
2012-04-18 18:43:45 +08:00
|
|
|
{
|
2013-07-08 23:12:11 +08:00
|
|
|
setTile(pos, getOriginalTile(pos));
|
2012-04-18 18:43:45 +08:00
|
|
|
}
|
2011-04-11 11:24:10 +08:00
|
|
|
|
2014-05-15 01:07:09 +08:00
|
|
|
void FadeOutTRTiles::turnOffTile(const Vec2& pos)
|
2012-04-18 18:43:45 +08:00
|
|
|
{
|
2013-07-05 16:49:22 +08:00
|
|
|
Quad3 coords;
|
|
|
|
memset(&coords, 0, sizeof(Quad3));
|
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
|
|
|
|
2014-05-15 01:07:09 +08:00
|
|
|
void FadeOutTRTiles::transformTile(const Vec2& pos, float distance)
|
2012-04-18 18:43:45 +08:00
|
|
|
{
|
2013-07-08 23:12:11 +08:00
|
|
|
Quad3 coords = getOriginalTile(pos);
|
2014-05-15 01:07:09 +08:00
|
|
|
Vec2 step = _gridNodeTarget->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
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
void FadeOutTRTiles::update(float time)
|
2012-04-18 18:43:45 +08:00
|
|
|
{
|
2014-05-28 17:41:34 +08:00
|
|
|
for (int i = 0; i < _gridSize.width; ++i)
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
2014-05-28 17:41:34 +08:00
|
|
|
for (int j = 0; j < _gridSize.height; ++j)
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
2013-07-12 14:30:26 +08:00
|
|
|
float distance = testFunc(Size(i, j), time);
|
2012-04-19 14:35:52 +08:00
|
|
|
if ( distance == 0 )
|
|
|
|
{
|
2014-05-15 01:07:09 +08:00
|
|
|
turnOffTile(Vec2(i, j));
|
2012-04-19 14:35:52 +08:00
|
|
|
} else
|
|
|
|
if (distance < 1)
|
|
|
|
{
|
2014-05-15 01:07:09 +08:00
|
|
|
transformTile(Vec2(i, j), distance);
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2014-05-15 01:07:09 +08:00
|
|
|
turnOnTile(Vec2(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
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
// implementation of FadeOutBLTiles
|
2012-06-14 15:13:16 +08:00
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
FadeOutBLTiles* FadeOutBLTiles::create(float duration, const Size& gridSize)
|
2012-04-18 18:43:45 +08:00
|
|
|
{
|
2014-08-28 07:31:57 +08:00
|
|
|
FadeOutBLTiles *action = new (std::nothrow) FadeOutBLTiles();
|
2012-04-19 14:35:52 +08:00
|
|
|
|
2016-04-08 13:40:36 +08:00
|
|
|
if (action && action->initWithDuration(duration, gridSize))
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
2016-04-08 13:40:36 +08:00
|
|
|
action->autorelease();
|
|
|
|
return action;
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
|
|
|
|
2016-04-08 13:40:36 +08:00
|
|
|
delete action;
|
|
|
|
return nullptr;
|
2012-04-18 18:43:45 +08:00
|
|
|
}
|
2011-04-11 11:24:10 +08:00
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
FadeOutBLTiles* FadeOutBLTiles::clone() const
|
2013-06-16 10:44:39 +08:00
|
|
|
{
|
2015-01-08 10:22:45 +08:00
|
|
|
// no copy constructor
|
2016-04-08 13:40:36 +08:00
|
|
|
return FadeOutBLTiles::create(_duration, _gridSize);
|
2013-06-16 10:44:39 +08:00
|
|
|
}
|
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
float FadeOutBLTiles::testFunc(const Size& pos, float time)
|
2012-04-18 18:43:45 +08:00
|
|
|
{
|
2014-05-15 01:07:09 +08:00
|
|
|
Vec2 n = Vec2((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
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
// implementation of FadeOutUpTiles
|
2012-04-18 18:43:45 +08:00
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
FadeOutUpTiles* FadeOutUpTiles::create(float duration, const Size& gridSize)
|
2012-04-18 18:43:45 +08:00
|
|
|
{
|
2014-08-28 07:31:57 +08:00
|
|
|
FadeOutUpTiles *action = new (std::nothrow) FadeOutUpTiles();
|
2012-04-19 14:35:52 +08:00
|
|
|
|
2016-04-08 13:40:36 +08:00
|
|
|
if (action && action->initWithDuration(duration, gridSize))
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
2016-04-08 13:40:36 +08:00
|
|
|
action->autorelease();
|
|
|
|
return action;
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
|
|
|
|
2016-04-08 13:40:36 +08:00
|
|
|
delete action;
|
|
|
|
return nullptr;
|
2012-04-18 18:43:45 +08:00
|
|
|
}
|
2011-04-11 11:24:10 +08:00
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
FadeOutUpTiles* FadeOutUpTiles::clone() const
|
2013-06-16 10:44:39 +08:00
|
|
|
{
|
2015-01-08 10:22:45 +08:00
|
|
|
// no copy constructor
|
2016-04-08 13:40:36 +08:00
|
|
|
return FadeOutUpTiles::create(_duration, _gridSize);
|
2013-06-16 10:44:39 +08:00
|
|
|
}
|
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
float FadeOutUpTiles::testFunc(const Size& pos, float time)
|
2012-04-18 18:43:45 +08:00
|
|
|
{
|
2014-05-15 01:07:09 +08:00
|
|
|
Vec2 n = Vec2((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
|
|
|
|
2014-05-15 01:07:09 +08:00
|
|
|
void FadeOutUpTiles::transformTile(const Vec2& pos, float distance)
|
2012-04-18 18:43:45 +08:00
|
|
|
{
|
2013-07-08 23:12:11 +08:00
|
|
|
Quad3 coords = getOriginalTile(pos);
|
2014-05-15 01:07:09 +08:00
|
|
|
Vec2 step = _gridNodeTarget->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
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
// implementation of FadeOutDownTiles
|
2012-06-14 15:13:16 +08:00
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
FadeOutDownTiles* FadeOutDownTiles::create(float duration, const Size& gridSize)
|
2012-04-18 18:43:45 +08:00
|
|
|
{
|
2014-08-28 07:31:57 +08:00
|
|
|
FadeOutDownTiles *action = new (std::nothrow) FadeOutDownTiles();
|
2012-04-19 14:35:52 +08:00
|
|
|
|
2016-04-08 13:40:36 +08:00
|
|
|
if (action && action->initWithDuration(duration, gridSize))
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
2016-04-08 13:40:36 +08:00
|
|
|
action->autorelease();
|
|
|
|
return action;
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
|
|
|
|
2016-04-08 13:40:36 +08:00
|
|
|
delete action;
|
|
|
|
return nullptr;
|
2012-04-18 18:43:45 +08:00
|
|
|
}
|
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
FadeOutDownTiles* FadeOutDownTiles::clone() const
|
2013-06-16 10:44:39 +08:00
|
|
|
{
|
2015-01-08 10:22:45 +08:00
|
|
|
// no copy constructor
|
2016-04-08 13:40:36 +08:00
|
|
|
return FadeOutDownTiles::create(_duration, _gridSize);
|
2013-06-16 10:44:39 +08:00
|
|
|
}
|
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
float FadeOutDownTiles::testFunc(const Size& pos, float time)
|
2012-04-18 18:43:45 +08:00
|
|
|
{
|
2014-05-15 01:07:09 +08:00
|
|
|
Vec2 n = Vec2((float)_gridSize.width, (float)_gridSize.height) * (1.0f - time);
|
2015-10-27 14:41:31 +08:00
|
|
|
return powf(n.y / (pos.height > 0.0f ? pos.height : 0.1f), 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
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
TurnOffTiles* TurnOffTiles::create(float duration, const Size& gridSize)
|
2012-04-18 18:43:45 +08:00
|
|
|
{
|
2016-04-08 13:40:36 +08:00
|
|
|
TurnOffTiles* action = new (std::nothrow) TurnOffTiles();
|
|
|
|
if (action && action->initWithDuration(duration, gridSize, 0))
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
2016-04-08 13:40:36 +08:00
|
|
|
action->autorelease();
|
|
|
|
return action;
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
2016-04-08 13:40:36 +08:00
|
|
|
|
|
|
|
delete action;
|
|
|
|
return nullptr;
|
2012-04-18 18:43:45 +08:00
|
|
|
}
|
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
TurnOffTiles* TurnOffTiles::create(float duration, const Size& gridSize, unsigned int seed)
|
2012-04-18 18:43:45 +08:00
|
|
|
{
|
2014-08-28 07:31:57 +08:00
|
|
|
TurnOffTiles *action = new (std::nothrow) TurnOffTiles();
|
2012-04-19 14:35:52 +08:00
|
|
|
|
2016-04-08 13:40:36 +08:00
|
|
|
if (action && action->initWithDuration(duration, gridSize, seed))
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
2016-04-08 13:40:36 +08:00
|
|
|
action->autorelease();
|
|
|
|
return action;
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
|
|
|
|
2016-04-08 13:40:36 +08:00
|
|
|
delete action;
|
|
|
|
return nullptr;
|
2012-04-18 18:43:45 +08:00
|
|
|
}
|
2011-04-11 11:24:10 +08:00
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
bool TurnOffTiles::initWithDuration(float duration, const Size& gridSize, unsigned int seed)
|
2012-04-18 18:43:45 +08:00
|
|
|
{
|
2013-06-20 14:13:12 +08:00
|
|
|
if (TiledGrid3DAction::initWithDuration(duration, gridSize))
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
_seed = seed;
|
2013-12-18 17:47:20 +08:00
|
|
|
_tilesOrder = nullptr;
|
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-20 14:13:12 +08:00
|
|
|
TurnOffTiles* TurnOffTiles::clone() const
|
2013-06-16 10:44:39 +08:00
|
|
|
{
|
2015-01-08 10:22:45 +08:00
|
|
|
// no copy constructor
|
2016-04-08 13:40:36 +08:00
|
|
|
return TurnOffTiles::create(_duration, _gridSize, _seed);
|
2013-06-16 10:44:39 +08:00
|
|
|
}
|
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
TurnOffTiles::~TurnOffTiles(void)
|
2012-04-18 18:43:45 +08:00
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
CC_SAFE_DELETE_ARRAY(_tilesOrder);
|
2012-04-18 18:43:45 +08:00
|
|
|
}
|
|
|
|
|
2013-12-18 17:47:20 +08:00
|
|
|
void TurnOffTiles::shuffle(unsigned int *array, unsigned int len)
|
2012-04-18 18:43:45 +08:00
|
|
|
{
|
2014-05-28 17:41:34 +08:00
|
|
|
for (int i = len - 1; i >= 0; i--)
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
|
|
|
unsigned int j = rand() % (i+1);
|
2013-12-18 17:47:20 +08:00
|
|
|
unsigned int v = array[i];
|
|
|
|
array[i] = array[j];
|
|
|
|
array[j] = v;
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
2012-04-18 18:43:45 +08:00
|
|
|
}
|
2011-04-11 11:24:10 +08:00
|
|
|
|
2014-05-15 01:07:09 +08:00
|
|
|
void TurnOffTiles::turnOnTile(const Vec2& pos)
|
2012-04-18 18:43:45 +08:00
|
|
|
{
|
2013-07-08 23:12:11 +08:00
|
|
|
setTile(pos, getOriginalTile(pos));
|
2012-04-18 18:43:45 +08:00
|
|
|
}
|
2011-04-11 11:24:10 +08:00
|
|
|
|
2014-05-15 01:07:09 +08:00
|
|
|
void TurnOffTiles::turnOffTile(const Vec2& pos)
|
2012-04-18 18:43:45 +08:00
|
|
|
{
|
2013-07-05 16:49:22 +08:00
|
|
|
Quad3 coords;
|
2011-04-11 11:24:10 +08:00
|
|
|
|
2013-07-05 16:49:22 +08:00
|
|
|
memset(&coords, 0, sizeof(Quad3));
|
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
|
|
|
|
2013-07-18 07:56:19 +08:00
|
|
|
void TurnOffTiles::startWithTarget(Node *target)
|
2012-04-18 18:43:45 +08:00
|
|
|
{
|
2013-07-18 07:56:19 +08:00
|
|
|
TiledGrid3DAction::startWithTarget(target);
|
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
|
|
|
{
|
2016-07-11 11:17:28 +08:00
|
|
|
std::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
|
|
|
|
2014-05-28 17:41:34 +08:00
|
|
|
for (unsigned int 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
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
void TurnOffTiles::update(float time)
|
2012-04-18 18:43:45 +08:00
|
|
|
{
|
2014-05-28 17:41:34 +08:00
|
|
|
unsigned int l = (unsigned int)(time * (float)_tilesCount);
|
2012-04-19 14:35:52 +08:00
|
|
|
|
2014-05-28 17:41:34 +08:00
|
|
|
unsigned int t = 0;
|
|
|
|
for (unsigned int i = 0; i < _tilesCount; i++ )
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
t = _tilesOrder[i];
|
2015-04-20 01:40:52 +08:00
|
|
|
Vec2 tilePos( (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
|
|
|
}
|
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
// implementation of WavesTiles3D
|
2012-04-18 18:43:45 +08:00
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
WavesTiles3D* WavesTiles3D::create(float duration, const Size& gridSize, unsigned int waves, float amplitude)
|
2012-04-18 18:43:45 +08:00
|
|
|
{
|
2014-08-28 07:31:57 +08:00
|
|
|
WavesTiles3D *action = new (std::nothrow) WavesTiles3D();
|
2012-04-19 14:35:52 +08:00
|
|
|
|
2016-04-08 13:40:36 +08:00
|
|
|
if (action && action->initWithDuration(duration, gridSize, waves, amplitude))
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
2016-04-08 13:40:36 +08:00
|
|
|
action->autorelease();
|
|
|
|
return action;
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
|
|
|
|
2016-04-08 13:40:36 +08:00
|
|
|
delete action;
|
|
|
|
return nullptr;
|
2012-04-18 18:43:45 +08:00
|
|
|
}
|
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
bool WavesTiles3D::initWithDuration(float duration, const Size& gridSize, unsigned int waves, float amplitude)
|
2012-04-18 18:43:45 +08:00
|
|
|
{
|
2013-06-20 14:13:12 +08:00
|
|
|
if (TiledGrid3DAction::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-20 14:13:12 +08:00
|
|
|
WavesTiles3D* WavesTiles3D::clone() const
|
2013-06-16 10:44:39 +08:00
|
|
|
{
|
2015-01-08 10:22:45 +08:00
|
|
|
// no copy constructor
|
2016-04-08 13:40:36 +08:00
|
|
|
return WavesTiles3D::create(_duration, _gridSize, _waves, _amplitude);
|
2013-06-16 10:44:39 +08:00
|
|
|
}
|
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
void WavesTiles3D::update(float time)
|
2012-04-18 18:43:45 +08:00
|
|
|
{
|
2014-05-28 17:41:34 +08:00
|
|
|
for (int i = 0; i < _gridSize.width; i++ )
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
2014-05-28 17:41:34 +08:00
|
|
|
for (int j = 0; j < _gridSize.height; j++ )
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
2014-05-15 01:07:09 +08:00
|
|
|
Quad3 coords = getOriginalTile(Vec2(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;
|
|
|
|
|
2014-05-15 01:07:09 +08:00
|
|
|
setTile(Vec2(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
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
// implementation of JumpTiles3D
|
2012-04-18 18:43:45 +08:00
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
JumpTiles3D* JumpTiles3D::create(float duration, const Size& gridSize, unsigned int numberOfJumps, float amplitude)
|
2012-04-18 18:43:45 +08:00
|
|
|
{
|
2014-08-28 07:31:57 +08:00
|
|
|
JumpTiles3D *action = new (std::nothrow) JumpTiles3D();
|
2012-04-19 14:35:52 +08:00
|
|
|
|
2016-04-08 13:40:36 +08:00
|
|
|
if (action && action->initWithDuration(duration, gridSize, numberOfJumps, amplitude))
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
2016-04-08 13:40:36 +08:00
|
|
|
action->autorelease();
|
|
|
|
return action;
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
|
|
|
|
2016-04-08 13:40:36 +08:00
|
|
|
delete action;
|
|
|
|
return nullptr;
|
2012-04-18 18:43:45 +08:00
|
|
|
}
|
2011-04-11 11:24:10 +08:00
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
bool JumpTiles3D::initWithDuration(float duration, const Size& gridSize, unsigned int numberOfJumps, float amplitude)
|
2012-04-18 18:43:45 +08:00
|
|
|
{
|
2013-06-20 14:13:12 +08:00
|
|
|
if (TiledGrid3DAction::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-20 14:13:12 +08:00
|
|
|
JumpTiles3D* JumpTiles3D::clone() const
|
2013-06-16 10:44:39 +08:00
|
|
|
{
|
2015-01-08 10:22:45 +08:00
|
|
|
// no copy constructor
|
2016-04-08 13:40:36 +08:00
|
|
|
return JumpTiles3D::create(_duration, _gridSize, _jumps, _amplitude);
|
2013-06-16 10:44:39 +08:00
|
|
|
}
|
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
void JumpTiles3D::update(float time)
|
2012-04-18 18:43:45 +08:00
|
|
|
{
|
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
|
|
|
|
2014-05-28 17:41:34 +08:00
|
|
|
for (int i = 0; i < _gridSize.width; i++ )
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
2014-05-28 17:41:34 +08:00
|
|
|
for (int j = 0; j < _gridSize.height; j++ )
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
2014-05-15 01:07:09 +08:00
|
|
|
Quad3 coords = getOriginalTile(Vec2(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;
|
|
|
|
}
|
|
|
|
|
2014-05-15 01:07:09 +08:00
|
|
|
setTile(Vec2(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
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
// implementation of SplitRows
|
2011-04-11 11:24:10 +08:00
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
SplitRows* SplitRows::create(float duration, unsigned int nRows)
|
2012-04-18 18:43:45 +08:00
|
|
|
{
|
2014-08-28 07:31:57 +08:00
|
|
|
SplitRows *action = new (std::nothrow) SplitRows();
|
2012-04-19 14:35:52 +08:00
|
|
|
|
2016-04-08 13:40:36 +08:00
|
|
|
if (action && action->initWithDuration(duration, nRows))
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
2016-04-08 13:40:36 +08:00
|
|
|
action->autorelease();
|
|
|
|
return action;
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
|
|
|
|
2016-04-08 13:40:36 +08:00
|
|
|
delete action;
|
|
|
|
return nullptr;
|
2012-04-18 18:43:45 +08:00
|
|
|
}
|
2011-04-11 11:24:10 +08:00
|
|
|
|
2013-12-18 17:47:20 +08:00
|
|
|
bool SplitRows::initWithDuration(float duration, unsigned int rows)
|
2012-04-18 18:43:45 +08:00
|
|
|
{
|
2013-12-18 17:47:20 +08:00
|
|
|
_rows = rows;
|
2011-04-11 11:24:10 +08:00
|
|
|
|
2013-12-18 17:47:20 +08:00
|
|
|
return TiledGrid3DAction::initWithDuration(duration, Size(1, rows));
|
2012-04-18 18:43:45 +08:00
|
|
|
}
|
2011-04-11 11:24:10 +08:00
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
SplitRows* SplitRows::clone() const
|
2013-06-16 10:44:39 +08:00
|
|
|
{
|
2015-01-08 10:22:45 +08:00
|
|
|
// no copy constructor
|
2016-04-08 13:40:36 +08:00
|
|
|
return SplitRows::create(_duration, _rows);
|
2013-06-16 10:44:39 +08:00
|
|
|
}
|
|
|
|
|
2013-07-18 07:56:19 +08:00
|
|
|
void SplitRows::startWithTarget(Node *target)
|
2012-04-18 18:43:45 +08:00
|
|
|
{
|
2013-07-18 07:56:19 +08:00
|
|
|
TiledGrid3DAction::startWithTarget(target);
|
2013-07-12 06:24:23 +08:00
|
|
|
_winSize = Director::getInstance()->getWinSizeInPixels();
|
2012-04-18 18:43:45 +08:00
|
|
|
}
|
2011-04-11 11:24:10 +08:00
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
void SplitRows::update(float time)
|
2012-04-18 18:43:45 +08:00
|
|
|
{
|
2014-05-28 17:41:34 +08:00
|
|
|
for (unsigned int j = 0; j < _gridSize.height; ++j)
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
2014-05-15 01:07:09 +08:00
|
|
|
Quad3 coords = getOriginalTile(Vec2(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
|
|
|
|
2014-05-15 01:07:09 +08:00
|
|
|
setTile(Vec2(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
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
// implementation of SplitCols
|
2012-04-18 18:43:45 +08:00
|
|
|
|
2013-12-18 17:47:20 +08:00
|
|
|
SplitCols* SplitCols::create(float duration, unsigned int cols)
|
2012-04-18 18:43:45 +08:00
|
|
|
{
|
2014-08-28 07:31:57 +08:00
|
|
|
SplitCols *action = new (std::nothrow) SplitCols();
|
2012-04-19 14:35:52 +08:00
|
|
|
|
2016-04-08 13:40:36 +08:00
|
|
|
if (action && action->initWithDuration(duration, cols))
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
2016-04-08 13:40:36 +08:00
|
|
|
action->autorelease();
|
|
|
|
return action;
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
|
|
|
|
2016-04-08 13:40:36 +08:00
|
|
|
delete action;
|
|
|
|
return nullptr;
|
2012-04-18 18:43:45 +08:00
|
|
|
}
|
2011-04-11 11:24:10 +08:00
|
|
|
|
2013-12-18 17:47:20 +08:00
|
|
|
bool SplitCols::initWithDuration(float duration, unsigned int cols)
|
2012-04-18 18:43:45 +08:00
|
|
|
{
|
2013-12-18 17:47:20 +08:00
|
|
|
_cols = cols;
|
|
|
|
return TiledGrid3DAction::initWithDuration(duration, Size(cols, 1));
|
2012-04-18 18:43:45 +08:00
|
|
|
}
|
2011-04-11 11:24:10 +08:00
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
SplitCols* SplitCols::clone() const
|
2013-06-16 10:44:39 +08:00
|
|
|
{
|
2016-04-08 13:40:36 +08:00
|
|
|
// no copy constructor
|
|
|
|
return SplitCols::create(_duration, _cols);
|
2013-06-16 10:44:39 +08:00
|
|
|
}
|
|
|
|
|
2013-07-18 07:56:19 +08:00
|
|
|
void SplitCols::startWithTarget(Node *target)
|
2012-04-18 18:43:45 +08:00
|
|
|
{
|
2013-07-18 07:56:19 +08:00
|
|
|
TiledGrid3DAction::startWithTarget(target);
|
2013-07-12 06:24:23 +08:00
|
|
|
_winSize = Director::getInstance()->getWinSizeInPixels();
|
2012-04-18 18:43:45 +08:00
|
|
|
}
|
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
void SplitCols::update(float time)
|
2012-04-18 18:43:45 +08:00
|
|
|
{
|
2014-05-28 17:41:34 +08:00
|
|
|
for (unsigned int i = 0; i < _gridSize.width; ++i)
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
2014-05-15 01:07:09 +08:00
|
|
|
Quad3 coords = getOriginalTile(Vec2(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
|
|
|
|
2014-05-15 01:07:09 +08:00
|
|
|
setTile(Vec2(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
|