CBrick.js 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. function CBrick(iXPos, iYPos, oSprite, iResistance, bDestructible) {
  2. var _oBrick;
  3. var _oInfoData = {};
  4. this._init = function () {
  5. if (iResistance < 1 && bDestructible === true) {
  6. _oBrick = createBitmap(oSprite);
  7. _oBrick.regX = oSprite.width / 2;
  8. _oBrick.regY = oSprite.height / 2;
  9. _oInfoData["Effect"] = false;
  10. }
  11. else
  12. {
  13. if (bDestructible === true) {
  14. var oData = {
  15. images: [oSprite],
  16. // width, height & registration point of each sprite
  17. frames: {width: oSprite.width / 4, height: oSprite.height / 2, regX: (oSprite.width / 2) / 4, regY: (oSprite.height / 2) / 2},
  18. animations: {normal: 1, destroyed: [2, 7, "destroyed"]}
  19. };
  20. var oSpriteSheet = new createjs.SpriteSheet(oData);
  21. _oBrick = createSprite(oSpriteSheet, "normal", (oSprite.width / 2) / 4, (oSprite.height / 2) / 2, oSprite.width / 4, oSprite.height / 2);
  22. _oInfoData["Effect"] = true;
  23. }else {
  24. var oData = {
  25. images: [oSprite],
  26. // width, height & registration point of each sprite
  27. frames: {width: oSprite.width / 8, height: oSprite.height / 2, regX: (oSprite.width / 2) / 8, regY: (oSprite.height / 2) / 2},
  28. animations: {start:0,reflect: [0, 15, "start", 0.5]}
  29. };
  30. var oSpriteSheet = new createjs.SpriteSheet(oData);
  31. _oBrick = createSprite(oSpriteSheet, "start", (oSprite.width / 2) / 8, (oSprite.height / 2) / 2, oSprite.width / 8, oSprite.height / 2);
  32. _oInfoData["Effect"] = false;
  33. _oInfoData["Reflect"] = false;
  34. }
  35. }
  36. _oBrick.x = iXPos;
  37. _oBrick.y = iYPos;
  38. s_oStage.addChild(_oBrick);
  39. };
  40. this.getX = function () {
  41. return _oBrick.x;
  42. };
  43. this.getY = function () {
  44. return _oBrick.y;
  45. };
  46. this.setInfoData = function (szKey, oValue) {
  47. _oInfoData[szKey] = oValue;
  48. };
  49. this.getInfoData = function (szKey) {
  50. return _oInfoData[szKey];
  51. };
  52. this.animBrick = function (szState) {
  53. _oBrick.gotoAndPlay(szState);
  54. _oBrick.on("animationend", function () {
  55. s_oStage.removeChild(_oBrick);
  56. });
  57. };
  58. this.reflectBrick = function () {
  59. if (_oInfoData["Reflect"] === true) {
  60. return;
  61. }
  62. _oBrick.gotoAndPlay("reflect");
  63. _oBrick.on("animationend", function () {
  64. _oBrick.gotoAndStop("reflect");
  65. _oInfoData["Reflect"] = false;
  66. });
  67. };
  68. this.setPosition = function (iXPos, iYPos) {
  69. _oBrick.x = iXPos;
  70. _oBrick.y = iYPos;
  71. };
  72. this.setChildIndex = function (iValue) {
  73. s_oStage.setChildIndex(_oBrick, iValue);
  74. };
  75. this.damageBrick = function (iRes) {
  76. _oBrick.gotoAndStop(iRes);
  77. };
  78. this.unload = function () {
  79. s_oStage.removeChild(_oBrick);
  80. s_oBrick = null;
  81. };
  82. this.update = function () {
  83. };
  84. s_oBrick = this;
  85. this._init();
  86. }
  87. var s_oBrick;