Juckniz

Untitled

May 28th, 2013
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.96 KB | None | 0 0
  1. /**
  2. * Clase que construye un LifeBar
  3. * @class LifeBar
  4. * @constructors
  5. * @this {LifeBar}
  6. * @param {Number} x Posicion X en el que se encuentra
  7. * @param {Number} y Posicion Y en el que se encuentra
  8. * @param {Number} width Anchura del LifeBar
  9. * @param {Number} height Altura del LifeBar
  10. * @param {Number} initLife valor de la vida inicial
  11. * @returns {LifeBar}
  12. */
  13. function LifeBar(x, y, width, height, initLife) {
  14. /* * Posicion X en el que se encuentra. Por defecto 0.
  15. * @type Number
  16. */
  17. this.x = (x == null) ? 0 : x;
  18. /* * Posicion Y en el que se encuentra. Por defecto 0.
  19. * @type Number
  20. */
  21. this.y = (y == null) ? 0 : y;
  22.  
  23. /* * Anchura del TextArea. Por defecto 0.
  24. * @type Number
  25. */
  26. this.width = (width == null) ? 0 : width;
  27.  
  28. /**
  29. * Altura del TextArea Por defecto el tamano de la anchura.
  30. * @type Number
  31. */
  32. this.height = (height == null) ? this.width : height;
  33. /**
  34. * Imagen de la barra de vida que lo saca de una variable global llamada imgLife
  35. * @type imgLife
  36. */
  37. this.img = imgLife;
  38. /**
  39. * Anchura de la imagen, es la vida actual que mostrara respecto la barra entera de vida
  40. * @type Number
  41. */
  42. this.imgwidth = width;
  43. /**
  44. * Vida inicial
  45. * @type Number
  46. */
  47. this.initLife = initLife;
  48.  
  49. /**
  50. * Metodo para actualizar la barra vida
  51. * @param {Number} life vida actual
  52. * @returns {void}
  53. */
  54. this.updateLife = function(life) {
  55. if (life >= 0) {
  56. this.imgwidth = life / this.initLife * this.width;
  57. } else {
  58. this.imgwidth = 0;
  59. }
  60. }
  61.  
  62. /**
  63. * Metodo que updatea la posicion de la barra de vida
  64. * @param {Number} x nueva posicion x
  65. * @param {Number} y nueva posicion y
  66. * @returns {void}
  67. */
  68. this.updatePosition = function(x, y) {
  69. this.x = (x == null) ? 0 : x;
  70. this.y = (y == null) ? 0 : y;
  71. }
  72.  
  73. }
Advertisement
Add Comment
Please, Sign In to add comment