Bladeren bron

fixed collision detection

master
mort 8 jaren geleden
bovenliggende
commit
c95ccd167e
1 gewijzigde bestanden met toevoegingen van 7 en 4 verwijderingen
  1. 7
    4
      js/game.js

+ 7
- 4
js/game.js Bestand weergeven

} }


intersectsPoint(e) { intersectsPoint(e) {
let rect = this.boundingRect;
return ( return (
e.pos.x > this.pos.x && e.pos.x < this.pos.x + this.width &&
e.pos.y > this.pos.y && e.pos.y < this.pos.y + this.height
e.pos.x > rect.x && e.pos.x < rect.x + rect.width &&
e.pos.y > rect.y && e.pos.y < rect.y + rect.height
); );
} }


let f = new Vec2(0, 0); let f = new Vec2(0, 0);


if (this.keys.up) if (this.keys.up)
f.set(0, -0.4);
f.set(0, -0.9);
if (this.keys.down) if (this.keys.down)
f.set(0, 0.4);
f.set(0, 0.9);
if (this.keys.left) if (this.keys.left)
this.rotForce -= 0.005; this.rotForce -= 0.005;
if (this.keys.right) if (this.keys.right)
f.rotate(this.rot); f.rotate(this.rot);
this.force(f.x, f.y); this.force(f.x, f.y);


this.vel.scale(0.99);

//Detect collissions //Detect collissions
this.game.entities.forEach((e) => { this.game.entities.forEach((e) => {
if (e instanceof Bullet) { if (e instanceof Bullet) {

Laden…
Annuleren
Opslaan