Juckniz

Untitled

May 29th, 2013
30
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.81 KB | None | 0 0
  1. /**
  2. * Clase Tower que construye un Tower
  3. * @class Tower
  4. * @constructors
  5. * @this {Tower}
  6. * @param {Number} x posicion x
  7. * @param {Number} y posicion y
  8. * @param {Number} width anchura del Tower
  9. * @param {Number} height altura del Tower
  10. * @param {Number} damage dano de del Tower
  11. * @param {Number} radio radio de ataque del Tower
  12. * @param {String} img src de la imagen del Tower
  13. * @param {Number} index indice del json tipotower donde sacara informacion
  14. * @returns {Tower}
  15. */
  16. function Tower(x, y, width, height, damage, radio, img, index) {
  17. /* * Posicion X en el que se encuentra. Por defecto 0.
  18. * @type Number
  19. */
  20. this.x = (x == null) ? 0 : x;
  21. /* * Posicion Y en el que se encuentra. Por defecto 0.
  22. * @type Number
  23. */
  24. this.y = (y == null) ? 0 : y;
  25. /* * indice del json tipotower donde sacara informacion
  26. * @type Number
  27. */
  28. this.index = index;
  29. /* * Anchura del Tower. Por defecto 0.
  30. * @type Number
  31. */
  32. this.width = (width == null) ? 0 : width;
  33. /* * Altura del Tower. Por defecto coje el valor del width.
  34. * @type Number
  35. */
  36. this.height = (height == null) ? this.width : height;
  37. /**
  38. * Dano de la torre por dejecto 0
  39. * @type Number
  40. */
  41. this.damage = (damage == null) ? 0 : damage;
  42. /**
  43. * Radio de la torre por defecto es 0
  44. * @type Number
  45. */
  46. this.radio = (radio == null) ? 0 : radio;
  47. /**
  48. * Imagen de la torre coje el src del parametro img
  49. * @type Image
  50. */
  51. this.img = new Image();
  52. this.img.src = img;
  53. /**
  54. * Enemigo mas cercano que esta dnetro del rango de la torre
  55. * @type Tower.Enemy
  56. */
  57. this.Enemy = null;
  58. /**
  59. * El tipo de balas que dispara saca la informacion del json tipotower
  60. * @type String
  61. */
  62. this.bulletType = tipotower[index].bulletType;
  63. /**
  64. * El delay que tiene la torre entre disparo y disparo saca el valor del json tipotower
  65. * @type Number
  66. */
  67. this.delay = tipotower[index].delay;
  68. /**
  69. * Contador para saber si es el momento de disparar o no.
  70. * @type Number
  71. */
  72. this.count = this.delay;
  73.  
  74.  
  75.  
  76. /**
  77. * Metodo para disparar la bala es decir crea un nuevo objeto de tipo Bullet
  78. * @returns {void}
  79. */
  80. this.shoot = function() {
  81. if (this.Enemy != null) {
  82. if (this.bulletType == "target") {
  83. ArrayBullet.push(new Bullet(this.x, this.y, this.Enemy, this.damage, index));
  84.  
  85. } else if (this.bulletType == "lineal" || this.bulletType == "area") {
  86. ArrayBullet.push(new Bullet(this.x, this.y, this.Enemy, this.damage, index, "top"));
  87. ArrayBullet.push(new Bullet(this.x, this.y, this.Enemy, this.damage, index, "bot"));
  88. ArrayBullet.push(new Bullet(this.x, this.y, this.Enemy, this.damage, index, "left"));
  89. ArrayBullet.push(new Bullet(this.x, this.y, this.Enemy, this.damage, index, "right"));
  90.  
  91. }
  92. this.Enemy = null;
  93. }
  94.  
  95. }
  96.  
  97.  
  98. /**
  99. * Metodo que selecciona el target mas cercano dentro del radio para comenzar a disparar
  100. * @returns {void}
  101. */
  102. this.selecttarget = function() {
  103. if (this.Enemy == null && this.count >= this.delay) {
  104. var modulomin = this.radio;
  105.  
  106. for (var i = 0; i < horda.ArrayEnemy.length; i++) {
  107. var modulo = Math.sqrt(Math.pow(horda.ArrayEnemy[i].x - (this.x), 2) + Math.pow(horda.ArrayEnemy[i].y - (this.y), 2));
  108. if (modulo <= modulomin) {
  109. modulomin = modulo;
  110. this.Enemy = new Enemy();
  111. this.Enemy = horda.ArrayEnemy[i];
  112. this.count = 0;
  113.  
  114. }
  115.  
  116. }
  117. this.shoot();
  118.  
  119. }
  120.  
  121. this.count += 30;
  122. }
  123. }
Advertisement
Add Comment
Please, Sign In to add comment