CBonus.js 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. function CBonus(iXPos, iYPos, oSprite, iType, iID) {
  2. var _aCbCompleted;
  3. var _aCbOwner;
  4. var _oBonus;
  5. var _oInfoData = {};
  6. var _bBonusUnload;
  7. var _iSpeed;
  8. var _iBonusOffset;
  9. this._init = function (iXPos, iYPos, oSprite, iType, iID) {
  10. _aCbCompleted = new Array();
  11. _aCbOwner = new Array();
  12. _bBonusUnload = false;
  13. _oInfoData["Type"] = iType;
  14. _oInfoData["ID"] = iID;
  15. if (iType === 0 || iType === 7 || iType === 9) {
  16. var oData = {
  17. images: [oSprite],
  18. // width, height & registration point of each sprite
  19. frames: {width: oSprite.width / 5, height: oSprite.height / 2, regX: (oSprite.width / 2) / 5, regY: (oSprite.height / 2) / 2},
  20. animations: {normal: [0, 9, "normal", 1]}
  21. };
  22. var oSpriteSheet = new createjs.SpriteSheet(oData);
  23. _oBonus = createSprite(oSpriteSheet, "normal", (oSprite.width / 2) / 5, (oSprite.height / 2) / 2, oSprite.width / 5, oSprite.height / 2);
  24. _oInfoData["offsetX"] = (oSprite.width / 5) / 2;
  25. _oInfoData["offsetY"] = (oSprite.height / 2) / 2;
  26. } else if (iType === 1 || iType === 2 || iType === 4 || iType === 5 || iType === 8) {
  27. var oData = {
  28. images: [oSprite],
  29. // width, height & registration point of each sprite
  30. frames: {width: oSprite.width / 4, height: oSprite.height / 2, regX: (oSprite.width / 2) / 4, regY: (oSprite.height / 2) / 2},
  31. animations: {normal: [0, 7, "normal", 1]}
  32. };
  33. var oSpriteSheet = new createjs.SpriteSheet(oData);
  34. _oBonus = createSprite(oSpriteSheet, "normal", (oSprite.width / 2) / 4, (oSprite.height / 2) / 2, oSprite.width / 4, oSprite.height / 2);
  35. _oInfoData["offsetX"] = (oSprite.width / 4) / 2;
  36. _oInfoData["offsetY"] = (oSprite.height / 2) / 2;
  37. } else {
  38. var oData = {
  39. images: [oSprite],
  40. // width, height & registration point of each sprite
  41. frames: {width: oSprite.width / 6, height: oSprite.height / 2, regX: (oSprite.width / 2) / 6, regY: (oSprite.height / 2) / 2},
  42. animations: {normal: [0, 11, "normal", 1]}
  43. };
  44. var oSpriteSheet = new createjs.SpriteSheet(oData);
  45. _oBonus = createSprite(oSpriteSheet, "normal", (oSprite.width / 2) / 6, (oSprite.height / 2) / 2, oSprite.width / 6, oSprite.height / 2);
  46. _oInfoData["offsetX"] = (oSprite.width / 6) / 2;
  47. _oInfoData["offsetY"] = (oSprite.height / 2) / 2;
  48. }
  49. _iSpeed = BONUS_SPEED;
  50. _oBonus.x = iXPos;
  51. _oBonus.y = iYPos;
  52. s_oStage.addChild(_oBonus);
  53. //s_oStage.setChildIndex(_oBonus,s_oStage.numChildren-1);
  54. _iBonusOffset = CANVAS_HEIGHT + _oInfoData["offsetX"];
  55. };
  56. this.getX = function () {
  57. return _oBonus.x;
  58. };
  59. this.getY = function () {
  60. return _oBonus.y;
  61. };
  62. this.setInfoData = function (szKey, oValue) {
  63. _oInfoData[szKey] = oValue;
  64. };
  65. this.getInfoData = function (szKey) {
  66. return _oInfoData[szKey];
  67. };
  68. this.resetTheIndex = function (iValue) {
  69. _oInfoData["ID"] = iValue;
  70. };
  71. this.unload = function () {
  72. s_oStage.removeChild(_oBonus);
  73. };
  74. this.update = function () {
  75. _oBonus.y += _iSpeed;
  76. if (_oBonus.y < _iBonusOffset) {
  77. return;
  78. }
  79. else
  80. {
  81. s_oGame.unloadBonus(_oInfoData["ID"]);
  82. }
  83. };
  84. s_oBonus = this;
  85. this._init(iXPos, iYPos, oSprite, iType, iID);
  86. }
  87. var s_oBonus;