-
Notifications
You must be signed in to change notification settings - Fork 0
/
PlayLayer.cpp
684 lines (601 loc) · 19.3 KB
/
PlayLayer.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
#include "PlayLayer.h"
#include "SushiSprite.h"
#include "GameOverLayer.h"
#define MATRIX_WIDTH (6)
#define MATRIX_HEIGHT (8)
#define SUSHI_GAP (1)
typedef struct tagDIRECTION
{
int x_offset;
int y_offset;
}DIRECTION;
DIRECTION direction_4[] = { { -1, 0 }, { 0, 1 }, { 1, 0 }, { 0, -1 } };
PlayLayer::PlayLayer()
: spriteSheet(NULL)
, m_matrix(NULL)
, m_width(0)
, m_height(0)
, m_matrixLeftBottomX(0)
, m_matrixLeftBottomY(0)
, m_isAnimationing(true)//标志是否开始下落动画
, m_isTouchEnable(true) // 标志知否处理触摸事件
, m_movingVertical(true)//true: 4消除产生纵向炸弹. false: 4消除产生横向炸弹.
, m_iScore(0) //分数:0
, m_totalTime(0.0) //update中累计游戏时间
{
}
PlayLayer::~PlayLayer()
{
if (m_matrix) {
free(m_matrix);
}
}
Scene *PlayLayer::createScene()
{
auto scene = Scene::create();
auto layer = PlayLayer::create();
scene->addChild(layer);
return scene;
}
void PlayLayer::initBG()
{
//Size winSize = Director::getInstance()->getWinSize();
Size visibleSize = Director::getInstance()->getVisibleSize();
auto background = Sprite::create("mbackground.png");
background->setAnchorPoint(Point(1, 1));
background->setPosition(Point(visibleSize.width, visibleSize.height));
this->addChild(background,0);
}
void PlayLayer::loadUI()
{
auto UI = cocostudio::GUIReader::getInstance()->widgetFromJsonFile("LitterRunnerUI_1.ExportJson");
UI->setTouchEnabled(false);
this->addChild(UI);
//获取控件对象
m_scoreLab = (Text*)Helper::seekWidgetByName(UI,"scoreLab");
m_timeBar = (LoadingBar*)Helper::seekWidgetByName(UI,"hpProgress");
}
bool PlayLayer::init()
{
if (!Layer::init()) {
return false;
}
// 创建游戏背景
initBG();
//加载UI
loadUI();
// 初始化寿司精灵表单
SpriteFrameCache::getInstance()->addSpriteFramesWithFile("sushi.plist");
spriteSheet = SpriteBatchNode::create("sushi.pvr.ccz");
addChild(spriteSheet);
// 初始化矩阵的宽和高,即:寿司的长宽个数。MATRIX_WIDTH、MATRIX_HEIGHT通过宏定义
m_width = MATRIX_WIDTH;
m_height = MATRIX_HEIGHT;
// 初始化寿司矩阵左下角的点
Size visibleSize = Director::getInstance()->getVisibleSize();
m_matrixLeftBottomX = (visibleSize.width - SushiSprite::getContentWidth() * m_width - (m_width - 1) * SUSHI_GAP) / 2;
m_matrixLeftBottomY = (visibleSize.height - SushiSprite::getContentWidth() * m_height - (m_height - 1) * SUSHI_GAP) / 2;
// 初始化数组
int arraySize = sizeof(SushiSprite *) * m_width * m_height;//数组尺寸大小
//为 m_matrix 分配内存,这里 m_matrix 是指向指针类型的指针,其定义为:SushiSprite **m_matrix。所以可以理解为 m_matrix 是一个指针数组
m_matrix = (SushiSprite **)malloc(arraySize);
memset((void*)m_matrix, 0, arraySize);//初始化数组 m_matrix
/* memset 补充
void *memset(void *s, int ch, size_t n);
函数解释:s 指向的某一块内存,将 s 中前 n 个字节 (typedef unsigned int size_t )用 ch 指定的ASCII值 替换并返回 s 。
memset:作用是在一段内存块中填充某个给定的值,它是对较大的结构体或数组进行清零操作的一种最快方法[1] 。
*/
//初始化寿司矩阵
initMatrix();
//调用定时器
scheduleUpdate();
this->schedule(schedule_selector(PlayLayer::timeUpdate), 1.0f);
//创建并绑定触摸机制
// 1. 创建一个事件监听器,Onebyone 为单点触摸
auto touchListener = EventListenerTouchOneByOne::create();
// 2. 绑定触摸事件
touchListener->onTouchBegan = CC_CALLBACK_2(PlayLayer::onTouchBegan, this); // 触摸开始时触发
touchListener->onTouchMoved = CC_CALLBACK_2(PlayLayer::onTouchMoved, this); // 触摸移动时触发
// 3. 添加监听器
_eventDispatcher->addEventListenerWithSceneGraphPriority(touchListener, this);// addEventListenerWithSceneGraphPriority(EventListener *listener,Node *node); 事件监听器优先级为 0
//而 _eventDispatcher->addEventListenerWithFixedPriority(EventListenr *listener,int fixedPriority)的优先级由我们设置,但不能为 0
/*
eventDispatcher事件分发器,
1. eventDispatcher 是 Node 的属性,
2. 通过它我们可以统一管理当前节点(如:场景、层、精灵等)的所有事件分发情况。
3. 但是它本身是一个单例模式值的引用,在 Node 构造函数中,通过 “Director::getInstance()->getEventDispatcher();” 获取,有了这个属性,我们能更为方便的调用。
*/
return true;
}
void PlayLayer::timeUpdate(float dt)
{
m_totalTime += 2.0f;
m_timeBar->setPercent(100.0 - m_totalTime);
}
void PlayLayer::update(float dt)
{
if (m_timeBar->getPercent() <= 0)
{
sendMsg();
Director::getInstance()->replaceScene(GameOverLayer::createScene());
}
// check if animationing,m_isAnimationing(true)
if (m_isAnimationing)
{
// init with false
m_isAnimationing = false;
for (int i = 0; i < m_height * m_width; i++)
{
SushiSprite *sushi = m_matrix[i];
if (sushi && sushi->getNumberOfRunningActions() > 0)
{//getNumberOfRunningActions()方法可以获取sushi正在执行中的动作个数
m_isAnimationing = true;
break;
}
}
}
// if sushi is moving, ignore use touch event
m_isTouchEnable = !m_isAnimationing;
if (!m_isAnimationing) {
// checkAndRemoveChain();
}
}
/*void PlayLayer::checkAndRemoveChain()
{
//log("checkAndRemoveChain");
for (int i = 0; i < m_height * m_width; i++)
{
SushiSprite *sushi = m_matrix[i];
if (!sushi)
{
continue;
}
// start count chain
std::list<SushiSprite *> colChainList;
getColChain(sushi, colChainList);
std::list<SushiSprite *> rowChainList;
getRowChain(sushi, rowChainList);
std::list<SushiSprite *> &longerList = colChainList.size() > rowChainList.size() ? colChainList : rowChainList;
if (longerList.size() == 3)
{
removeSushi(longerList);
return;
}
if (longerList.size() > 3)
{
//TODO: make a special sushi can clean a line, and remove others
removeSushi(longerList);
return;
}
}
}*/
void PlayLayer::FloodSeedFill(int x, int y, SushiSprite* sushi)
{
if (x >= 0 && x < m_height && y >= 0 && y < m_width)
{
SushiSprite *neighborSushi = m_matrix[x * m_width + y];
if (neighborSushi->getImgIndex() == sushi->getImgIndex())
{
if (neighborSushi->getIgnoreCheck())return;
for (int i = 0; i < 4; i++)
{
neighborSushi->setIgnoreCheck(true);
FloodSeedFill(x + direction_4[i].x_offset, y + direction_4[i].y_offset, sushi);
}
}
}
}
void PlayLayer::checkAndRemoveChain()
{
//log("checkAndRemoveChain");
SushiSprite *sushi = m_srcSushi;
if (!sushi)
{
return;
}
std::list<SushiSprite*> sameList;
FloodSeedFill(sushi->getRow(),sushi->getCol(),sushi);
for (int i = 0; i < m_width*m_height; i++)
{
if (m_matrix[i]->getIgnoreCheck())
{
sameList.push_back(m_matrix[i]);
}
}
m_srcSushi = nullptr;//不然有上个源结点的bug 可以弄个新的功能
if (sameList.size()>2)
{
removeSushi(sameList);
}
return;
/* // start count chain
std::list<SushiSprite *> colChainList;
getColChain(sushi, colChainList);
std::list<SushiSprite *> rowChainList;
getRowChain(sushi, rowChainList);
std::list<SushiSprite *> &longerList = colChainList.size() > rowChainList.size() ? colChainList : rowChainList;
if (longerList.size() == 3)
{
removeSushi(longerList);
return;
}
if (longerList.size() > 3)
{
//TODO: make a special sushi can clean a line, and remove others
removeSushi(longerList);
return;
}*/
}
void PlayLayer::getColChain(SushiSprite *sushi, std::list<SushiSprite *> &chainList)
{//横向检测每一列
chainList.push_back(sushi);// 插入第一个寿司精灵
//向前检测相同图标值(ImgIndex)的寿司
int neighborCol = sushi->getCol() - 1;//sushi前一列寿司所在列数值
while (neighborCol >= 0) {
SushiSprite *neighborSushi = m_matrix[sushi->getRow() * m_width + neighborCol];
if (neighborSushi && (neighborSushi->getImgIndex() == sushi->getImgIndex())) {
chainList.push_back(neighborSushi);//插入该“邻居”寿司
neighborCol--;//继续向前
}
else {
break;
}
}
//向后检测相同图标值(ImgIndex)的寿司
neighborCol = sushi->getCol() + 1;
while (neighborCol < m_width) {
SushiSprite *neighborSushi = m_matrix[sushi->getRow() * m_width + neighborCol];
if (neighborSushi && (neighborSushi->getImgIndex() == sushi->getImgIndex())) {
chainList.push_back(neighborSushi);
neighborCol++;
}
else {
break;
}
}
}
void PlayLayer::getRowChain(SushiSprite *sushi, std::list<SushiSprite *> &chainList)
{
chainList.push_back(sushi);// add first sushi
int neighborRow = sushi->getRow() - 1;
while (neighborRow >= 0) {
SushiSprite *neighborSushi = m_matrix[neighborRow * m_width + sushi->getCol()];
if (neighborSushi && (neighborSushi->getImgIndex() == sushi->getImgIndex())) {
chainList.push_back(neighborSushi);
neighborRow--;
} else {
break;
}
}
neighborRow = sushi->getRow() + 1;
while (neighborRow < m_height) {
SushiSprite *neighborSushi = m_matrix[neighborRow * m_width + sushi->getCol()];
if (neighborSushi && (neighborSushi->getImgIndex() == sushi->getImgIndex())) {
chainList.push_back(neighborSushi);
neighborRow++;
} else {
break;
}
}
}
void PlayLayer::fillVacancies()
{
Size size = CCDirector::getInstance()->getWinSize();
int *colEmptyInfo = (int *)malloc(sizeof(int) * m_width);
memset((void *)colEmptyInfo, 0, sizeof(int) * m_width);
// 1. drop exist sushi
SushiSprite *sushi = NULL;
for (int col = 0; col < m_width; col++) {
int removedSushiOfCol = 0;
// from buttom to top
for (int row = 0; row < m_height; row++) {
sushi = m_matrix[row * m_width + col];
if (NULL == sushi) {
removedSushiOfCol++;
} else {
if (removedSushiOfCol > 0) {
// evey item have its own drop distance
int newRow = row - removedSushiOfCol;
// switch in matrix
m_matrix[newRow * m_width + col] = sushi;
m_matrix[row * m_width + col] = NULL;
// move to new position
Point startPosition = sushi->getPosition();
Point endPosition = positionOfItem(newRow, col);
float speed = (startPosition.y - endPosition.y) / size.height;
sushi->stopAllActions();// must stop pre drop action
sushi->runAction(CCMoveTo::create(speed, endPosition));
// set the new row to item
sushi->setRow(newRow);
}
}
}
// record empty info
colEmptyInfo[col] = removedSushiOfCol;
}
// 2. create new item and drop down.
for (int col = 0; col < m_width; col++) {
for (int row = m_height - colEmptyInfo[col]; row < m_height; row++) {
createAndDropSushi(row, col);
}
}
free(colEmptyInfo);
}
void PlayLayer::removeSushi(std::list<SushiSprite *> &sushiList)
{
// make sequence remove
m_isAnimationing = true;
std::list<SushiSprite *>::iterator itList;
for (itList = sushiList.begin(); itList != sushiList.end(); itList++) {
SushiSprite *sushi = (SushiSprite *)*itList;
// remove sushi from the metrix
m_matrix[sushi->getRow() * m_width + sushi->getCol()] = NULL;
explodeSushi(sushi);
}
// drop to fill empty
fillVacancies();
}
void PlayLayer::explodeSushi(SushiSprite *sushi)
{
//log("explodeSushi ture");
float time = 0.3;
// 1. action for sushi
sushi->runAction(Sequence::create(
ScaleTo::create(time, 0.0),
CallFunc::create(CC_CALLBACK_0(Sprite::removeFromParent, sushi)),
NULL));
// 2. action for circle
auto circleSprite = Sprite::create("circle.png");
addChild(circleSprite, 10);
circleSprite->setPosition(sushi->getPosition());
circleSprite->setScale(0);// start size
circleSprite->runAction(Sequence::create(ScaleTo::create(time, 1.0),
CallFunc::create(CC_CALLBACK_0(Sprite::removeFromParent, circleSprite)),
NULL));
// 3. particle effect
auto particleStars = ParticleSystemQuad::create("stars.plist");
particleStars->setAutoRemoveOnFinish(true);
particleStars->setBlendAdditive(false);
particleStars->setPosition(sushi->getPosition());
particleStars->setScale(0.3);
addChild(particleStars, 20);
//消除加分
setScore();
}
//设置得分
void PlayLayer::setScore()
{
m_iScore += 100;
m_scoreLab->setText(Value(m_iScore).asString());
}
//矩阵的初始化
void PlayLayer::initMatrix()
{//row 是行 ,col 是列
for (int row = 0; row < m_height; row++) {
for (int col = 0; col < m_width; col++) {
createAndDropSushi(row, col);
}
}
}
//创建SushiSprite,并下落到指定位置
void PlayLayer::createAndDropSushi(int row, int col)
{
Size size = Director::getInstance()->getWinSize();
SushiSprite *sushi = SushiSprite::create(row, col);
// 创建并执行下落动画
Point endPosition = positionOfItem(row, col);
Point startPosition = Point(endPosition.x, endPosition.y + size.height /2);
sushi->setPosition(startPosition);
float speed = startPosition.y / (2 * size.height);
sushi->runAction(MoveTo::create(speed, endPosition));
//将寿司添加到精灵表单里。注意,如果没有添加到精灵表单里,而是添加到层里的话,就不会得到性能的优化。
spriteSheet->addChild(sushi);
//给指定位置的数组赋值
m_matrix[row * m_width + col] = sushi;
}
//得到对应行列精灵的坐标值
Point PlayLayer::positionOfItem(int row, int col)
{
float x = m_matrixLeftBottomX + (SushiSprite::getContentWidth() + SUSHI_GAP) * col + SushiSprite::getContentWidth() / 2;
float y = m_matrixLeftBottomY + (SushiSprite::getContentWidth() + SUSHI_GAP) * row + SushiSprite::getContentWidth() / 2;
return Point(x, y);
}
/*//获取触屏点所在的寿司,得到 m_srcSushi
SushiSprite *PlayLayer::sushiOfPoint(Point *point)//试试该 &point
{
SushiSprite *sushi = nullptr;
Rect rect = Rect(0, 0, 0, 0); // rect这个对象是用来存储成对出现的参数,比如,一个矩形框的左上角坐标、宽度和高度
for (int i = 0; i < m_width*m_height; i++)
{
sushi = m_matrix[i];
if (sushi)
{
rect.origin.x = sushi->getPositionX() - (sushi->getContentSize().width / 2);
rect.origin.y = sushi->getPositionY() - (sushi->getContentSize().height / 2);
rect.size = sushi->getContentSize();
if (rect.containsPoint(*point))
return sushi;
}
}
return nullptr;
}
bool PlayLayer::onTouchBegan(Touch *touch, Event *unused)
{
//log("onTouchBegan");
m_srcSushi = nullptr;
m_destSushi = nullptr;
if (m_isTouchEnable)
{
auto location = touch->getLocation();
m_srcSushi = sushiOfPoint(&location);
}
return m_isTouchEnable;
}*/
//
bool PlayLayer::onTouchBegan(Touch *touch, Event *unused_event)
{
if (m_isTouchEnable)
{
SushiSprite *sushi = nullptr;
for (int i = 0; i < m_width*m_height; i++)
{
sushi = m_matrix[i];
if (sushi)
{
//将触点坐标, 转换为相对节点sushi的, 相对坐标
auto point = sushi->convertTouchToNodeSpace(touch);
//构造sushi的尺寸矩形
Size size = sushi->getContentSize();
Rect rect = Rect(0, 0, size.width, size.height);
//判断触点是否触摸到sp内部
if (rect.containsPoint(point)) {
m_srcSushi = sushi;
}
}
}
}
checkAndRemoveChain();
return m_isTouchEnable;
}
//
//用 m_srcSushi (源寿司)求得 m_destSushi
void PlayLayer::onTouchMoved(Touch *touch, Event *unused)
{
//log("onTouchMoved");
if (!m_srcSushi || !m_isTouchEnable)
return;
// 定义一些变量节省些代码
auto row = m_srcSushi->getRow();
auto col = m_srcSushi->getCol();
auto location = touch->getLocation();
auto halfSushiWidth = m_srcSushi->getContentSize().width / 2;
auto halfSushiHeight = m_srcSushi->getContentSize().height / 2;
// 计算源寿司四周 rect
// 源寿司上边寿司面积
auto upRect = Rect(m_srcSushi->getPositionX() - halfSushiWidth,
m_srcSushi->getPositionY() + halfSushiHeight,
m_srcSushi->getContentSize().width,
m_srcSushi->getContentSize().height);
if (upRect.containsPoint(location))
{
row++;
if (row < m_height)
{
m_destSushi = m_matrix[row*m_width + col];
}
m_movingVertical = true;//可能生成纵向的特殊寿司
swapSushi();
return;
}
auto downRect = Rect(m_srcSushi->getPositionX() - halfSushiWidth,
m_srcSushi->getPositionY() - (halfSushiHeight*3),
m_srcSushi->getContentSize().width,
m_srcSushi->getContentSize().height
);
if (downRect.containsPoint(location))
{
row--;
if (row >= 0)
{
m_destSushi = m_matrix[row*m_width + col];
}
m_movingVertical = true;
swapSushi();
return;
}
auto leftRect = Rect(m_srcSushi->getPositionX() - (halfSushiWidth * 3),
m_srcSushi->getPositionY() - halfSushiHeight,
m_srcSushi->getContentSize().width,
m_srcSushi->getContentSize().height
);
if (leftRect.containsPoint(location))
{
col--;
if (col >= 0)
{
m_destSushi = m_matrix[row*m_width + col];
}
m_movingVertical = false;//可能生成横向的特殊寿司
swapSushi();
return;
}
auto rightRect = Rect(m_srcSushi->getPositionX() + halfSushiWidth,
m_srcSushi->getPositionY() - halfSushiHeight,
m_srcSushi->getContentSize().width,
m_srcSushi->getContentSize().height
);
if (rightRect.containsPoint(location))
{
col++;
if (col < m_width)
{
m_destSushi = m_matrix[row*m_width + col];
}
m_movingVertical = false;
swapSushi();
return;
}
}
void PlayLayer::swapSushi()
{
//log("swapSushi");
m_isAnimationing = true;
m_isTouchEnable = false;
if (!m_srcSushi || !m_destSushi)
{
m_movingVertical = true;
return;
}
Point posOfSrc = m_srcSushi->getPosition();
Point posOfDest = m_destSushi->getPosition();
float time = 0.2;
// 1.交换 m_srcSushi 与 m_destSushi 在寿司矩阵的行列号, 和 m_srcSushi 与 m_destSushi 本身内容
m_matrix[m_srcSushi->getRow()*m_width + m_srcSushi->getCol()] = m_destSushi;
m_matrix[m_destSushi->getRow()*m_width + m_destSushi->getCol()] = m_srcSushi;
int tmpRow = m_srcSushi->getRow();
int tmpCol = m_srcSushi->getCol();
m_srcSushi->setRow(m_destSushi->getRow());
m_srcSushi->setCol(m_destSushi->getCol());
m_destSushi->setRow(tmpRow);
m_destSushi->setCol(tmpCol);
// 2.检测交换后的 m_srcSushi 与 m_destSushi 在横纵方向上是否满足消除条件
std::list<SushiSprite*> ColChainListOfFirst;
getColChain(m_srcSushi, ColChainListOfFirst);
std::list<SushiSprite*> RowChainListOfFirst;
getRowChain(m_srcSushi, RowChainListOfFirst);
std::list<SushiSprite*> ColChainListOfSecond;
getColChain(m_destSushi, ColChainListOfSecond);
std::list<SushiSprite*> RowChainListOfSecond;
getRowChain(m_destSushi, RowChainListOfSecond);
if (
ColChainListOfFirst.size() >= 3
|| RowChainListOfFirst.size() >= 3
|| ColChainListOfSecond.size() >= 3
|| RowChainListOfSecond.size() >= 3
)
{
m_srcSushi->runAction(MoveTo::create(time, posOfDest));
m_destSushi->runAction(MoveTo::create(time, posOfSrc));
return;
}
m_matrix[m_srcSushi->getRow() * m_width + m_srcSushi->getCol()] = m_destSushi;
m_matrix[m_destSushi->getRow() * m_width + m_destSushi->getCol()] = m_srcSushi;
tmpRow = m_srcSushi->getRow();
tmpCol = m_srcSushi->getCol();
m_srcSushi->setRow(m_destSushi->getRow());
m_srcSushi->setCol(m_destSushi->getCol());
m_destSushi->setRow(tmpRow);
m_destSushi->setCol(tmpCol);
m_srcSushi->runAction(Sequence::create(
MoveTo::create(time, posOfDest),
MoveTo::create(time, posOfSrc),
NULL));
m_destSushi->runAction(Sequence::create(
MoveTo::create(time, posOfSrc),
MoveTo::create(time, posOfDest),
NULL));
}
void PlayLayer::sendMsg()
{
NotificationCenter::getInstance()->postNotification("score");
}