From eba6dea4d734a6ae277e59673b112aa15fd3b41d Mon Sep 17 00:00:00 2001 From: grozamorei Date: Sat, 5 Nov 2016 18:53:54 +0300 Subject: [PATCH] fixed level building --- client/src/index.html | 2 +- client/src/js/game/VisualState.js | 10 ++++++---- shared/src/simulation/Physics.js | 2 +- shared/src/util/game/LevelModel.js | 18 ------------------ 4 files changed, 8 insertions(+), 24 deletions(-) diff --git a/client/src/index.html b/client/src/index.html index 403cb15..791dd82 100644 --- a/client/src/index.html +++ b/client/src/index.html @@ -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); diff --git a/client/src/js/game/VisualState.js b/client/src/js/game/VisualState.js index 87a7771..36c71f6 100644 --- a/client/src/js/game/VisualState.js +++ b/client/src/js/game/VisualState.js @@ -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 { diff --git a/shared/src/simulation/Physics.js b/shared/src/simulation/Physics.js index 9755183..647cd5d 100644 --- a/shared/src/simulation/Physics.js +++ b/shared/src/simulation/Physics.js @@ -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); } diff --git a/shared/src/util/game/LevelModel.js b/shared/src/util/game/LevelModel.js index 28f5129..a4c7ea8 100644 --- a/shared/src/util/game/LevelModel.js +++ b/shared/src/util/game/LevelModel.js @@ -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); } @@ -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; - }; } \ No newline at end of file