add basic missiles
This commit is contained in:
parent
21a30ad212
commit
ac089f3e8e
19 changed files with 215 additions and 85 deletions
|
@ -1,15 +1,21 @@
|
|||
'use strict';
|
||||
|
||||
const Body = require('./bodies.js');
|
||||
const Body = require('./body.js');
|
||||
|
||||
class Missile extends Body {
|
||||
constructor(world, source) {
|
||||
constructor(world, pos, source) {
|
||||
super(world);
|
||||
|
||||
this.x = pos.x * 32;
|
||||
this.y = pos.y * 32;
|
||||
this.r = pos.r;
|
||||
|
||||
this.source = source;
|
||||
this.player = source.player;
|
||||
this.fuel = 100;
|
||||
|
||||
this.frame = [[[0, 0], [0, 10], [3, 10], [3, 0]]];
|
||||
this.type = 'missile';
|
||||
this.frame = [[[0, 0], [10, 0], [10, 3], [0, 3]]];
|
||||
}
|
||||
|
||||
detonate() {
|
||||
|
@ -17,6 +23,16 @@ class Missile extends Body {
|
|||
this.world.removeBody(this);
|
||||
}
|
||||
|
||||
tickType() {
|
||||
let power = 0.005;
|
||||
let x = Math.cos(this.b2body.GetAngleRadians()) * power;
|
||||
let y = Math.sin(this.b2body.GetAngleRadians()) * power;
|
||||
this.applyForce(x, y);
|
||||
|
||||
if(this.fuel-- <= 0)
|
||||
this.detonate();
|
||||
}
|
||||
|
||||
packTypeDelta() {
|
||||
return [];
|
||||
}
|
||||
|
@ -26,11 +42,10 @@ class Missile extends Body {
|
|||
type: 'missile',
|
||||
id: this.id,
|
||||
source: this.source.id,
|
||||
team: this.player.team,
|
||||
frame: this.frame,
|
||||
delta: this.packDelta()
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = Projectile;
|
||||
module.exports = Missile;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue