Hook.js 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. function Hook() {
  2. base(this,LSprite,[]);
  3. this.init();
  4. }
  5. Hook.prototype.init = function() {
  6. var self = this;
  7. self.hookBitmapData = new LBitmapData(dataList["hook"],0,0,57,1100);
  8. self.hookBitmap = new LBitmap(self.hookBitmapData);
  9. self.hookBitmap.x = -27.5;
  10. self.hookBitmap.y = -822;
  11. self.x = LGlobal.width/2;
  12. self.y = 0;
  13. self.addChild(self.hookBitmap);
  14. // self.graphics.drawVertices(0,"#880088", [[26-26,194],[3-26,237],[4-26,264],[30-26,277],[50-26,268],[51-26,242],[40-26,196]], true, "#880088");
  15. self.addShape(LShape.VERTICES, [[26-26,194],[3-26,237],[4-26,264],[30-26,277],[50-26,268],[51-26,242],[40-26,196]])
  16. self.direction = -1;
  17. self.isShooting = false;
  18. self.addEventListener(LEvent.ENTER_FRAME, self.onframe);
  19. self.addEventListener(LMouseEvent.MOUSE_DOWN, self.onmousedown);
  20. };
  21. Hook.prototype.onframe = function(event) {
  22. var self = event.target;
  23. if(!self.isShooting) {
  24. self.rotate += self.direction * 1.5;
  25. if(Math.abs(self.rotate)>35) {
  26. self.direction = -self.direction;
  27. }
  28. } else {
  29. var r = self.rotate/180*Math.PI;
  30. var v = 20;
  31. self.x -= v*Math.sin(r)*self.shootDirection;
  32. self.y += v*Math.cos(r)*self.shootDirection;
  33. if(self.hitTestObject(self.parent.getChildByName("background"))) {
  34. self.shootDirection = -1;
  35. }
  36. if(!self.hasGotFish) {
  37. for(var i = 0; i < self.fishManager.childList.length; i++) {
  38. if(self.hitTestObject(self.fishManager.childList[i])) {
  39. self.fishOnHook = self.fishManager.childList[i];
  40. self.fishOnHook.beHooked();
  41. self.fishOnHook.rotate = self.rotate+90+(self.fishOnHook.motion.direction==0?0:180);
  42. self.shootDirection = -1;
  43. self.hasGotFish = true;
  44. self.parent.getChildByName("score").addScore(self.fishOnHook.stype, self.fishOnHook);
  45. break;
  46. }
  47. }
  48. } else {
  49. self.fishOnHook.x = self.x-270*Math.sin(r);
  50. self.fishOnHook.y = self.y+270*Math.cos(r);
  51. }
  52. if(self.y <= 0) {
  53. self.isShooting = false;
  54. self.x = LGlobal.width/2;
  55. self.y = 0;
  56. if(self.fishOnHook) {
  57. self.fishOnHook.remove();
  58. self.fishOnHook.die();
  59. self.fishOnHook = null;
  60. } else {
  61. self.parent.getChildByName("score").addHook(-1);
  62. }
  63. }
  64. }
  65. }
  66. Hook.prototype.onmousedown = function(event) {
  67. var self = event.target;
  68. }
  69. Hook.prototype.shoot = function() {
  70. var self = this;
  71. if(!self.isShooting) {
  72. self.isShooting = true;
  73. self.shootDirection = 1;
  74. self.fishManager = self.parent.getChildByName("fishManager");
  75. self.hasGotFish = false;
  76. }
  77. }