add asteroids

This commit is contained in:
Asraelite 2016-03-22 18:34:11 +00:00
parent 0ceea5f4af
commit 0aa259b874
17 changed files with 246 additions and 37 deletions

View file

@ -1,5 +1,6 @@
'use strict';
const Asteroid = require('./asteroid.js');
const Physics = require('./physics.js');
const Ship = require('./ship.js');
@ -15,17 +16,42 @@ class World {
addPlayer(player) {
this.players.add(player);
let ship = new Ship(this, player);
let pos = {
x: player.team == 'b' ? 200 : 0,
y: 0
};
let ship = new Ship(this, pos, player);
player.ship = ship;
this.ships.set(player, ship);
this.addShip(ship);
}
addShip(ship) {
this.ships.set(ship.player, ship);
this.bodies.add(ship);
this.physics.createBody(ship);
}
addAsteroid(asteroid) {
this.asteroids.add(asteroid);
this.bodies.add(asteroid);
this.physics.createBody(asteroid);
}
applyDelta(body, data) {
this.players.forEach(player => player.delta[body] = data);
}
populate() {
for (var i = 0; i < 20; i++) {
let pos = {
x: Math.random() * 2000 - 200,
y: Math.random() * 500 - 250
};
let asteroid = new Asteroid(this, pos, Math.random() * 50 + 10);
this.addAsteroid(asteroid);
}
}
removePlayer(player) {
this.removeBody(player.ship);
this.ships.delete(player);