CPinDragger.js 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  1. function CPinDragger(iXPos, iYPos, oSprite, oParentContainer) {
  2. var _oPinBinder;
  3. var _oParentContainer;
  4. this._init = function (iXPos, iYPos, oSprite, oParentContainer) {
  5. _oParentContainer = oParentContainer;
  6. var fAnimSpeed = 30 / FPS;
  7. var oData = {
  8. images: [oSprite],
  9. // width, height & registration point of each sprite
  10. frames: {width: oSprite.width / 8, height: oSprite.height / 4, regX: (oSprite.width / 2) / 8, regY: (oSprite.height / 2) / 4},
  11. animations: {
  12. up: {
  13. frames: [8, 7, 6, 5, 4, 3, 2, 1, 0],
  14. speed: fAnimSpeed
  15. },
  16. down: [0, 8, 8, fAnimSpeed - 0.15],
  17. throw_pins_0: [0, 8, "throw_pins_1", fAnimSpeed],
  18. throw_pins_1: [9, 31, 31, fAnimSpeed]
  19. }
  20. };
  21. var oSpriteSheet = new createjs.SpriteSheet(oData);
  22. _oPinBinder = createSprite(oSpriteSheet, "run", (oSprite.width / 2) / 10, (oSprite.height / 2) / 4, oSprite.width / 10, oSprite.height / 6);
  23. _oPinBinder.x = iXPos;
  24. _oPinBinder.y = iYPos;
  25. _oParentContainer.addChild(_oPinBinder);
  26. };
  27. this.getX = function () {
  28. return _oPinBinder.x;
  29. };
  30. this.getY = function () {
  31. return _oPinBinder.y;
  32. };
  33. this.animThrowPins = function () {
  34. var oParent = this;
  35. _oPinBinder.gotoAndPlay("throw_pins_0");
  36. this.onFinishAnimation(function () {
  37. var oPinBinderBody = s_oScenario.getPinsBinder();
  38. createjs.Tween.get(oPinBinderBody.position).to({y: PIN_BINDER_TO_Y}, 900).call(function () {
  39. s_oGame.isAwakwePins(false);
  40. });
  41. s_oGame.isAwakwePins(true);
  42. _oPinBinder.gotoAndPlay("throw_pins_1");
  43. playSound("binder", 1, false);
  44. _oPinBinder.removeAllEventListeners();
  45. oParent.onFinishAnimation(function () {
  46. _oPinBinder.gotoAndStop(31);
  47. _oPinBinder.removeAllEventListeners();
  48. createjs.Tween.get(this).wait(500).call(function () {
  49. s_oGame.setPinsPhysicsMovement(false);
  50. s_oGame.repositionPins();
  51. s_oGame.resetScene();
  52. createjs.Tween.get(this).wait(200).call(function () {
  53. _oPinBinder.gotoAndPlay("down");
  54. oParent.onFinishAnimation(function () {
  55. _oPinBinder.gotoAndStop(8);
  56. createjs.Tween.get(this).wait(200).call(function () {
  57. _oPinBinder.gotoAndPlay("up");
  58. s_oGame.updatePinsPosition();
  59. _oPinBinder.removeAllEventListeners();
  60. oParent.onFinishAnimation(function () {
  61. _oPinBinder.visible = false;
  62. s_oGame.setPinsPhysicsMovement(true);
  63. s_oGame.nextStage();
  64. _oPinBinder.removeAllEventListeners();
  65. });
  66. });
  67. });
  68. });
  69. });
  70. });
  71. });
  72. };
  73. this.takeRemainPinsAndRepos = function () {
  74. var oParent = this;
  75. _oPinBinder.gotoAndPlay("down");
  76. oParent.onFinishAnimation(function () {
  77. createjs.Tween.get(oParent).wait(200).call(function () {
  78. _oPinBinder.gotoAndPlay("up");
  79. s_oGame.setPinsPhysicsMovement(false);
  80. s_oGame.animUpRemainPins();
  81. _oPinBinder.removeAllEventListeners();
  82. oParent.onFinishAnimation(function () {
  83. _oPinBinder.gotoAndPlay("throw_pins_0");
  84. _oPinBinder.removeAllEventListeners();
  85. oParent.onFinishAnimation(function () {
  86. var oPinBinderBody = s_oScenario.getPinsBinder();
  87. createjs.Tween.get(oPinBinderBody.position).to({y: PIN_BINDER_TO_Y}, 900).call(function () {
  88. s_oGame.isAwakwePins(false);
  89. });
  90. s_oGame.isAwakwePins(true);
  91. _oPinBinder.gotoAndPlay("throw_pins_1");
  92. playSound("binder", 1, false);
  93. s_oGame.setPinsPhysicsMovement(true);
  94. _oPinBinder.removeAllEventListeners();
  95. oParent.onFinishAnimation(function () {
  96. _oPinBinder.gotoAndStop(31);
  97. _oPinBinder.removeAllEventListeners();
  98. createjs.Tween.get(this).wait(500).call(function () {
  99. s_oScenario.getPinsBinder().collisionResponse = 0;
  100. createjs.Tween.get(this).wait(200).call(function () {
  101. _oPinBinder.gotoAndPlay("down");
  102. s_oGame.setPinsPhysicsMovement(false);
  103. s_oGame.repositionRemainPins();
  104. oParent.onFinishAnimation(function () {
  105. _oPinBinder.gotoAndStop(8);
  106. createjs.Tween.get(this).wait(200).call(function () {
  107. _oPinBinder.gotoAndPlay("up");
  108. _oPinBinder.removeAllEventListeners();
  109. oParent.onFinishAnimation(function () {
  110. _oPinBinder.visible = false;
  111. s_oScenario.getPinsBinder().position.y = PINS_BINDER_POSITION.y;
  112. s_oGame.activeControl();
  113. s_oGame.setPinsPhysicsMovement(true);
  114. _oPinBinder.removeAllEventListeners();
  115. });
  116. });
  117. });
  118. });
  119. });
  120. });
  121. });
  122. });
  123. });
  124. });
  125. };
  126. this.setPosition = function (iXPos, iYPos) {
  127. _oPinBinder.x = iXPos;
  128. _oPinBinder.y = iYPos;
  129. };
  130. this.setVisible = function (bVal) {
  131. _oPinBinder.visible = bVal;
  132. };
  133. this.changeState = function (szState) {
  134. _oPinBinder.gotoAndPlay(szState);
  135. };
  136. this.onFinishAnimation = function (oFunc) {
  137. _oPinBinder.on("animationend", function () {
  138. oFunc();
  139. });
  140. };
  141. s_oPinBinder = this;
  142. this._init(iXPos, iYPos, oSprite, oParentContainer);
  143. }
  144. var s_oPinBinder;