From 44ddaacb1574df3ba9188bd848e95bbc7da9d7f2 Mon Sep 17 00:00:00 2001 From: Asraelite Date: Wed, 30 Mar 2016 19:35:05 +0100 Subject: [PATCH] add discharge collision detection --- public/stylus/styles.styl | 8 +++++ .../world/body/turret/discharge/discharge.js | 33 ++++++++++++++++--- server/game/room/world/physics.js | 3 ++ 3 files changed, 40 insertions(+), 4 deletions(-) diff --git a/public/stylus/styles.styl b/public/stylus/styles.styl index 6c3dae1..12d6ff9 100644 --- a/public/stylus/styles.styl +++ b/public/stylus/styles.styl @@ -15,6 +15,14 @@ body font-family FreePixel font-size 16px +canvas + -webkit-touch-callout none + -webkit-user-select none + -khtml-user-select none + -moz-user-select none + -ms-user-select none + user-select: none + .small font-family PixelArial font-size 8px diff --git a/server/game/room/world/body/turret/discharge/discharge.js b/server/game/room/world/body/turret/discharge/discharge.js index a07c47b..65e8d4e 100644 --- a/server/game/room/world/body/turret/discharge/discharge.js +++ b/server/game/room/world/body/turret/discharge/discharge.js @@ -8,15 +8,21 @@ class Discharge { this.yvel = data.yvel; this.r = data.r; - this.lifetime = data.lifetime || 100; + this.lifetime = data.lifetime || 50; this.fixture = fixture; + this.world = this.fixture.body.world; - // Might just make it this.world later if it turns out I need it more. - this.id = this.fixture.body.world.room.generateId(); + this.id = this.world.room.generateId(); } destroy() { - this.fixture.body.world.removeDischarge(this); + this.world.removeDischarge(this); + } + + contact(body) { + if (body == this.body) return; + + this.destroy(); } packDelta() { @@ -41,6 +47,25 @@ class Discharge { } tick() { + let start = { + x: this.x, + y: this.y + }; + + this.x += this.xvel; + this.y += this.yvel + + let end = { + x: this.x, + y: this.y + }; + + let contact = this.world.physics.raycast(start, end); + + if (contact) { + this.contact(contact.body); + } + if (this.lifetime-- <= 0) this.destroy(); } diff --git a/server/game/room/world/physics.js b/server/game/room/world/physics.js index ec0b209..4511bf9 100644 --- a/server/game/room/world/physics.js +++ b/server/game/room/world/physics.js @@ -4,6 +4,9 @@ // so most changes done to it should be mirrored there to keep consistent // physics between client and server. +// TODO: Put all physics constants into a JSON file that is sent to the client +// as well so that the top paragraph no longer applies. + // Note: // b2Body.GetWorldPoint is broken or something and to get it to work, you // must pass an object as the second argument. I don't think it matters what