add start of gun support
This commit is contained in:
parent
444533ce85
commit
65f78ec3ac
19 changed files with 141 additions and 29 deletions
BIN
public/img/turrets/01/large.png
Normal file
BIN
public/img/turrets/01/large.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 233 B |
BIN
public/img/turrets/01/medium.png
Normal file
BIN
public/img/turrets/01/medium.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 195 B |
BIN
public/img/turrets/01/small.png
Normal file
BIN
public/img/turrets/01/small.png
Normal file
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 |
|
@ -10,6 +10,11 @@ function loadAssets() {
|
|||
thrust5: 'img/ships/01/thrust5.png',
|
||||
thrust8: 'img/ships/01/thrust8.png'
|
||||
}
|
||||
},
|
||||
turrets: {
|
||||
'01': {
|
||||
small: 'img/turrets/01/small.png'
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -19,7 +24,6 @@ function loadAssets() {
|
|||
// Magical recursive magic.
|
||||
(function r(o, t) {
|
||||
for (var i in o) {
|
||||
console.log(i);
|
||||
if (typeof o[i] == 'string') {
|
||||
t[i] = new Image();
|
||||
t[i].src = o[i];
|
||||
|
|
|
@ -5,6 +5,7 @@ function renderShip(pallet, ship) {
|
|||
var thr0 = game.assets.images.ships[ship.hull].thrust0;
|
||||
var thr5 = game.assets.images.ships[ship.hull].thrust5;
|
||||
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);
|
||||
var pos = ship.getPos();
|
||||
var x = pos.x;
|
||||
|
@ -13,7 +14,15 @@ function renderShip(pallet, ship) {
|
|||
var vy = -game.world.getCenter().y;
|
||||
|
||||
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.move[0] ? thr8 : thr0, 0, 0, 0);
|
||||
pallet.image(img, 0, 0, 0);
|
||||
pallet.image(ship.move[0] ? thr8 : thr0, 0, 0, 0);
|
||||
|
||||
|
|
|
@ -9,6 +9,14 @@ function Ship(data) {
|
|||
this.rvel = data.delta[5];
|
||||
this.hull = '01';
|
||||
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.bodyType = 'ship';
|
||||
this.com = {
|
||||
|
|
11
server/game/room/world/beam.js
Normal file
11
server/game/room/world/beam.js
Normal file
|
@ -0,0 +1,11 @@
|
|||
'use strict';
|
||||
|
||||
const Discharge = require('./discharge.js');
|
||||
|
||||
class Beam extends Discharge {
|
||||
constructor() {
|
||||
super();
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = Beam;
|
|
@ -29,6 +29,16 @@ class Body {
|
|||
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() {
|
||||
let pos = this.b2body.GetPosition();
|
||||
let vel = this.b2body.GetLinearVelocity();
|
||||
|
|
0
server/game/room/world/discharge.js
Normal file
0
server/game/room/world/discharge.js
Normal file
|
@ -13,6 +13,13 @@ class World {
|
|||
this.ships = new Map();
|
||||
this.players = new Set();
|
||||
this.room = room;
|
||||
|
||||
this.bounds = {
|
||||
left: -5,
|
||||
right: 50,
|
||||
top: -15,
|
||||
bottom: 15
|
||||
}
|
||||
}
|
||||
|
||||
addPlayer(player) {
|
||||
|
@ -83,7 +90,10 @@ class World {
|
|||
self.physics.step();
|
||||
|
||||
if (Math.random() < 0.1) {
|
||||
self.bodies.forEach(body => body.applyDelta());
|
||||
self.bodies.forEach(body => {
|
||||
body.applyDelta(),
|
||||
body.tick();
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
36
server/game/room/world/missile.js
Normal file
36
server/game/room/world/missile.js
Normal 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;
|
11
server/game/room/world/projectile.js
Normal file
11
server/game/room/world/projectile.js
Normal file
|
@ -0,0 +1,11 @@
|
|||
'use strict';
|
||||
|
||||
const Discharge = require('./discharge.js');
|
||||
|
||||
class Projectile extends Discharge {
|
||||
constructor() {
|
||||
super();
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = Projectile;
|
|
@ -1,7 +1,7 @@
|
|||
'use strict';
|
||||
|
||||
const defaults = require('./traits/defaults.json');
|
||||
const hulls = require('./traits/hulls.json');
|
||||
const shipTraits = require('./traits/ships.json');
|
||||
|
||||
const Body = require('./body.js');
|
||||
|
||||
|
@ -9,9 +9,15 @@ class Ship extends Body {
|
|||
constructor(world, pos, player, build) {
|
||||
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.frame = hulls[this.build.hull];
|
||||
this.type = 'ship';
|
||||
|
||||
this.thrust = {
|
||||
|
@ -19,8 +25,6 @@ class Ship extends Body {
|
|||
left: 0,
|
||||
right: 0
|
||||
}
|
||||
|
||||
this.power = this.build.power;
|
||||
}
|
||||
|
||||
move(data) {
|
||||
|
@ -66,7 +70,10 @@ class Ship extends Body {
|
|||
type: 'ship',
|
||||
id: this.id,
|
||||
team: this.player.team,
|
||||
build: this.build,
|
||||
frame: this.frame,
|
||||
mounts: this.mounts,
|
||||
turrets: this.turrets,
|
||||
size: this.size,
|
||||
delta: this.packDelta()
|
||||
};
|
||||
}
|
||||
|
|
|
@ -1,13 +1,6 @@
|
|||
{
|
||||
"spawnShip": {
|
||||
"build": {
|
||||
"hull": "01",
|
||||
"turrets": [0],
|
||||
"power": {
|
||||
"forward": 0.0015,
|
||||
"back": 0,
|
||||
"rotation": 0.0001
|
||||
}
|
||||
}
|
||||
"ship": "01",
|
||||
"turrets": ["01", "01"]
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,12 +0,0 @@
|
|||
{
|
||||
"01": [
|
||||
[
|
||||
[1, 28],
|
||||
[31, 28],
|
||||
[31, 19],
|
||||
[19, 2],
|
||||
[13, 2],
|
||||
[1, 19]
|
||||
]
|
||||
]
|
||||
}
|
25
server/game/room/world/traits/ships.json
Normal file
25
server/game/room/world/traits/ships.json
Normal 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]
|
||||
]
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue