Skip to content

Commit

Permalink
fixed level building
Browse files Browse the repository at this point in the history
  • Loading branch information
nikitaosyak committed Nov 5, 2016
1 parent 642979b commit eba6dea
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 24 deletions.
2 changes: 1 addition & 1 deletion client/src/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@
loadJson('assets/' + Facade.params.startMap, function(data) {
Facade.level = new LevelModel(data);
Facade.simulation.physics.initializeLevel(Facade.level);
visualState = Facade.visualState = new VisualState(game, networkState, Facade.level);
visualState = Facade.visualState = new VisualState(game, networkState);
game.world.setBounds(-20, -20, Facade.level.width+40, Facade.level.height+60);


Expand Down
10 changes: 6 additions & 4 deletions client/src/js/game/VisualState.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@

function VisualState(game, networkState, levelModel) {
function VisualState(game, networkState) {
console.log("visual state created");
this._game = game;
this._networkState = networkState;

var g = game.add.graphics(levelModel.width, levelModel.height);
var g = game.add.graphics(Facade.level.width, Facade.level.height);
g.x = 0;
g.y = 0;
// console.log(levelModel);
for (var bi = 0; bi < levelModel.bodies.length; bi++) {
var b = levelModel.bodies[bi];

var bodies = Facade.simulation.physics.allBodies;
for (var bi = 0; bi < bodies.length; bi++) {
var b = bodies[bi];
if (b.colorScheme == 'bounds') {
g.lineStyle(2, 0xCC1111, 1);
} else {
Expand Down
2 changes: 1 addition & 1 deletion shared/src/simulation/Physics.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ export class Physics {
// this.addStaticBody(bs[i]);
let b = level.bodies[i];
let rectB = Matter.Bodies.rectangle(b.x, b.y, b.w, b.h, b.o);
rectB.colorCheme = b.colorCheme;
rectB.colorScheme = b.colorScheme;
Matter.Body.setStatic(rectB, true);
Matter.World.add(this._world, rectB);
}
Expand Down
18 changes: 0 additions & 18 deletions shared/src/util/game/LevelModel.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ export class LevelModel {
w: w, h: h,
o: {angle: angleRad},
colorScheme: layer.name,
vertices: this._fromPath('L 0 0 L ' + w + ' 0 L ' + w + ' ' + h + ' L 0 ' + h)
};
this._bodies.push(boundBody);
}
Expand All @@ -49,21 +48,4 @@ export class LevelModel {
get bodies() { return this._bodies; }
/** @returns {Array.<*>} */
get respawns() { return this._respawns; }

/**
* Description
* @method fromPath
* @param {string} path
* @return {vertices} vertices
*/
_fromPath(path) {
let pathPattern = /L\s*([\-\d\.]*)\s*([\-\d\.]*)/ig;
let vertices = [];

path.replace(pathPattern, function(match, x, y) {
vertices.push({ x: parseFloat(x, 10), y: parseFloat(y, 10) });
});

return vertices;
};
}

0 comments on commit eba6dea

Please sign in to comment.