add lasers
This commit is contained in:
parent
cf4e8024af
commit
f87aa1446d
31 changed files with 298 additions and 125 deletions
|
@ -3,7 +3,7 @@
|
|||
const Asteroid = require('./body/asteroid.js');
|
||||
const Grapple = require('./body/projectile/grapple.js');
|
||||
const Missile = require('./body/projectile/missile.js');
|
||||
const Laser = require('./body/turret/shot/laser.js');
|
||||
const Laser = require('./body/turret/discharge/laser.js');
|
||||
|
||||
class Spawner {
|
||||
constructor(world) {
|
||||
|
@ -35,38 +35,46 @@ class Spawner {
|
|||
return missile;
|
||||
}
|
||||
|
||||
spawnGrapple(ship, x, y) {
|
||||
let sx = ship.center.x;
|
||||
let sy = ship.center.y;
|
||||
let dx = x - sx;
|
||||
let dy = y - sy;
|
||||
spawnGrapple(fixture, x, y) {
|
||||
let fixturePos = fixture.body.getWorldPos(fixture.mount.pos);
|
||||
let fx = fixturePos.x;
|
||||
let fy = fixturePos.y;
|
||||
let dx = x - fx;
|
||||
let dy = y - fy;
|
||||
let a = Math.atan2(dy, dx);
|
||||
let pos = {
|
||||
x: sx + Math.cos(a) * 1,
|
||||
y: sy + Math.sin(a) * 1,
|
||||
x: fx + Math.cos(a) * 1,
|
||||
y: fy + Math.sin(a) * 1,
|
||||
r: a,
|
||||
xvel: ship.vel.x,
|
||||
yvel: ship.vel.y
|
||||
xvel: fixture.body.vel.x,
|
||||
yvel: fixture.body.vel.y
|
||||
};
|
||||
let grapple = new Grapple(this.world, pos, ship);
|
||||
let grapple = new Grapple(this.world, pos, fixture.body);
|
||||
this.world.addProjectile(grapple);
|
||||
return grapple;
|
||||
}
|
||||
|
||||
spawnLaser(ship) {
|
||||
let r = ship.pos.r;
|
||||
let ox = Math.cos(r) * 0.7;
|
||||
let oy = Math.sin(r) * 0.7;
|
||||
let pos = {
|
||||
x: ship.center.x + ox,
|
||||
y: ship.center.y + oy,
|
||||
r: r,
|
||||
xvel: ship.vel.x,
|
||||
yvel: ship.vel.y
|
||||
spawnLaser(fixture) {
|
||||
let r = fixture.angle;
|
||||
let a = fixture.body.pos.r + fixture.angle;
|
||||
let fixturePos = fixture.mount.pos;
|
||||
let f = {
|
||||
x: fixturePos.x + Math.cos(r) * 0.3,
|
||||
y: fixturePos.y + Math.sin(r) * 0.3
|
||||
};
|
||||
let missile = new Missile(this.world, pos, ship);
|
||||
this.world.addProjectile(missile);
|
||||
return missile;
|
||||
let vx = Math.cos(a) * 0.5;
|
||||
let vy = Math.sin(a) * 0.5;
|
||||
let spawnPos = fixture.body.getWorldPos(f);
|
||||
let pos = {
|
||||
x: spawnPos.x,
|
||||
y: spawnPos.y,
|
||||
r: r,
|
||||
xvel: fixture.body.vel.x + vx,
|
||||
yvel: fixture.body.vel.y + vy
|
||||
};
|
||||
let laser = new Laser(fixture, pos);
|
||||
this.world.addDischarge(laser);
|
||||
return laser;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue