From 16826b174a8e606a2f50185eda37cd80bcbe6f40 Mon Sep 17 00:00:00 2001 From: Jeena Date: Mon, 16 Mar 2015 01:50:41 +0100 Subject: [PATCH] fixed debug view and ragdoll start positioning --- app/Game/Channel/Player.js | 4 +- app/Game/Client/GameController.js | 12 +++- app/Game/Client/Physics/Engine.js | 12 ++-- app/Game/Client/View/DomController.js | 27 ++++---- app/Game/Client/View/Pixi/Layers/Debug.js | 11 +--- app/Game/Config/Settings.js | 4 +- app/Game/Core/GameObjects/Items/RagDoll.js | 10 +-- app/Game/Core/GameObjects/Items/Skateboard.js | 12 ++-- app/Game/Core/Loader/Level.js | 26 ++++---- app/Game/Core/Loader/TiledLevel.js | 24 ++----- ...5T19:00:28.545Z-debug_residence_stones.rec | 2 +- static/maps/tiled/stones.json | 64 ++++++++++++++++++- 12 files changed, 135 insertions(+), 73 deletions(-) diff --git a/app/Game/Channel/Player.js b/app/Game/Channel/Player.js index 06c8b56..1af56c1 100755 --- a/app/Game/Channel/Player.js +++ b/app/Game/Channel/Player.js @@ -55,7 +55,9 @@ function (Parent, Nc) { }; Player.prototype.suicide = function() { - this.addDamage(100, this, null); + if(this.isSpawned()) { + this.addDamage(100, this, null); + } }; Player.prototype.addDamage = function(damage, enemy, byItem) { diff --git a/app/Game/Client/GameController.js b/app/Game/Client/GameController.js index 741cec6..b41d008 100755 --- a/app/Game/Client/GameController.js +++ b/app/Game/Client/GameController.js @@ -14,10 +14,11 @@ define([ "Game/Client/Me", "Game/Client/AudioPlayer", "Game/Client/PointerLockManager", - "Lib/Utilities/Assert" + "Lib/Utilities/Assert", + "Lib/Utilities/Exception" ], -function (Parent, Box2D, PhysicsEngine, ViewManager, PlayerController, Nc, requestAnimFrame, Settings, GameObject, Doll, DomController, ProtocolHelper, Me, AudioPlayer, PointerLockManager, Assert) { +function (Parent, Box2D, PhysicsEngine, ViewManager, PlayerController, Nc, requestAnimFrame, Settings, GameObject, Doll, DomController, ProtocolHelper, Me, AudioPlayer, PointerLockManager, Assert, Exception) { "use strict"; @@ -88,7 +89,11 @@ function (Parent, Box2D, PhysicsEngine, ViewManager, PlayerController, Nc, reque } if(!alreadyExists) { + // When creating from synchronization we need to bring it into level format (px) + itemDef.options.x *= Settings.RATIO; + itemDef.options.y *= Settings.RATIO; this.level.createItem(itemDef.uid, itemDef.options); + console.log("Creating runtime Item: ", itemDef.options.name, itemDef.uid) } } } @@ -180,6 +185,9 @@ function (Parent, Box2D, PhysicsEngine, ViewManager, PlayerController, Nc, reque GameController.prototype.onUpdateStats = function(options) { var player = this.players[options.playerId]; + if(!player) { + throw new Exception("No player with id: " + options.playerId); + } player.setStats(options.stats); }; diff --git a/app/Game/Client/Physics/Engine.js b/app/Game/Client/Physics/Engine.js index 192b078..231bf1d 100755 --- a/app/Game/Client/Physics/Engine.js +++ b/app/Game/Client/Physics/Engine.js @@ -8,7 +8,7 @@ define([ "Game/Client/View/Pixi/Layers/Debug" ], -function (Parent, Settings, DomController, Box2D, Nc, DebugDraw, DebugLayer) { +function (Parent, Settings, DomController, Box2D, Nc, DebugDraw, debugLayer) { "use strict"; @@ -25,9 +25,11 @@ function (Parent, Settings, DomController, Box2D, Nc, DebugDraw, DebugLayer) { Engine.prototype.onToggleDebugMode = function(debugMode) { this.debugMode = debugMode; - if(this.debugMode && !this.debugDraw) { + if(!this.debugDraw) { this.setupDebugDraw(); } + + debugLayer.container.visible = this.debugMode; }; Engine.prototype.setupDebugDraw = function () { @@ -35,7 +37,7 @@ function (Parent, Settings, DomController, Box2D, Nc, DebugDraw, DebugLayer) { // set debug draw this.debugDraw = new DebugDraw(); - this.debugDraw.SetSprite(DebugLayer.graphics); + this.debugDraw.SetSprite(debugLayer.graphics); this.debugDraw.SetDrawScale(Settings.RATIO); this.debugDraw.SetFillAlpha(0.5); this.debugDraw.SetLineThickness(1.0); @@ -51,7 +53,7 @@ function (Parent, Settings, DomController, Box2D, Nc, DebugDraw, DebugLayer) { ); this.world.SetDebugDraw(this.debugDraw); - } + }; Engine.prototype.update = function () { Parent.prototype.update.call(this); @@ -59,7 +61,7 @@ function (Parent, Settings, DomController, Box2D, Nc, DebugDraw, DebugLayer) { if(this.debugMode) { this.world.DrawDebugData(); } - } + }; return Engine; }); \ No newline at end of file diff --git a/app/Game/Client/View/DomController.js b/app/Game/Client/View/DomController.js index adfa0b7..bb4c74d 100755 --- a/app/Game/Client/View/DomController.js +++ b/app/Game/Client/View/DomController.js @@ -1,6 +1,6 @@ define([ - 'Game/Config/Settings', - 'Lib/Utilities/NotificationCenter', + "Game/Config/Settings", + "Lib/Utilities/NotificationCenter", "Lib/Vendor/Screenfull", "Game/Client/View/Graph", "Game/Client/PointerLockManager" @@ -36,7 +36,7 @@ function (Settings, Nc, Screenfull, Graph, PointerLockManager) { button.innerHTML = "Menu"; button.onclick = function() { window.location.href="/"; - } + }; li.appendChild(button); this.devToolsContainer.appendChild(li); @@ -98,7 +98,7 @@ function (Settings, Nc, Screenfull, Graph, PointerLockManager) { scaleStartValue: 0, scaleStepWidth: 0, scaleSteps: 0 - }) + }); // create Ping: container li = document.createElement("li"); @@ -114,7 +114,7 @@ function (Settings, Nc, Screenfull, Graph, PointerLockManager) { checkbox.type = "checkbox"; checkbox.onclick = function(e) { Nc.trigger(Nc.ns.client.view.debugMode.toggle, e.target.checked); - } + }; label.appendChild(checkbox); label.appendChild(document.createTextNode("Debug")); li.appendChild(label); @@ -123,7 +123,7 @@ function (Settings, Nc, Screenfull, Graph, PointerLockManager) { // create Fullscreen li = document.createElement("li"); - li.id = "fullscreen" + li.id = "fullscreen"; button = document.createElement("button"); button.innerHTML = "Fullscreen"; button.onclick = function() { @@ -131,7 +131,7 @@ function (Settings, Nc, Screenfull, Graph, PointerLockManager) { PointerLockManager.request(); Screenfull.request(self.canvas); } - } + }; li.appendChild(button); this.devToolsContainer.appendChild(li); @@ -139,13 +139,12 @@ function (Settings, Nc, Screenfull, Graph, PointerLockManager) { // FIXME : isn't this a weird place for this? window.onresize = function() { Nc.trigger(Nc.ns.client.view.display.change); - } + }; }; DomController.prototype.setNick = function (nick) { - this.nickContainer.innerHTML = nick - } - + this.nickContainer.innerHTML = nick; + }; DomController.prototype.fpsStep = function() { this.fpsGraph.step(); @@ -164,15 +163,15 @@ function (Settings, Nc, Screenfull, Graph, PointerLockManager) { } else { throw 'Canvas Container missing: #' + Settings.CANVAS_DOM_ID; } - } + }; DomController.prototype.getCanvas = function () { return this.canvas; - } + }; DomController.prototype.initCanvas = function (canvas) { Nc.trigger(Nc.ns.client.view.display.change, Screenfull.isFullscreen); - } + }; DomController.prototype.setConnected = function(connected) { if(connected) { diff --git a/app/Game/Client/View/Pixi/Layers/Debug.js b/app/Game/Client/View/Pixi/Layers/Debug.js index 08c10a4..2185476 100644 --- a/app/Game/Client/View/Pixi/Layers/Debug.js +++ b/app/Game/Client/View/Pixi/Layers/Debug.js @@ -1,16 +1,14 @@ define([ "Game/Client/View/Pixi/Layer", "Lib/Vendor/Pixi", - "Game/Config/Settings", - ], -function (Parent, PIXI, Settings) { +function (Parent, PIXI) { "use strict"; function Debug() { - Parent.call(this, "debug", 0); + Parent.call(this, "debug", 0.00000001); this.graphics = new PIXI.Graphics(); @@ -20,14 +18,11 @@ function (Parent, PIXI, Settings) { Debug.prototype = Object.create(Parent.prototype); Debug.prototype.render = function(centerPosition, zoom) { - Parent.prototype.render.call(this, centerPosition, zoom); - - this.container.x -= 300 * zoom; this.container.y -= 200 * zoom; - } + }; return new Debug(); }); \ No newline at end of file diff --git a/app/Game/Config/Settings.js b/app/Game/Config/Settings.js index ec80eba..c2759ed 100755 --- a/app/Game/Config/Settings.js +++ b/app/Game/Config/Settings.js @@ -28,7 +28,7 @@ function () { MAPS_PATH: "static/maps/tiled/", AUDIO_PATH: "static/sounds/", CHANNEL_RECORDING_PATH: "recordings/", - CHANNEL_PLAY_RECORDING: false, //"Quickstart-2015-03-15T19:00:28.545Z-debug_residence_stones.log", + CHANNEL_PLAY_RECORDING: false, //"Varberg-2015-03-15T23:10:29.316Z-stones.log", RATIO: 21, //35 // original tile size is 25 but we want it to resize to 20 @@ -52,7 +52,7 @@ function () { RESPAWN_TIME: 5, HEALTH_DISPLAY_TIME: 2, CRITICAL_HEALTH_THRESHOLD: 0.3, - RAGDOLL_DESTRUCTION_TIME: 20000, + RAGDOLL_DESTRUCTION_TIME: 10, VIEWPORT_SPEED_FACTOR: 640, VIEWPORT_LOOK_AHEAD: 0.1, diff --git a/app/Game/Core/GameObjects/Items/RagDoll.js b/app/Game/Core/GameObjects/Items/RagDoll.js index ef753e6..1d5a53e 100644 --- a/app/Game/Core/GameObjects/Items/RagDoll.js +++ b/app/Game/Core/GameObjects/Items/RagDoll.js @@ -102,10 +102,10 @@ function (Parent, Box2D, Settings, Nc, Assert, Options, ItemSettings) { //this.createSensor(); this.limbs = {}; - this.addHead(); + this.addLimb( "upperLeftLeg", this.body, @@ -137,7 +137,6 @@ function (Parent, Box2D, Settings, Nc, Assert, Options, ItemSettings) { - this.addLimb( "upperLeftArm", this.body, @@ -165,6 +164,7 @@ function (Parent, Box2D, Settings, Nc, Assert, Options, ItemSettings) { 0, options.limbs.upperRightArm.height / 2 ); + } RagDoll.prototype = Object.create(Parent.prototype); @@ -185,6 +185,8 @@ function (Parent, Box2D, Settings, Nc, Assert, Options, ItemSettings) { var bodyDef = Parent.prototype.getBodyDef.call(this); bodyDef.linearDamping = Settings.PLAYER_LINEAR_DAMPING; bodyDef.type = Box2D.Dynamics.b2Body.b2_dynamicBody; + bodyDef.position.y -= this.options.height / 2 / Settings.RATIO; // position it on top of ground + return bodyDef; }; @@ -235,7 +237,7 @@ function (Parent, Box2D, Settings, Nc, Assert, Options, ItemSettings) { Assert.number(this.options.limbs.head.width); var x = this.options.x + this.options.limbs.head.x, - y = this.options.y + this.options.limbs.head.y; + y = this.options.y + this.options.limbs.head.y - this.options.height / 2; // position it on top of ground; var bodyDef = new Box2D.Dynamics.b2BodyDef(); bodyDef.type = Box2D.Dynamics.b2Body.b2_dynamicBody; @@ -286,7 +288,7 @@ function (Parent, Box2D, Settings, Nc, Assert, Options, ItemSettings) { Assert.number(this.options.limbs[name].width, this.options.limbs[name].height); var x = this.options.x + this.options.limbs[name].x, - y = this.options.y + this.options.limbs[name].y; + y = this.options.y + this.options.limbs[name].y - this.options.height / 2; // position it on top of ground;; var bodyDef = new Box2D.Dynamics.b2BodyDef(); bodyDef.linearDamping = Settings.PLAYER_LINEAR_DAMPING; diff --git a/app/Game/Core/GameObjects/Items/Skateboard.js b/app/Game/Core/GameObjects/Items/Skateboard.js index 311f01e..e6124c9 100755 --- a/app/Game/Core/GameObjects/Items/Skateboard.js +++ b/app/Game/Core/GameObjects/Items/Skateboard.js @@ -51,7 +51,6 @@ function (Parent, Box2D, Settings, Assert) { }; Skateboard.prototype.addWheel = function(x, y) { - Assert.number(x, y); var bodyDef = new Box2D.Dynamics.b2BodyDef(); @@ -71,15 +70,20 @@ function (Parent, Box2D, Settings, Assert) { fixtureDef.density = density; fixtureDef.shape = wheelShape; fixtureDef.isSensor = false; + fixtureDef.friction = 0; var wheelBody = this.body.GetWorld().CreateBody(bodyDef); wheelBody.CreateFixture(fixtureDef); - var revoluteJointDef = new Box2D.Dynamics.Joints.b2RevoluteJointDef(); - revoluteJointDef.enableMotor = false; + //var revoluteJointDef = new Box2D.Dynamics.Joints.b2RevoluteJointDef(); + var revoluteJointDef = new Box2D.Dynamics.Joints.b2WeldJointDef(); + //revoluteJointDef.enableMotor = false; + + revoluteJointDef.Initialize(this.body, wheelBody, wheelBody.GetWorldCenter()); - this.body.GetWorld().CreateJoint(revoluteJointDef); + var j = this.body.GetWorld().CreateJoint(revoluteJointDef); + // FIXME this means, that we will have bodies in the world, which must not be // updated (wheels) because they are always connected to a body which will be updated. diff --git a/app/Game/Core/Loader/Level.js b/app/Game/Core/Loader/Level.js index a599bb3..84b0c68 100755 --- a/app/Game/Core/Loader/Level.js +++ b/app/Game/Core/Loader/Level.js @@ -25,13 +25,13 @@ define([ Level.prototype.load = function (uid) { var self = this; - var path = Settings.MAPS_PATH + uid + ".json" + var path = Settings.MAPS_PATH + uid + ".json"; this.loadLevelDataFromPath(path, function (levelData) { self.setup(levelData); }); - } + }; - Level.prototype.setup = function(levelData) { + Level.prototype.setup = function(levelData) { // jshint unused:false this.isLoaded = true; Nc.trigger(Nc.ns.core.game.events.level.loaded); }; @@ -40,17 +40,17 @@ define([ for (var i = 0; i < options.length; i++) { var uid = "item-" + i; this.createItem(uid, options[i]); - }; + } }; Level.prototype.createItem = function(uid, options) { switch(options.type) { - //case 'skateboard': + //case "skateboard": // return new Skateboard(this.engine, uid, options); - case 'ragdoll': + case "ragdoll": return new RagDoll(this.engine, uid, options); - case 'rube': + case "rube": return new Rube(this.engine, uid, options); default: return new Item(this.engine, uid, options); @@ -60,19 +60,19 @@ define([ Level.prototype.createTiles = function(options) { for (var i = 0; i < options.length; i++) { new Tile(this.engine, "tile-" + i, options[i]); - }; + } }; Level.prototype.createSpawnPoints = function(points) { this.spawnPoints = points; }; - Level.prototype.setupLayer = function(options, behind, referenceId) { + Level.prototype.setupLayer = function(options, behind, referenceId) { // jshint unused:false // will be extended (so far only in client) - } + }; - Level.prototype.createContainer = function(options) { + Level.prototype.createContainer = function(options) { // jshint unused:false // nothing to do here yet, in the future perhaps synchronize day/night graphics }; @@ -90,12 +90,12 @@ define([ return { x: object.x / Settings.TILE_RATIO, y: object.y / Settings.TILE_RATIO - } + }; }; Level.prototype.destroy = function () { this.isLoaded = false; - } + }; return Level; }); \ No newline at end of file diff --git a/app/Game/Core/Loader/TiledLevel.js b/app/Game/Core/Loader/TiledLevel.js index 85ff92d..ba998c1 100755 --- a/app/Game/Core/Loader/TiledLevel.js +++ b/app/Game/Core/Loader/TiledLevel.js @@ -6,13 +6,14 @@ define([ "Lib/Utilities/Options", "Lib/Utilities/Exception", "Lib/Utilities/NotificationCenter", + "Lib/Utilities/Assert", "Game/Client/View/Abstract/Layer", "Game/" + GLOBALS.context + "/Collision/Detector", "Game/" + GLOBALS.context + "/GameObjects/Tile", "Game/" + GLOBALS.context + "/GameObjects/Item", "Game/" + GLOBALS.context + "/GameObjects/Items/Skateboard", -], function (Parent, Settings, ItemSettings, Box2D, Options, Exception, Nc, AbstractLayer, CollisionDetector, Tile, Item, Skateboard) { +], function (Parent, Settings, ItemSettings, Box2D, Options, Exception, Nc, Assert, AbstractLayer, CollisionDetector, Tile, Item, Skateboard) { "use strict"; @@ -40,7 +41,7 @@ define([ }); if (!spawnpointsExists) { - console.warn('No layerMapping for level file layer: ' + layerOptions.name); + console.warn("No layerMapping for level file layer: " + layerOptions.name); return; } @@ -49,7 +50,7 @@ define([ tiles: AbstractLayer.ID.TILE, items: AbstractLayer.ID.ITEM, spawnpoints: AbstractLayer.ID.SPAWN - } + }; if(mapping[name]) { return mapping[name]; } @@ -167,26 +168,15 @@ define([ }; TiledLevel.prototype.gatherOptions = function(tiledObject) { - var options = {}; - + var options = this.getDefaultItemSettingsByName(tiledObject.name); options.name = tiledObject.name; - options.rotation = tiledObject.rotation; - options.width = tiledObject.width / Settings.TILE_RATIO; - options.height = tiledObject.height / Settings.TILE_RATIO; - options.x = (tiledObject.x + tiledObject.width / 2) / Settings.TILE_RATIO; + options.x = (tiledObject.x + options.width / 2) / Settings.TILE_RATIO; options.y = (tiledObject.y + options.height / 2) / Settings.TILE_RATIO; - - if (!options.width) options.width = undefined; - if (!options.height) options.height = undefined; - - var defaultOptions = this.getDefaultItemSettingsByName(options.name); - - options = Options.merge(options, defaultOptions); + // FIXME: check RAD vs. DEG for options.rotation = tiledObject.rotation; return options; }; - TiledLevel.prototype.getDefaultItemSettingsByName = function(name) { if(!name) { diff --git a/recordings/Quickstart-2015-03-15T19:00:28.545Z-debug_residence_stones.rec b/recordings/Quickstart-2015-03-15T19:00:28.545Z-debug_residence_stones.rec index f10b78b..be27a2c 100644 --- a/recordings/Quickstart-2015-03-15T19:00:28.545Z-debug_residence_stones.rec +++ b/recordings/Quickstart-2015-03-15T19:00:28.545Z-debug_residence_stones.rec @@ -1,4 +1,4 @@ -m1426446028547{"recipient":"channel","data":{"addUser":{"id":"7389285181034131943","nickname":"Jeena"}}} +m1426446028547{"recipient":"channel","data":{"addUser":{"id":"7389285181034131943","nickname":"Bot1"}}} m1426446029119{"recipient":"7389285181034131943","data":"{\"gameCommand\":\"{\\\"clientReady\\\":null}\"}"} w1426446029547{"doll-7389285181034131943":{"p":{"x":26.757009396292265,"y":2.8537988666369247},"a":0,"lv":{"x":0,"y":3.686287386450715e-18},"av":0,"as":"stand","laxy":{"x":0,"y":0}},"item-6":{"p":{"x":17.676190476190477,"y":14.278214285714286},"a":0,"lv":{"x":0,"y":0},"av":0},"item-5":{"p":{"x":20.68034223796989,"y":14.27172409912905},"a":0.05645956288623199,"lv":{"x":-0.3822032971313994,"y":0.10581586623357915},"av":-0.9131901027366345},"item-4":{"p":{"x":20.210667860242594,"y":14.23713937029844},"a":0.2172662762511257,"lv":{"x":-0.4539838684349691,"y":0.056447865910879066},"av":-0.8171646189887583},"item-3":{"p":{"x":22.4,"y":14.277445638095237},"a":0,"lv":{"x":0,"y":0},"av":0},"item-2":{"p":{"x":9.013612698412686,"y":18.087738095238098},"a":0,"lv":{"x":0,"y":0},"av":0},"item-1":{"p":{"x":19.642184126984116,"y":14.278214285714286},"a":0,"lv":{"x":0,"y":0},"av":0},"item-0":{"p":{"x":19.14632479802086,"y":14.27055244283271},"a":-0.030402669209750526,"lv":{"x":0.36764627338079947,"y":0.11541986576858798},"av":0.6858739292935763}} w1426446030548{"doll-7389285181034131943":{"p":{"x":26.757009396292265,"y":2.8537988666369247},"a":0,"lv":{"x":0,"y":0},"av":0,"as":"stand","laxy":{"x":0,"y":0}},"item-6":{"p":{"x":17.676190476190477,"y":14.278214285714286},"a":0,"lv":{"x":0,"y":0},"av":0},"item-5":{"p":{"x":20.676956793943322,"y":14.27693273489722},"a":-0.006893630787064592,"lv":{"x":0,"y":0},"av":0},"item-4":{"p":{"x":20.200040618322713,"y":14.276203443653712},"a":-0.0004911852214511643,"lv":{"x":-0.0017410956075321858,"y":8.552005003579723e-7},"av":3.946495907847236e-17},"item-3":{"p":{"x":22.4,"y":14.277445638095237},"a":0,"lv":{"x":0,"y":0},"av":0},"item-2":{"p":{"x":9.013612698412686,"y":18.087738095238098},"a":0,"lv":{"x":0,"y":0},"av":0},"item-1":{"p":{"x":19.642184126984116,"y":14.278214285714286},"a":0,"lv":{"x":0,"y":0},"av":0},"item-0":{"p":{"x":19.147450032657666,"y":14.276009262801196},"a":0.0025201794161469693,"lv":{"x":0,"y":0},"av":0}} diff --git a/static/maps/tiled/stones.json b/static/maps/tiled/stones.json index 6e243d2..381276d 100644 --- a/static/maps/tiled/stones.json +++ b/static/maps/tiled/stones.json @@ -13,7 +13,7 @@ "type":"imagelayer", "visible":true, "width":0, - "x":121, + "x":120, "y":43 }, { @@ -402,6 +402,66 @@ "width":0, "x":286.077500264968, "y":59.318656270437 + }, + { + "height":0, + "id":35, + "name":"Skateboard", + "properties": + { + + }, + "rotation":0, + "type":"", + "visible":true, + "width":0, + "x":1317, + "y":458 + }, + { + "height":0, + "id":36, + "name":"Laundry Machine", + "properties": + { + + }, + "rotation":0, + "type":"", + "visible":true, + "width":0, + "x":557, + "y":711 + }, + { + "height":0, + "id":39, + "name":"Laundry Machine", + "properties": + { + + }, + "rotation":0, + "type":"", + "visible":true, + "width":0, + "x":1557, + "y":508 + }, + { + "height":0, + "id":40, + "name":"Laundry Machine", + "properties": + { + + }, + "rotation":0, + "type":"", + "visible":true, + "width":0, + "x":1457, + "y":733 }], "opacity":1, "type":"objectgroup", @@ -550,7 +610,7 @@ "x":0, "y":0 }], - "nextobjectid":35, + "nextobjectid":41, "orientation":"orthogonal", "properties": {