add start of gun support

This commit is contained in:
Asraelite 2016-03-22 23:46:55 +00:00
parent 444533ce85
commit 65f78ec3ac
19 changed files with 141 additions and 29 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 233 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 195 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 132 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 229 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 194 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 148 B

View file

@ -10,6 +10,11 @@ function loadAssets() {
thrust5: 'img/ships/01/thrust5.png', thrust5: 'img/ships/01/thrust5.png',
thrust8: 'img/ships/01/thrust8.png' thrust8: 'img/ships/01/thrust8.png'
} }
},
turrets: {
'01': {
small: 'img/turrets/01/small.png'
}
} }
} }
} }
@ -19,7 +24,6 @@ function loadAssets() {
// Magical recursive magic. // Magical recursive magic.
(function r(o, t) { (function r(o, t) {
for (var i in o) { for (var i in o) {
console.log(i);
if (typeof o[i] == 'string') { if (typeof o[i] == 'string') {
t[i] = new Image(); t[i] = new Image();
t[i].src = o[i]; t[i].src = o[i];

View file

@ -5,6 +5,7 @@ function renderShip(pallet, ship) {
var thr0 = game.assets.images.ships[ship.hull].thrust0; var thr0 = game.assets.images.ships[ship.hull].thrust0;
var thr5 = game.assets.images.ships[ship.hull].thrust5; var thr5 = game.assets.images.ships[ship.hull].thrust5;
var thr8 = game.assets.images.ships[ship.hull].thrust8; var thr8 = game.assets.images.ships[ship.hull].thrust8;
var turr = game.assets.images.turrets['01'].small;
//pallet.view(ship.x, ship.y, false, ship.r); //pallet.view(ship.x, ship.y, false, ship.r);
var pos = ship.getPos(); var pos = ship.getPos();
var x = pos.x; var x = pos.x;
@ -13,7 +14,15 @@ function renderShip(pallet, ship) {
var vy = -game.world.getCenter().y; var vy = -game.world.getCenter().y;
pallet.view(x + vx, y + vy, false, ship.r); pallet.view(x + vx, y + vy, false, ship.r);
var ts = ship.size / 2;
for (var i = 0; i < ship.mounts.length; i++) {
if (ship.turrets[i]) {
pallet.image(turr, ship.mounts[i][0] - ts, ship.mounts[i][1] - ts, 0);
}
}
pallet.image(ship.team == 'a' ? teama : teamb, 0, 0, 0); pallet.image(ship.team == 'a' ? teama : teamb, 0, 0, 0);
pallet.image(ship.move[0] ? thr8 : thr0, 0, 0, 0);
pallet.image(img, 0, 0, 0); pallet.image(img, 0, 0, 0);
pallet.image(ship.move[0] ? thr8 : thr0, 0, 0, 0); pallet.image(ship.move[0] ? thr8 : thr0, 0, 0, 0);

View file

@ -9,6 +9,14 @@ function Ship(data) {
this.rvel = data.delta[5]; this.rvel = data.delta[5];
this.hull = '01'; this.hull = '01';
this.move = []; this.move = [];
this.mounts = data.mounts;
this.turrets = data.turrets;
this.frame = data.frame;
this.size = {
'small': 8,
'medium': 16,
'large': 24
}[data.size];
this.lastMove = []; this.lastMove = [];
this.bodyType = 'ship'; this.bodyType = 'ship';
this.com = { this.com = {

View file

@ -0,0 +1,11 @@
'use strict';
const Discharge = require('./discharge.js');
class Beam extends Discharge {
constructor() {
super();
}
}
module.exports = Beam;

View file

@ -29,6 +29,16 @@ class Body {
this.b2body.ApplyTorque(f); this.b2body.ApplyTorque(f);
} }
tick() {
let pos = this.b2body.GetPosition();
let bounds = this.world.bounds;
if(pos.x < bounds.left) this.applyForce(0.003, 0);
if(pos.x > bounds.right) this.applyForce(-0.003, 0);
if(pos.y < bounds.top) this.applyForce(0, 0.003);
if(pos.y > bounds.bottom) this.applyForce(-0, -0.003);
}
packDelta() { packDelta() {
let pos = this.b2body.GetPosition(); let pos = this.b2body.GetPosition();
let vel = this.b2body.GetLinearVelocity(); let vel = this.b2body.GetLinearVelocity();

View file

View file

@ -13,6 +13,13 @@ class World {
this.ships = new Map(); this.ships = new Map();
this.players = new Set(); this.players = new Set();
this.room = room; this.room = room;
this.bounds = {
left: -5,
right: 50,
top: -15,
bottom: 15
}
} }
addPlayer(player) { addPlayer(player) {
@ -83,7 +90,10 @@ class World {
self.physics.step(); self.physics.step();
if (Math.random() < 0.1) { if (Math.random() < 0.1) {
self.bodies.forEach(body => body.applyDelta()); self.bodies.forEach(body => {
body.applyDelta(),
body.tick();
});
} }
} }
} }

View file

@ -0,0 +1,36 @@
'use strict';
const Body = require('./bodies.js');
class Missile extends Body {
constructor(world, source) {
super(world);
this.source = source;
this.player = source.player;
this.frame = [[[0, 0], [0, 10], [3, 10], [3, 0]]];
}
detonate() {
// Blow up stuff.
this.world.removeBody(this);
}
packTypeDelta() {
return [];
}
packFull() {
return {
type: 'missile',
id: this.id,
source: this.source.id,
team: this.player.team,
frame: this.frame,
delta: this.packDelta()
};
}
}
module.exports = Projectile;

View file

@ -0,0 +1,11 @@
'use strict';
const Discharge = require('./discharge.js');
class Projectile extends Discharge {
constructor() {
super();
}
}
module.exports = Projectile;

View file

@ -1,7 +1,7 @@
'use strict'; 'use strict';
const defaults = require('./traits/defaults.json'); const defaults = require('./traits/defaults.json');
const hulls = require('./traits/hulls.json'); const shipTraits = require('./traits/ships.json');
const Body = require('./body.js'); const Body = require('./body.js');
@ -9,9 +9,15 @@ class Ship extends Body {
constructor(world, pos, player, build) { constructor(world, pos, player, build) {
super(world); super(world);
this.build = build || defaults.spawnShip.build; build = build || {};
this.class = build.ship || defaults.spawnShip.ship;
this.turrets = build.turrets || defaults.spawnShip.turrets;
let traits = shipTraits[this.class];
this.frame = traits.hull;
this.power = traits.power;
this.mounts = traits.mounts;
this.size = traits.size;
this.player = player; this.player = player;
this.frame = hulls[this.build.hull];
this.type = 'ship'; this.type = 'ship';
this.thrust = { this.thrust = {
@ -19,8 +25,6 @@ class Ship extends Body {
left: 0, left: 0,
right: 0 right: 0
} }
this.power = this.build.power;
} }
move(data) { move(data) {
@ -66,7 +70,10 @@ class Ship extends Body {
type: 'ship', type: 'ship',
id: this.id, id: this.id,
team: this.player.team, team: this.player.team,
build: this.build, frame: this.frame,
mounts: this.mounts,
turrets: this.turrets,
size: this.size,
delta: this.packDelta() delta: this.packDelta()
}; };
} }

View file

@ -1,13 +1,6 @@
{ {
"spawnShip": { "spawnShip": {
"build": { "ship": "01",
"hull": "01", "turrets": ["01", "01"]
"turrets": [0],
"power": {
"forward": 0.0015,
"back": 0,
"rotation": 0.0001
}
}
} }
} }

View file

@ -1,12 +0,0 @@
{
"01": [
[
[1, 28],
[31, 28],
[31, 19],
[19, 2],
[13, 2],
[1, 19]
]
]
}

View file

@ -0,0 +1,25 @@
{
"01": {
"name": "Aiwodge",
"size": "small",
"power": {
"forward": 0.0015,
"back": 0,
"rotation": 0.0001
},
"hull": [
[
[3, 1],
[3, 30],
[12, 30],
[29, 18],
[29, 13],
[12, 1]
]
],
"mounts": [
[18, 4],
[18, 27]
]
}
}