Juckniz

Untitled

May 29th, 2013
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.71 KB | None | 0 0
  1. /**
  2. * Clase Bullet que construye un Bullet
  3. * @class Bullet
  4. * @constructors
  5. * @this {Bullet}
  6. * @param {Number} x Posicion X en el que se encuentra
  7. * @param {Number} y Posicion Y en el que se encuentra
  8. * @param {Enemy} Enemy enemigo que tiene seleccionado
  9. * @param {Number} damage dano que inflije la bala
  10. * @param {Number} index indice para sacar la informacion del json
  11. * @param {String} direccion direccion que va a disprar
  12. * @returns {Bullet}
  13. */
  14. function Bullet(x, y, Enemy, damage, index, direccion) {
  15. /* * Posicion X en el que se encuentra. Por defecto 0.
  16. * @type Number
  17. */
  18. this.x = (x == null) ? 0 : x;
  19. /* * Posicion Y en el que se encuentra. Por defecto 0.
  20. * @type Number
  21. */
  22. this.y = (y == null) ? 0 : y;
  23. /* * Posicion X inicial coje el valor de X al construir el objeto.
  24. * @type Number
  25. */
  26. this.xi = this.x;
  27. /* * Posicion Y inicial coje el valor de Y al construir el objeto.
  28. * @type Number
  29. */
  30. this.yi = this.y;
  31. /**
  32. * Direccion donde va disparar "bot" || "top" || "left" || "right" solo se usara si bulletType es "lineal" o "area".
  33. * @type String
  34. */
  35. this.direccion = direccion;
  36. /**
  37. * Tipo de la bala coje el valor del json tipotower.
  38. * @type String
  39. */
  40. this.bulletType = tipotower[index].bulletType;
  41. /**
  42. * Anchura de la bala coje el valor del json tipotower.
  43. * @type Number
  44. */
  45. this.width = tipotower[index].bulletSize;
  46. /**
  47. * Altura de la bala coje el valor del json tipotower.
  48. * @type Number
  49. *
  50. */
  51. this.height = tipotower[index].bulletSize;
  52. /**
  53. * Dano de la bala por defecto 0.
  54. * @type Number
  55. */
  56. this.damage = (damage == null) ? 0 : damage;
  57. /**
  58. * Imagen de la bala coje la src del json tipotower.
  59. * @type Image
  60. */
  61. this.img = new Image();
  62. this.img.src = tipotower[index].imgbullet;
  63. /**
  64. * Enemigo que tiene seleccionado solo lo utilizara si el bulletType es "target"
  65. * @type Enemy
  66. */
  67. this.Enemy = Enemy;
  68. /**
  69. * Velocidad de la bala coje el valor del json tipotower.
  70. * @type Number
  71. */
  72. this.velocity = tipotower[index].velocity;
  73. this.radio = tipotower[index].radio;
  74. this.countradio = 0;
  75.  
  76. /**
  77. * Metodo que comprueba si se ha chocado con otro cuerpo
  78. * @param {type} rect
  79. * @returns {boolean}
  80. */
  81. this.intersects = function(rect) {
  82. if (rect != null) {
  83. return(this.x <= rect.x + rect.width &&
  84. this.x + this.width > rect.x &&
  85. this.y <= rect.y + rect.height &&
  86. this.y + this.height > rect.y);
  87. }
  88. }
Advertisement
Add Comment
Please, Sign In to add comment