1
0

weapons.js 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. /*** Weapons ***/
  2. function Weapon() {
  3. "use strict";
  4. }
  5. Weapon.prototype = {
  6. speed : 5,
  7. strength : 10,
  8. stock: Infinity,
  9. rof : 300,
  10. ror : 1500,
  11. load : 1,
  12. max_load : 1,
  13. width : 5,
  14. height : 5,
  15. shot_timer : false,
  16. reload_timer : false,
  17. directionX : 0,
  18. directionY : 1,
  19. animation : null,
  20. clazz : "default",
  21. callback : undefined,
  22. fire : function() {
  23. if (this.shot_timer || this.load <= 0) {
  24. return false;
  25. }
  26. var _this = this;
  27. this.load = Math.max(0,this.load - 1);
  28. this.shot_timer = setInterval(function() {
  29. if (_this.load > 0) {
  30. clearTimeout(_this.shot_timer);
  31. _this.shot_timer = false;
  32. }
  33. }, this.rof);
  34. if( !this.reload_timer) {
  35. this.reload_timer = setInterval( function() {
  36. _this.load = Math.min(_this.load + 1, Math.min(_this.max_load, _this.stock));
  37. if( _this.load == _this.max_load ) {
  38. clearInterval(_this.reload_timer);
  39. _this.reload_timer = false;
  40. }
  41. }, this.ror);
  42. }
  43. return true;
  44. }
  45. }
  46. function ShotgunWeapon() {
  47. "use strict";
  48. this.directionY = -1;
  49. this.rof = 200;
  50. this.ror = 1500;
  51. this.load = 2;
  52. this.max_load = 2;
  53. this.width = 3;
  54. this.height = 3;
  55. this.clazz = "Shotgun"
  56. }
  57. ShotgunWeapon.prototype = {
  58. }
  59. heriter(ShotgunWeapon.prototype, Weapon.prototype);
  60. function CarotWeapon() {
  61. "use strict";
  62. this.directionY = -1;
  63. this.stock = 10;
  64. this.clazz = "carot";
  65. this.load = 5;
  66. this.max_load = 5;
  67. this.width = 5;
  68. this.height = 10;
  69. }
  70. CarotWeapon.prototype = {
  71. }
  72. heriter(CarotWeapon.prototype, Weapon.prototype);
  73. function CornWeapon() {
  74. "use strict";
  75. this.directionY = -1;
  76. this.stock = 3;
  77. this.clazz = "corn";
  78. this.load = 1;
  79. this.max_load = 1;
  80. this.callback = function(shot) {
  81. var mediumAlien = getAliensMidHeight();
  82. if( shot.y() < mediumAlien ) {
  83. var x = shot.x(),
  84. y = shot.y(),
  85. explosion = EXPLOSIONS.SMALL[0];
  86. $("#shipShots").addSprite("cornExplosion", {width: explosion.width, height: explosion.height, posx: x - explosion.width / 2, posy: y - explosion.height / 2});
  87. explosionSmall($("#cornExplosion"), function() {$("#cornExplosion").remove()});
  88. shot.remove();
  89. var shipShots = $("#shipShots");
  90. for( var i = 0; i < 8; i++) {
  91. var cos = Math.cos( (Math.PI / 4) * i ),
  92. sin = Math.sin( (Math.PI / 4) * i);
  93. if( Math.abs(cos) < 0.01 ) {
  94. cos = 0;
  95. }
  96. if( Math.abs(sin) < 0.01) {
  97. sin = 0;
  98. }
  99. shipShots.addSprite( "shotCorn" + i, { posx : x + 5 * cos, posy : y + 5 * sin, width: 2, height: 2});
  100. var shotCorn = $("#shotCorn" + i);
  101. shotCorn.addClass("shipShot").addClass("shotCorn");
  102. $("#shotCorn" + i)[0].weapon = $.extend({
  103. directionX : cos < 0 ? -1 : cos > 0 ? 1 : 0,
  104. directionY : sin < 0 ? -1 : sin > 0 ? 1 : 0,
  105. speed : 1
  106. }, shot.weapon);
  107. }
  108. }
  109. }
  110. }
  111. CornWeapon.prototype = {
  112. }
  113. heriter(CornWeapon.prototype, Weapon.prototype);
  114. function AlienWeapon() {
  115. "use strict";
  116. this.directionY = 1;
  117. this.width = 5;
  118. this.height = 10;
  119. }
  120. AlienWeapon.prototype = {
  121. }
  122. heriter(AlienWeapon.prototype, Weapon.prototype);
  123. /*** Weapons -END ***/