Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * Clase Tower que construye un Tower
- * @class Tower
- * @constructors
- * @this {Tower}
- * @param {Number} x posicion x
- * @param {Number} y posicion y
- * @param {Number} width anchura del Tower
- * @param {Number} height altura del Tower
- * @param {Number} damage dano de del Tower
- * @param {Number} radio radio de ataque del Tower
- * @param {String} img src de la imagen del Tower
- * @param {Number} index indice del json tipotower donde sacara informacion
- * @returns {Tower}
- */
- function Tower(x, y, width, height, damage, radio, img, index) {
- /* * Posicion X en el que se encuentra. Por defecto 0.
- * @type Number
- */
- this.x = (x == null) ? 0 : x;
- /* * Posicion Y en el que se encuentra. Por defecto 0.
- * @type Number
- */
- this.y = (y == null) ? 0 : y;
- /* * indice del json tipotower donde sacara informacion
- * @type Number
- */
- this.index = index;
- /* * Anchura del Tower. Por defecto 0.
- * @type Number
- */
- this.width = (width == null) ? 0 : width;
- /* * Altura del Tower. Por defecto coje el valor del width.
- * @type Number
- */
- this.height = (height == null) ? this.width : height;
- /**
- * Dano de la torre por dejecto 0
- * @type Number
- */
- this.damage = (damage == null) ? 0 : damage;
- /**
- * Radio de la torre por defecto es 0
- * @type Number
- */
- this.radio = (radio == null) ? 0 : radio;
- /**
- * Imagen de la torre coje el src del parametro img
- * @type Image
- */
- this.img = new Image();
- this.img.src = img;
- /**
- * Enemigo mas cercano que esta dnetro del rango de la torre
- * @type Tower.Enemy
- */
- this.Enemy = null;
- /**
- * El tipo de balas que dispara saca la informacion del json tipotower
- * @type String
- */
- this.bulletType = tipotower[index].bulletType;
- /**
- * El delay que tiene la torre entre disparo y disparo saca el valor del json tipotower
- * @type Number
- */
- this.delay = tipotower[index].delay;
- /**
- * Contador para saber si es el momento de disparar o no.
- * @type Number
- */
- this.count = this.delay;
- /**
- * Metodo para disparar la bala es decir crea un nuevo objeto de tipo Bullet
- * @returns {void}
- */
- this.shoot = function() {
- if (this.Enemy != null) {
- if (this.bulletType == "target") {
- ArrayBullet.push(new Bullet(this.x, this.y, this.Enemy, this.damage, index));
- } else if (this.bulletType == "lineal" || this.bulletType == "area") {
- ArrayBullet.push(new Bullet(this.x, this.y, this.Enemy, this.damage, index, "top"));
- ArrayBullet.push(new Bullet(this.x, this.y, this.Enemy, this.damage, index, "bot"));
- ArrayBullet.push(new Bullet(this.x, this.y, this.Enemy, this.damage, index, "left"));
- ArrayBullet.push(new Bullet(this.x, this.y, this.Enemy, this.damage, index, "right"));
- }
- this.Enemy = null;
- }
- }
- /**
- * Metodo que selecciona el target mas cercano dentro del radio para comenzar a disparar
- * @returns {void}
- */
- this.selecttarget = function() {
- if (this.Enemy == null && this.count >= this.delay) {
- var modulomin = this.radio;
- for (var i = 0; i < horda.ArrayEnemy.length; i++) {
- var modulo = Math.sqrt(Math.pow(horda.ArrayEnemy[i].x - (this.x), 2) + Math.pow(horda.ArrayEnemy[i].y - (this.y), 2));
- if (modulo <= modulomin) {
- modulomin = modulo;
- this.Enemy = new Enemy();
- this.Enemy = horda.ArrayEnemy[i];
- this.count = 0;
- }
- }
- this.shoot();
- }
- this.count += 30;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment