add start of grappling hook

This commit is contained in:
Asraelite 2016-03-26 20:23:05 +00:00
parent ff0ac094cf
commit 4753f879e5
14 changed files with 192 additions and 69 deletions

View file

@ -1,7 +1,7 @@
'use strict';
const Projectile = require('./projectile.js');
const Rope = require('../copula/rope.js');
const Rope = require('../../copula/rope.js');
class Grapple extends Projectile {
constructor(world, pos, source) {
@ -12,12 +12,13 @@ class Grapple extends Projectile {
this.xvel = pos.xvel;
this.yvel = pos.yvel;
this.r = pos.r;
this.xvel += Math.cos(this.r) * 0.2;
this.yvel += Math.sin(this.r) * 0.2;
this.xvel += Math.cos(this.r) * 0.4;
this.yvel += Math.sin(this.r) * 0.4;
this.welded = false;
this.source = source;
this.player = source.player;
this.rope = new Rope(this, this);
this.type = 'grapple';
this.frame = [
@ -26,29 +27,36 @@ class Grapple extends Projectile {
];
}
contact(body) {
this.detonate();
}
detonate() {
this.world.explosion(this.center, 10);
this.world.room.broadcast('effect', {
type: 'explosion',
size: 10,
pos: this.center
});
release() {
this.source.grapple = false;
this.world.removeBody(this);
}
tickType() {
let power = 0.004;
let x = Math.cos(this.b2body.GetAngleRadians()) * power;
let y = Math.sin(this.b2body.GetAngleRadians()) * power;
this.applyForce(x, y);
retract() {
if (this.rope.length > 0.05)
this.rope.length = this.rope.length - 0.1;
}
connect() {
let p1 = { x: 0, y: 0.5 };
let p2 = { x: 4, y: 0 };
this.rope = new Rope(this.player.ship, this, p1, p2);
this.world.addCopula(this.rope);
this.rope.length = 5;
}
contact(body, contact) {
if (this.welded || body == this.source)
return;
this.welded = true;
let normal = this.world.physics.contactData(contact).normal;
let angle = Math.atan2(normal.y, normal.x);
this.b2body.SetAngleRadians(angle);
this.world.weld(this, body);
}
tickType() {
if(this.fuel-- <= 0) {
this.detonate();
}
}
packTypeDelta() {
@ -57,7 +65,7 @@ class Grapple extends Projectile {
packFull() {
return {
type: 'missile',
type: 'grapple',
id: this.id,
source: this.source.id,
frame: this.frame,
@ -66,4 +74,4 @@ class Grapple extends Projectile {
}
}
module.exports = Missile;
module.exports = Grapple;