CNextBlock.js 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. function CNextBlock(aBlock, oSprite, oParentContainer) {
  2. var _oParentContainer = oParentContainer;
  3. var _aSpriteBlock;
  4. var _iOffsetX;
  5. var _iOffsetY;
  6. this._init = function (aBlock, oSprite) {
  7. _iOffsetX = 0;
  8. _aSpriteBlock = this.createSpriteBlock(aBlock, oSprite);
  9. this.orderCellsChildIndex();
  10. };
  11. this.createSpriteBlock = function (aBlock, oSprite) {
  12. var aSpriteBlock = new Array();
  13. var iX = 0;
  14. var iY = 0;
  15. for (var i = 0; i < aBlock.length; i++) {
  16. for (var j = 0; j < aBlock[i].length; j++) {
  17. if (aBlock[i][j] === 1) {
  18. aSpriteBlock.push(this.createCell(iX, iY, oSprite, 0));
  19. }
  20. iX += CELL_SIZE + CELL_OFFSET.x;
  21. }
  22. iY += CELL_SIZE + CELL_OFFSET.y;
  23. iX = 0;
  24. }
  25. _iOffsetX = ((CELL_SIZE + CELL_OFFSET.y) * 0.5) * aBlock[0].length;
  26. _iOffsetY = ((CELL_SIZE + CELL_OFFSET.x) * 0.5) * aBlock.length;
  27. return aSpriteBlock;
  28. };
  29. this.createCell = function (iX, iY, oSprite, iRegY) {
  30. var oCell = new CCell(iX, iY, iRegY, oSprite, _oParentContainer);
  31. oCell.setPosition(iX, iY);
  32. return oCell;
  33. };
  34. this.orderCellsChildIndex = function () {
  35. var iID = _oParentContainer.numChildren - 1;
  36. for (var i = 0; i < _aSpriteBlock.length; i++) {
  37. _aSpriteBlock[i].setChildIndex(iID);
  38. iID--;
  39. }
  40. };
  41. this.getOffsetX = function () {
  42. return _iOffsetX;
  43. };
  44. this.getOffsetY = function () {
  45. return _iOffsetY;
  46. };
  47. this.unload = function () {
  48. for (var i = 0; i < _aSpriteBlock.length; i++) {
  49. _aSpriteBlock[i].unload();
  50. }
  51. _aSpriteBlock = null;
  52. };
  53. this._init(aBlock, oSprite);
  54. return this;
  55. }