diff options
Diffstat (limited to 'server/Entities/Bullet.js')
-rw-r--r-- | server/Entities/Bullet.js | 43 |
1 files changed, 27 insertions, 16 deletions
diff --git a/server/Entities/Bullet.js b/server/Entities/Bullet.js index 6ae6c0f..cc47362 100644 --- a/server/Entities/Bullet.js +++ b/server/Entities/Bullet.js @@ -1,27 +1,32 @@ const Entity = require('./Entity'); const Player = require('./Player'); -var Bullet = function(parent, angle) { +var Bullet = function (parent, angle) +{ var self = Entity.Entity(); self.id = Math.random(); - self.speedX = Math.cos(angle/180*Math.PI) *10; - self.speedY = Math.sin(angle/180*Math.PI) *10; + self.speedX = Math.cos(angle / 180 * Math.PI) * 10; + self.speedY = Math.sin(angle / 180 * Math.PI) * 10; self.dir = 0; self.parent = parent; self.timer = 0; self.toRemove = false; var super_update = self.update; - self.update = function(){ + self.update = function () + { if (self.timer++ > 100) self.toRemove = true; super_update(); - for (var i in Player.list){ + for (var i in Player.list) + { var p = Player.list[i]; - if(self.getDistance(p) < 32 && self.parent !== p.id){ + if (self.getDistance(p) < 32 && self.parent !== p.id) + { if (!p.ignorePlayerAttack) p.hp -= 1; - if (p.hp <= 0){ + if (p.hp <= 0) + { var shooter = Player.list[self.parent]; if (shooter) shooter.score += 1; @@ -35,7 +40,8 @@ var Bullet = function(parent, angle) { } } - self.getInitPack = function() { + self.getInitPack = function () + { return { id: self.id, x: self.x, @@ -45,7 +51,8 @@ var Bullet = function(parent, angle) { }; } - self.getUpdatePack = function() { + self.getUpdatePack = function () + { return { id: self.id, x: self.x, @@ -60,14 +67,17 @@ var Bullet = function(parent, angle) { return self; } -Bullet.list= {}; +Bullet.list = {}; -Bullet.update = function(){ +Bullet.update = function () +{ var pack = []; - for(var i in Bullet.list){ + for (var i in Bullet.list) + { var bullet = Bullet.list[i]; bullet.update(); - if(bullet.toRemove){ + if (bullet.toRemove) + { delete Bullet.list[i]; Entity.removePack.bullet.push(bullet.id); } @@ -77,12 +87,13 @@ Bullet.update = function(){ return pack; } -Bullet.getAllInitPack = function(){ +Bullet.getAllInitPack = function () +{ var bullets = []; - for(var i in Bullet.list) + for (var i in Bullet.list) bullets.push(Bullet.list[i].getInitPack()); return bullets; } module.exports = { Bullet }; -exports.list = Bullet.list;
\ No newline at end of file +exports.list = Bullet.list; |