1 /****************************************************************************
  2  Copyright (c) 2010-2012 cocos2d-x.org
  3  Copyright (c) 2008-2010 Ricardo Quesada
  4  Copyright (c) 2011      Zynga Inc.
  5 
  6  http://www.cocos2d-x.org
  7 
  8  Permission is hereby granted, free of charge, to any person obtaining a copy
  9  of this software and associated documentation files (the "Software"), to deal
 10  in the Software without restriction, including without limitation the rights
 11  to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 12  copies of the Software, and to permit persons to whom the Software is
 13  furnished to do so, subject to the following conditions:
 14 
 15  The above copyright notice and this permission notice shall be included in
 16  all copies or substantial portions of the Software.
 17 
 18  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 19  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 20  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 21  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 22  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 23  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 24  THE SOFTWARE.
 25  ****************************************************************************/
 26 
 27 /**
 28  * cc.ShakyTiles3D action
 29  * @class
 30  * @extends cc.TiledGrid3DAction
 31  */
 32 cc.ShakyTiles3D = cc.TiledGrid3DAction.extend(/** @lends cc.ShakyTiles3D# */{
 33     _randRange:0,
 34     _shakeZ:false,
 35 
 36     ctor:function () {
 37         cc.GridAction.prototype.ctor.call(this);
 38         this._randRange = 0;
 39         this._shakeZ = false;
 40     },
 41 
 42     /**
 43      * initializes the action with a range, whether or not to shake Z vertices, a grid size, and duration
 44      * @param {Number} duration
 45      * @param {cc.Size} gridSize
 46      * @param {Number} range
 47      * @param {Boolean} shakeZ
 48      * @return {Boolean}
 49      */
 50     initWithDuration:function (duration, gridSize, range, shakeZ) {
 51         if (cc.TiledGrid3DAction.prototype.initWithDuration.call(this, duration, gridSize)) {
 52             this._randRange = range;
 53             this._shakeZ = shakeZ;
 54             return true;
 55         }
 56         return false;
 57     },
 58 
 59     update:function (time) {
 60         var locGridSize = this._gridSize, locRandRange = this._randRange;
 61         var locPos = cc.p(0, 0);
 62         for (var i = 0; i < locGridSize.width; ++i) {
 63             for (var j = 0; j < locGridSize.height; ++j) {
 64                 locPos.x = i;
 65                 locPos.y = j;
 66                 var coords = this.originalTile(locPos);
 67 
 68                 // X
 69                 coords.bl.x += ( cc.rand() % (locRandRange * 2) ) - locRandRange;
 70                 coords.br.x += ( cc.rand() % (locRandRange * 2) ) - locRandRange;
 71                 coords.tl.x += ( cc.rand() % (locRandRange * 2) ) - locRandRange;
 72                 coords.tr.x += ( cc.rand() % (locRandRange * 2) ) - locRandRange;
 73 
 74                 // Y
 75                 coords.bl.y += ( cc.rand() % (locRandRange * 2) ) - locRandRange;
 76                 coords.br.y += ( cc.rand() % (locRandRange * 2) ) - locRandRange;
 77                 coords.tl.y += ( cc.rand() % (locRandRange * 2) ) - locRandRange;
 78                 coords.tr.y += ( cc.rand() % (locRandRange * 2) ) - locRandRange;
 79 
 80                 if (this._shakeZ) {
 81                     coords.bl.z += ( cc.rand() % (locRandRange * 2) ) - locRandRange;
 82                     coords.br.z += ( cc.rand() % (locRandRange * 2) ) - locRandRange;
 83                     coords.tl.z += ( cc.rand() % (locRandRange * 2) ) - locRandRange;
 84                     coords.tr.z += ( cc.rand() % (locRandRange * 2) ) - locRandRange;
 85                 }
 86 
 87                 this.setTile(locPos, coords);
 88             }
 89         }
 90     }
 91 });
 92 
 93 /**
 94  * creates the action with a range, whether or not to shake Z vertices, a grid size, and duration
 95  * @param {Number} duration
 96  * @param {cc.Size} gridSize
 97  * @param {Number} range
 98  * @param {Boolean} shakeZ
 99  * @return {cc.ShakyTiles3D}
100  */
101 cc.ShakyTiles3D.create = function (duration, gridSize, range, shakeZ) {
102     var action = new cc.ShakyTiles3D();
103     action.initWithDuration(duration, gridSize, range, shakeZ);
104     return action;
105 };
106 
107 /**
108  * cc.ShatteredTiles3D action
109  * @class
110  * @extends cc.TiledGrid3DAction
111  */
112 cc.ShatteredTiles3D = cc.TiledGrid3DAction.extend(/** @lends cc.ShatteredTiles3D# */{
113     _randRange:0,
114     _once:false,
115     _shatterZ:false,
116 
117     ctor:function () {
118         cc.GridAction.prototype.ctor.call(this);
119         this._randRange = 0;
120         this._shakeZ = false;
121         this._once = false;
122     },
123 
124     /**
125      * initializes the action with a range, whether or not to shatter Z vertices, a grid size and duration
126      * @param {Number} duration
127      * @param {cc.Size} gridSize
128      * @param {Number} range
129      * @param {Boolean} shatterZ
130      * @return {Boolean}
131      */
132     initWithDuration:function (duration, gridSize, range, shatterZ) {
133         if (cc.TiledGrid3DAction.prototype.initWithDuration.call(this, duration, gridSize)) {
134             this._once = false;
135             this._randRange = range;
136             this._shatterZ = shatterZ;
137             return true;
138         }
139         return false;
140     },
141 
142     update:function (time) {
143         if (this._once === false) {
144             var locGridSize = this._gridSize, locRandRange = this._randRange;
145             var coords, locPos = cc.p(0, 0);
146             for (var i = 0; i < locGridSize.width; ++i) {
147                 for (var j = 0; j < locGridSize.height; ++j) {
148                     locPos.x = i;
149                     locPos.y = j;
150                     coords = this.originalTile(locPos);
151 
152                     // X
153                     coords.bl.x += ( cc.rand() % (locRandRange * 2) ) - locRandRange;
154                     coords.br.x += ( cc.rand() % (locRandRange * 2) ) - locRandRange;
155                     coords.tl.x += ( cc.rand() % (locRandRange * 2) ) - locRandRange;
156                     coords.tr.x += ( cc.rand() % (locRandRange * 2) ) - locRandRange;
157 
158                     // Y
159                     coords.bl.y += ( cc.rand() % (locRandRange * 2) ) - locRandRange;
160                     coords.br.y += ( cc.rand() % (locRandRange * 2) ) - locRandRange;
161                     coords.tl.y += ( cc.rand() % (locRandRange * 2) ) - locRandRange;
162                     coords.tr.y += ( cc.rand() % (locRandRange * 2) ) - locRandRange;
163 
164                     if (this._shatterZ) {
165                         coords.bl.z += ( cc.rand() % (locRandRange * 2) ) - locRandRange;
166                         coords.br.z += ( cc.rand() % (locRandRange * 2) ) - locRandRange;
167                         coords.tl.z += ( cc.rand() % (locRandRange * 2) ) - locRandRange;
168                         coords.tr.z += ( cc.rand() % (locRandRange * 2) ) - locRandRange;
169                     }
170                     this.setTile(locPos, coords);
171                 }
172             }
173             this._once = true;
174         }
175     }
176 });
177 
178 /**
179  * creates the action with a range, whether of not to shatter Z vertices, a grid size and duration
180  * @param {Number} duration
181  * @param {cc.Size} gridSize
182  * @param {Number} range
183  * @param {Boolean} shatterZ
184  * @return {cc.ShatteredTiles3D}
185  */
186 cc.ShatteredTiles3D.create = function (duration, gridSize, range, shatterZ) {
187     var action = new cc.ShatteredTiles3D();
188     action.initWithDuration(duration, gridSize, range, shatterZ);
189     return action;
190 };
191 
192 /**
193  * A Tile composed of position, startPosition and delta
194  * @Class
195  * @constructor
196  * @param {cc.Point} [position=cc.Point_ZERO]
197  * @param {cc.Point} [startPosition=cc.Point_ZERO]
198  * @param {cc.Size} [delta=cc.Point_ZERO]
199  */
200 cc.Tile = function (position, startPosition, delta) {
201     this.position = position || cc.POINT_ZERO;
202     this.startPosition = startPosition || cc.POINT_ZERO;
203     this.delta = delta || cc.POINT_ZERO;
204 };
205 
206 /**
207  * cc.ShuffleTiles action, Shuffle the tiles in random order
208  * @class
209  * @extends cc.TiledGrid3DAction
210  */
211 cc.ShuffleTiles = cc.TiledGrid3DAction.extend(/** @lends cc.ShuffleTiles# */{
212     _seed:0,
213     _tilesCount:0,
214     _tilesOrder:null,
215     _tiles:null,
216 
217     ctor:function () {
218         cc.GridAction.prototype.ctor.call(this);
219         this._tilesOrder = [];
220         this._tiles = [];
221         this._seed = 0;
222         this._tilesCount = 0;
223     },
224 
225     /**
226      * initializes the action with a random seed, the grid size and the duration
227      * @param {Number} duration
228      * @param {cc.Size} gridSize
229      * @param {Number} seed
230      * @return {Boolean}
231      */
232     initWithDuration:function (duration, gridSize, seed) {
233         if (cc.TiledGrid3DAction.prototype.initWithDuration.call(this, duration, gridSize)) {
234             this._seed = seed;
235             this._tilesOrder.length = 0;
236             this._tiles.length = 0;
237             return true;
238         }
239         return false;
240     },
241 
242     /**
243      *  shuffle
244      * @param {Array} array
245      * @param {Number} len
246      */
247     shuffle:function (array, len) {
248         for (var i = len - 1; i >= 0; i--) {
249             var j = 0 | (cc.rand() % (i + 1));
250             var v = array[i];
251             array[i] = array[j];
252             array[j] = v;
253         }
254     },
255 
256     /**
257      * get Delta
258      * @param {cc.Size} pos
259      */
260     getDelta:function (pos) {
261         var locGridSize = this._gridSize;
262         var idx = pos.width * locGridSize.height + pos.height;
263         return cc.size(((this._tilesOrder[idx] / locGridSize.height) - pos.width),
264             ((this._tilesOrder[idx] % locGridSize.height) - pos.height));
265     },
266 
267     /**
268      * place Tile
269      * @param {cc.Point} pos
270      * @param {cc.Tile} tile
271      */
272     placeTile:function (pos, tile) {
273         var coords = this.originalTile(pos);
274 
275         var step = this._target.getGrid().getStep();
276         var locPosition = tile.position;
277         coords.bl.x += (locPosition.x * step.x);
278         coords.bl.y += (locPosition.y * step.y);
279 
280         coords.br.x += (locPosition.x * step.x);
281         coords.br.y += (locPosition.y * step.y);
282 
283         coords.tl.x += (locPosition.x * step.x);
284         coords.tl.y += (locPosition.y * step.y);
285 
286         coords.tr.x += (locPosition.x * step.x);
287         coords.tr.y += (locPosition.y * step.y);
288 
289         this.setTile(pos, coords);
290     },
291 
292     /**
293      * start with target
294      * @param {cc.Node} target
295      */
296     startWithTarget:function (target) {
297         cc.TiledGrid3DAction.prototype.startWithTarget.call(this, target);
298         var locGridSize = this._gridSize;
299 
300         this._tilesCount = locGridSize.width * locGridSize.height;
301         var locTilesOrder = this._tilesOrder;
302         locTilesOrder.length = 0;
303 
304         /**
305          * Use k to loop. Because m_nTilesCount is unsigned int,
306          * and i is used later for int.
307          */
308         for (var k = 0; k < this._tilesCount; ++k)
309             locTilesOrder[k] = k;
310         this.shuffle(locTilesOrder, this._tilesCount);
311 
312         var locTiles = this._tiles ;
313         locTiles.length = 0;
314         var tileIndex = 0, tempSize = cc.size(0,0);
315         for (var i = 0; i < locGridSize.width; ++i) {
316             for (var j = 0; j < locGridSize.height; ++j) {
317                 locTiles[tileIndex] = new cc.Tile();
318                 locTiles[tileIndex].position = cc.p(i, j);
319                 locTiles[tileIndex].startPosition = cc.p(i, j);
320                 tempSize.width = i;
321                 tempSize.height = j;
322                 locTiles[tileIndex].delta = this.getDelta(tempSize);
323                 ++tileIndex;
324             }
325         }
326     },
327 
328     update:function (time) {
329         var tileIndex = 0, locGridSize = this._gridSize, locTiles = this._tiles;
330         var selTile, locPos = cc.p(0, 0);
331         for (var i = 0; i < locGridSize.width; ++i) {
332             for (var j = 0; j < locGridSize.height; ++j) {
333                 locPos.x = i;
334                 locPos.y = j;
335                 selTile = locTiles[tileIndex];
336                 selTile.position.x = selTile.delta.width * time;
337                 selTile.position.y = selTile.delta.height * time;
338                 this.placeTile(locPos, selTile);
339                 ++tileIndex;
340             }
341         }
342     }
343 });
344 
345 /**
346  * creates the action with a random seed, the grid size and the duration
347  * @param {Number} duration
348  * @param {cc.Size} gridSize
349  * @param {Number} seed
350  * @return {cc.ShuffleTiles}
351  */
352 cc.ShuffleTiles.create = function (duration, gridSize, seed) {
353     var action = new cc.ShuffleTiles();
354     action.initWithDuration(duration, gridSize, seed);
355     return action;
356 };
357 
358 /**
359  * cc.FadeOutTRTiles action. Fades out the tiles in a Top-Right direction
360  * @class
361  * @extends cc.TiledGrid3DAction
362  */
363 cc.FadeOutTRTiles = cc.TiledGrid3DAction.extend(/** @lends cc.FadeOutTRTiles# */{
364     /**
365      * @param {cc.Size} pos
366      * @param {Number} time
367      */
368     testFunc:function (pos, time) {
369         var locX = this._gridSize.width * time;
370         var locY = this._gridSize.height * time;
371         if ((locX + locY) == 0.0)
372             return 1.0;
373         return Math.pow((pos.width + pos.height) / (locX + locY), 6);
374     },
375 
376     /**
377      * turn on Tile
378      * @param {cc.Point} pos
379      */
380     turnOnTile:function (pos) {
381         this.setTile(pos, this.originalTile(pos));
382     },
383 
384     /**
385      * turn Off Tile
386      * @param {cc.Point} pos
387      */
388     turnOffTile:function (pos) {
389         this.setTile(pos, new cc.Quad3());
390     },
391 
392     /**
393      * transform tile
394      * @param {cc.Point} pos
395      * @param {Number} distance
396      */
397     transformTile:function (pos, distance) {
398         var coords = this.originalTile(pos);
399         var step = this._target.getGrid().getStep();
400 
401         coords.bl.x += (step.x / 2) * (1.0 - distance);
402         coords.bl.y += (step.y / 2) * (1.0 - distance);
403 
404         coords.br.x -= (step.x / 2) * (1.0 - distance);
405         coords.br.y += (step.y / 2) * (1.0 - distance);
406 
407         coords.tl.x += (step.x / 2) * (1.0 - distance);
408         coords.tl.y -= (step.y / 2) * (1.0 - distance);
409 
410         coords.tr.x -= (step.x / 2) * (1.0 - distance);
411         coords.tr.y -= (step.y / 2) * (1.0 - distance);
412 
413         this.setTile(pos, coords);
414     },
415 
416     update:function (time) {
417         var locGridSize = this._gridSize;
418         var locPos = cc.p(0, 0), locSize = cc.size(0, 0), distance;
419         for (var i = 0; i < locGridSize.width; ++i) {
420             for (var j = 0; j < locGridSize.height; ++j) {
421                 locPos.x = i;
422                 locPos.y = j;
423                 locSize.width = i;
424                 locSize.height = j;
425                 distance = this.testFunc(locSize, time);
426                 if (distance == 0)
427                     this.turnOffTile(locPos);
428                 else if (distance < 1)
429                     this.transformTile(locPos, distance);
430                 else
431                     this.turnOnTile(locPos);
432             }
433         }
434     }
435 });
436 
437 /**
438  * creates the action with the grid size and the duration
439  * @param duration
440  * @param gridSize
441  * @return {cc.FadeOutTRTiles}
442  */
443 cc.FadeOutTRTiles.create = function (duration, gridSize) {
444     var action = new cc.FadeOutTRTiles();
445     action.initWithDuration(duration, gridSize);
446     return action;
447 };
448 
449 /**
450  * cc.FadeOutBLTiles action. Fades out the tiles in a Bottom-Left direction
451  * @class
452  * @extends cc.FadeOutTRTiles
453  */
454 cc.FadeOutBLTiles = cc.FadeOutTRTiles.extend(/** @lends cc.FadeOutBLTiles# */{
455     /**
456      * @param {cc.Size} pos
457      * @param {Number} time
458      */
459     testFunc:function (pos, time) {
460         var locX = this._gridSize.width * (1.0 - time);
461         var locY = this._gridSize.height * (1.0 - time);
462         if ((pos.width + pos.height) == 0)
463             return 1.0;
464 
465         return Math.pow((locX + locY) / (pos.width + pos.height), 6);
466     }
467 });
468 
469 /**
470  * creates the action with the grid size and the duration
471  * @param duration
472  * @param gridSize
473  * @return {cc.FadeOutBLTiles}
474  */
475 cc.FadeOutBLTiles.create = function (duration, gridSize) {
476     var action = new cc.FadeOutBLTiles();
477     action.initWithDuration(duration, gridSize);
478     return action;
479 };
480 
481 /**
482  * cc.FadeOutUpTiles action. Fades out the tiles in upwards direction
483  * @class
484  * @extends cc.FadeOutTRTiles
485  */
486 cc.FadeOutUpTiles = cc.FadeOutTRTiles.extend(/** @lends cc.FadeOutUpTiles# */{
487     testFunc:function (pos, time) {
488         var locY = this._gridSize.height * time;
489         if (locY == 0.0)
490             return 1.0;
491         return Math.pow(pos.height / locY, 6);
492     },
493 
494     transformTile:function (pos, distance) {
495         var coords = this.originalTile(pos);
496         var step = this._target.getGrid().getStep();
497 
498         coords.bl.y += (step.y / 2) * (1.0 - distance);
499         coords.br.y += (step.y / 2) * (1.0 - distance);
500         coords.tl.y -= (step.y / 2) * (1.0 - distance);
501         coords.tr.y -= (step.y / 2) * (1.0 - distance);
502 
503         this.setTile(pos, coords);
504     }
505 });
506 
507 /**
508  * creates the action with the grid size and the duration
509  * @param {Number} duration
510  * @param {cc.Size} gridSize
511  * @return {cc.FadeOutUpTiles}
512  */
513 cc.FadeOutUpTiles.create = function (duration, gridSize) {
514     var action = new cc.FadeOutUpTiles();
515     action.initWithDuration(duration, gridSize);
516     return action;
517 };
518 
519 /**
520  * cc.FadeOutDownTiles action. Fades out the tiles in downwards direction
521  * @class
522  * @extends cc.FadeOutUpTiles
523  */
524 cc.FadeOutDownTiles = cc.FadeOutUpTiles.extend(/** @lends cc.FadeOutDownTiles# */{
525     testFunc:function (pos, time) {
526         var locY = this._gridSize.height * (1.0 - time);
527         if (pos.height == 0)
528             return 1.0;
529         return Math.pow(locY / pos.height, 6);
530     }
531 });
532 
533 /**
534  * creates the action with the grid size and the duration
535  * @param {Number} duration
536  * @param {cc.Size} gridSize
537  * @return {cc.FadeOutDownTiles}
538  */
539 cc.FadeOutDownTiles.create = function (duration, gridSize) {
540     var action = new cc.FadeOutDownTiles();
541     action.initWithDuration(duration, gridSize);
542     return action;
543 };
544 
545 
546 /**
547  * cc.TurnOffTiles action.<br/>
548  * Turn off the files in random order
549  * @class
550  * @extends cc.TiledGrid3DAction
551  */
552 cc.TurnOffTiles = cc.TiledGrid3DAction.extend(/** @lends cc.TurnOffTiles# */{
553     _seed:null,
554     _tilesCount:0,
555     _tilesOrder:null,
556 
557     ctor:function () {
558         cc.GridAction.prototype.ctor.call(this);
559         this._tilesOrder = [];
560         this._seed = null;
561         this._tilesCount = 0;
562     },
563 
564     /** initializes the action with a random seed, the grid size and the duration
565      * @param {Number} duration
566      * @param {cc.Size} gridSize
567      * @param {Number} seed
568      * @return {Boolean}
569      */
570     initWithDuration:function (duration, gridSize, seed) {
571         if (cc.TiledGrid3DAction.prototype.initWithDuration.call(this, duration, gridSize)) {
572             this._seed = seed;
573             this._tilesOrder.length = 0;
574             return true;
575         }
576         return false;
577     },
578 
579     /**
580      * @param {Array} array
581      * @param {Number} len
582      */
583     shuffle:function (array, len) {
584         for (var i = len - 1; i >= 0; i--) {
585             var j = 0 | (cc.rand() % (i + 1));
586             var v = array[i];
587             array[i] = array[j];
588             array[j] = v;
589         }
590     },
591 
592     /**
593      * @param {cc.Point} pos
594      */
595     turnOnTile:function (pos) {
596         this.setTile(pos, this.originalTile(pos));
597     },
598 
599     /**
600      * @param {cc.Point} pos
601      */
602     turnOffTile:function (pos) {
603         this.setTile(pos, new cc.Quad3());
604     },
605 
606     /**
607      * @param {cc.Node} target
608      */
609     startWithTarget:function (target) {
610         cc.TiledGrid3DAction.prototype.startWithTarget.call(this, target);
611 
612         this._tilesCount = this._gridSize.width * this._gridSize.height;
613         var locTilesOrder = this._tilesOrder;
614         locTilesOrder.length = 0;
615         for (var i = 0; i < this._tilesCount; ++i)
616             locTilesOrder[i] = i;
617         this.shuffle(locTilesOrder, this._tilesCount);
618     },
619 
620     /**
621      * @param {Number} time
622      */
623     update:function (time) {
624         var l = 0 | (time * this._tilesCount), locGridSize = this._gridSize;
625         var t,tilePos = cc.p(0,0), locTilesOrder = this._tilesOrder;
626         for (var i = 0; i < this._tilesCount; i++) {
627             t = locTilesOrder[i];
628             tilePos.x = 0 | (t / locGridSize.height);
629             tilePos.y = t % (0 | locGridSize.height);
630             if (i < l)
631                 this.turnOffTile(tilePos);
632             else
633                 this.turnOnTile(tilePos);
634         }
635     }
636 });
637 
638 /**
639  * creates the action with a random seed, the grid size and the duration
640  * @param {Number} duration
641  * @param {cc.Size} gridSize
642  * @param {Number|Null} [seed=0]
643  * @return {cc.TurnOffTiles}
644  * @example
645  * // example
646  * // turnOffTiles without seed
647  * var toff = cc.TurnOffTiles.create(this._duration, cc.size(x, y));
648  *
649  * // turnOffTiles with seed
650  * var toff = cc.TurnOffTiles.create(this._duration, cc.size(x, y), 0);
651  */
652 cc.TurnOffTiles.create = function (duration, gridSize, seed) {
653     seed = seed || 0;
654     var action = new cc.TurnOffTiles();
655     action.initWithDuration(duration, gridSize, seed);
656     return action;
657 };
658 
659 /**
660  * cc.WavesTiles3D action.
661  * @class
662  * @extends cc.TiledGrid3DAction
663  */
664 cc.WavesTiles3D = cc.TiledGrid3DAction.extend(/** @lends cc.WavesTiles3D# */{
665     _waves:0,
666     _amplitude:0,
667     _amplitudeRate:0,
668 
669     ctor:function () {
670         cc.GridAction.prototype.ctor.call(this);
671         this._waves = 0;
672         this._amplitude = 0;
673         this._amplitudeRate = 0;
674     },
675 
676     /**
677      * get amplitude of waves
678      * @return {Number}
679      */
680     getAmplitude:function () {
681         return this._amplitude;
682     },
683 
684     /**
685      * set amplitude of waves
686      * @param {Number} amplitude
687      */
688     setAmplitude:function (amplitude) {
689         this._amplitude = amplitude;
690     },
691 
692     /**
693      * get amplitude rate of waves
694      * @return {Number}
695      */
696     getAmplitudeRate:function () {
697         return this._amplitudeRate;
698     },
699 
700     /**
701      * set amplitude rate of waves
702      * @param {Number} amplitudeRate
703      */
704     setAmplitudeRate:function (amplitudeRate) {
705         this._amplitudeRate = amplitudeRate;
706     },
707 
708     /**
709      * initializes the action with a number of waves, the waves amplitude, the grid size and the duration
710      * @param {Number} duration
711      * @param {cc.Size} gridSize
712      * @param {Number} waves
713      * @param {Number} amplitude
714      * @return {Boolean}
715      */
716     initWithDuration:function (duration, gridSize, waves, amplitude) {
717         if (cc.TiledGrid3DAction.prototype.initWithDuration.call(this, duration, gridSize)) {
718             this._waves = waves;
719             this._amplitude = amplitude;
720             this._amplitudeRate = 1.0;
721             return true;
722         }
723         return false;
724     },
725 
726     update:function (time) {
727         var locGridSize = this._gridSize, locWaves = this._waves, locAmplitude = this._amplitude, locAmplitudeRate = this._amplitudeRate;
728         var locPos = cc.p(0, 0), coords;
729         for (var i = 0; i < locGridSize.width; i++) {
730             for (var j = 0; j < locGridSize.height; j++) {
731                 locPos.x = i;
732                 locPos.y = j;
733                 coords = this.originalTile(locPos);
734                 coords.bl.z = (Math.sin(time * Math.PI * locWaves * 2 +
735                     (coords.bl.y + coords.bl.x) * 0.01) * locAmplitude * locAmplitudeRate);
736                 coords.br.z = coords.bl.z;
737                 coords.tl.z = coords.bl.z;
738                 coords.tr.z = coords.bl.z;
739                 this.setTile(locPos, coords);
740             }
741         }
742     }
743 });
744 
745 /**
746  * creates the action with a number of waves, the waves amplitude, the grid size and the duration
747  * @param {Number} duration
748  * @param {cc.Size} gridSize
749  * @param {Number} waves
750  * @param {Number} amplitude
751  * @return {cc.WavesTiles3D}
752  */
753 cc.WavesTiles3D.create = function (duration, gridSize, waves, amplitude) {
754     var action = new cc.WavesTiles3D();
755     action.initWithDuration(duration, gridSize, waves, amplitude);
756     return action;
757 };
758 
759 /**
760  * cc.JumpTiles3D action.  A sin function is executed to move the tiles across the Z axis
761  * @class
762  * @extends cc.TiledGrid3DAction
763  */
764 cc.JumpTiles3D = cc.TiledGrid3DAction.extend(/** @lends cc.JumpTiles3D# */{
765     _jumps:0,
766     _amplitude:0,
767     _amplitudeRate:0,
768 
769     ctor:function () {
770         cc.GridAction.prototype.ctor.call(this);
771         this._jumps = 0;
772         this._amplitude = 0;
773         this._amplitudeRate = 0;
774     },
775 
776     /**
777      * get amplitude of the sin
778      * @return {Number}
779      */
780     getAmplitude:function () {
781         return this._amplitude;
782     },
783 
784     /**
785      * set amplitude of the sin
786      * @param {Number} amplitude
787      */
788     setAmplitude:function (amplitude) {
789         this._amplitude = amplitude;
790     },
791 
792     /**
793      * get amplitude rate
794      * @return {Number}
795      */
796     getAmplitudeRate:function () {
797         return this._amplitudeRate;
798     },
799 
800     /**
801      * set amplitude rate
802      * @param amplitudeRate
803      */
804     setAmplitudeRate:function (amplitudeRate) {
805         this._amplitudeRate = amplitudeRate;
806     },
807 
808     /**
809      * initializes the action with the number of jumps, the sin amplitude, the grid size and the duration
810      * @param {Number} duration
811      * @param {cc.Size} gridSize
812      * @param {Number} numberOfJumps
813      * @param {Number} amplitude
814      */
815     initWithDuration:function (duration, gridSize, numberOfJumps, amplitude) {
816         if (cc.TiledGrid3DAction.prototype.initWithDuration.call(this, duration, gridSize)) {
817             this._jumps = numberOfJumps;
818             this._amplitude = amplitude;
819             this._amplitudeRate = 1.0;
820             return true;
821         }
822         return false;
823     },
824 
825     update:function (time) {
826         var sinz = (Math.sin(Math.PI * time * this._jumps * 2) * this._amplitude * this._amplitudeRate );
827         var sinz2 = (Math.sin(Math.PI * (time * this._jumps * 2 + 1)) * this._amplitude * this._amplitudeRate );
828 
829         var locGridSize = this._gridSize;
830         var locGrid = this._target.getGrid();
831         var coords, locPos = cc.p(0, 0);
832         for (var i = 0; i < locGridSize.width; i++) {
833             for (var j = 0; j < locGridSize.height; j++) {
834                 locPos.x = i;
835                 locPos.y = j;
836                 //hack for html5
837                 //var coords = this.originalTile(cc.p(i, j));
838                 coords = locGrid.originalTile(locPos);
839 
840                 if (((i + j) % 2) == 0) {
841                     coords.bl.z += sinz;
842                     coords.br.z += sinz;
843                     coords.tl.z += sinz;
844                     coords.tr.z += sinz;
845                 } else {
846                     coords.bl.z += sinz2;
847                     coords.br.z += sinz2;
848                     coords.tl.z += sinz2;
849                     coords.tr.z += sinz2;
850                 }
851                 //hack for html5
852                 //this.setTile(cc.p(i, j), coords);
853                 locGrid.setTile(locPos, coords);
854             }
855         }
856     }
857 });
858 
859 /**
860  * creates the action with the number of jumps, the sin amplitude, the grid size and the duration
861  * @param {Number} duration
862  * @param {cc.Size} gridSize
863  * @param {Number} numberOfJumps
864  * @param {Number} amplitude
865  * @return {cc.JumpTiles3D}
866  */
867 cc.JumpTiles3D.create = function (duration, gridSize, numberOfJumps, amplitude) {
868     var action = new cc.JumpTiles3D();
869     action.initWithDuration(duration, gridSize, numberOfJumps, amplitude);
870     return action;
871 };
872 
873 /**
874  * cc.SplitRows action
875  * @class
876  * @extends cc.TiledGrid3DAction
877  */
878 cc.SplitRows = cc.TiledGrid3DAction.extend(/** @lends cc.SplitRows# */{
879     _rows:0,
880     _winSize:null,
881 
882     ctor:function () {
883         cc.GridAction.prototype.ctor.call(this);
884         this._rows = 0;
885         this._winSize = null;
886     },
887 
888     /**
889      * initializes the action with the number of rows to split and the duration
890      * @param {Number} duration
891      * @param {Number} rows
892      * @return {Boolean}
893      */
894     initWithDuration:function (duration, rows) {
895         this._rows = rows;
896         return cc.TiledGrid3DAction.prototype.initWithDuration.call(this, duration, cc.size(1, rows));
897     },
898 
899     update:function (time) {
900         var locGridSize = this._gridSize, locWinSizeWidth = this._winSize.width;
901         var coords, direction, locPos = cc.p(0, 0);
902         for (var j = 0; j < locGridSize.height; ++j) {
903             locPos.y = j;
904             coords = this.originalTile(locPos);
905             direction = 1;
906 
907             if ((j % 2 ) == 0)
908                 direction = -1;
909 
910             coords.bl.x += direction * locWinSizeWidth * time;
911             coords.br.x += direction * locWinSizeWidth * time;
912             coords.tl.x += direction * locWinSizeWidth * time;
913             coords.tr.x += direction * locWinSizeWidth * time;
914 
915             this.setTile(locPos, coords);
916         }
917     },
918 
919     startWithTarget:function (target) {
920         cc.TiledGrid3DAction.prototype.startWithTarget.call(this, target);
921         this._winSize = cc.Director.getInstance().getWinSizeInPixels();
922     }
923 });
924 
925 /**
926  * creates the action with the number of rows to split and the duration
927  * @param {Number} duration
928  * @param {Number} rows
929  * @return {cc.SplitRows}
930  */
931 cc.SplitRows.create = function (duration, rows) {
932     var action = new cc.SplitRows();
933     action.initWithDuration(duration, rows);
934     return action;
935 };
936 
937 /**
938  * cc.SplitCols action
939  * @class
940  * @extends cc.TiledGrid3DAction
941  */
942 cc.SplitCols = cc.TiledGrid3DAction.extend(/** @lends cc.SplitCols# */{
943     _cols:0,
944     _winSize:null,
945 
946     ctor:function () {
947         cc.GridAction.prototype.ctor.call(this);
948         this._cols = 0;
949         this._winSize = null;
950     },
951     /**
952      * initializes the action with the number of columns to split and the duration
953      * @param {Number} duration
954      * @param {Number} cols
955      * @return {Boolean}
956      */
957     initWithDuration:function (duration, cols) {
958         this._cols = cols;
959         return cc.TiledGrid3DAction.prototype.initWithDuration.call(this, duration, cc.size(cols, 1));
960     },
961 
962     update:function (time) {
963         var locGridSizeWidth = this._gridSize.width, locWinSizeHeight = this._winSize.height;
964         var coords, direction, locPos = cc.p(0, 0);
965         for (var i = 0; i < locGridSizeWidth; ++i) {
966             locPos.x = i;
967             coords = this.originalTile(locPos);
968             direction = 1;
969 
970             if ((i % 2 ) == 0)
971                 direction = -1;
972 
973             coords.bl.y += direction * locWinSizeHeight * time;
974             coords.br.y += direction * locWinSizeHeight * time;
975             coords.tl.y += direction * locWinSizeHeight * time;
976             coords.tr.y += direction * locWinSizeHeight * time;
977 
978             this.setTile(locPos, coords);
979         }
980     },
981 
982     /**
983      * @param {cc.Node} target
984      */
985     startWithTarget:function (target) {
986         cc.TiledGrid3DAction.prototype.startWithTarget.call(this, target);
987         this._winSize = cc.Director.getInstance().getWinSizeInPixels();
988     }
989 });
990 
991 /**
992  * creates the action with the number of columns to split and the duration
993  * @param {Number} duration
994  * @param {Number} cols
995  * @return {cc.SplitCols}
996  */
997 cc.SplitCols.create = function (duration, cols) {
998     var action = new cc.SplitCols();
999     action.initWithDuration(duration, cols);
1000     return action;
1001 };