add discharge collision detection
This commit is contained in:
parent
f87aa1446d
commit
44ddaacb15
3 changed files with 40 additions and 4 deletions
|
@ -15,6 +15,14 @@ body
|
||||||
font-family FreePixel
|
font-family FreePixel
|
||||||
font-size 16px
|
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
|
.small
|
||||||
font-family PixelArial
|
font-family PixelArial
|
||||||
font-size 8px
|
font-size 8px
|
||||||
|
|
|
@ -8,15 +8,21 @@ class Discharge {
|
||||||
this.yvel = data.yvel;
|
this.yvel = data.yvel;
|
||||||
this.r = data.r;
|
this.r = data.r;
|
||||||
|
|
||||||
this.lifetime = data.lifetime || 100;
|
this.lifetime = data.lifetime || 50;
|
||||||
this.fixture = fixture;
|
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.world.room.generateId();
|
||||||
this.id = this.fixture.body.world.room.generateId();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
destroy() {
|
destroy() {
|
||||||
this.fixture.body.world.removeDischarge(this);
|
this.world.removeDischarge(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
contact(body) {
|
||||||
|
if (body == this.body) return;
|
||||||
|
|
||||||
|
this.destroy();
|
||||||
}
|
}
|
||||||
|
|
||||||
packDelta() {
|
packDelta() {
|
||||||
|
@ -41,6 +47,25 @@ class Discharge {
|
||||||
}
|
}
|
||||||
|
|
||||||
tick() {
|
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)
|
if (this.lifetime-- <= 0)
|
||||||
this.destroy();
|
this.destroy();
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,6 +4,9 @@
|
||||||
// so most changes done to it should be mirrored there to keep consistent
|
// so most changes done to it should be mirrored there to keep consistent
|
||||||
// physics between client and server.
|
// 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:
|
// Note:
|
||||||
// b2Body.GetWorldPoint is broken or something and to get it to work, you
|
// 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
|
// must pass an object as the second argument. I don't think it matters what
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue