From 039213cf50889f90637dcb7776be6ae3ff5f6136 Mon Sep 17 00:00:00 2001 From: logsol Date: Wed, 19 Mar 2014 02:40:03 +0100 Subject: [PATCH] missing commits from last commit 7eb3d0b8b0 --- app/Game/Channel/GameObjects/Doll.js | 10 +- app/Game/Client/Loader/TiledLevel.js | 3 +- app/Game/Config/Settings.js | 2 +- app/Game/Core/GameObjects/Item.js | 12 +- app/Game/Core/Loader/Level.js | 3 +- app/Game/Core/Loader/TiledLevel.js | 53 +++- app/Lib/Utilities/Options.js | 8 + static/img/Items/kitchen/spoon.gif | Bin 179 -> 3293 bytes static/maps/tiled/debug.json | 158 +++++----- static/maps/tiled/stones.json | 0 static/maps/tiled/stones2.json | 438 +++++++-------------------- 11 files changed, 257 insertions(+), 430 deletions(-) mode change 100755 => 100644 static/maps/tiled/stones.json diff --git a/app/Game/Channel/GameObjects/Doll.js b/app/Game/Channel/GameObjects/Doll.js index b73d06b..34014e3 100755 --- a/app/Game/Channel/GameObjects/Doll.js +++ b/app/Game/Channel/GameObjects/Doll.js @@ -53,14 +53,16 @@ function (Parent, Item, Box2D, Nc) { if(absItemVelocity.x > max || absItemVelocity.y > max) { if(item.lastMoved && item.lastMoved.player != this.player) { - var damage = b2Math.SubtractVV(itemVelocity, ownVelocity); - damage.Abs(); - damage.Multiply(itemMass); + var damageVector = b2Math.SubtractVV(itemVelocity, ownVelocity); + damageVector.Abs(); + damageVector.Multiply(itemMass); + var damage = damageVector.Length() * 2; + damage *= item.options.danger ? item.options.danger : 1; var player = item.lastMoved.player; var callback = function() { - self.player.addDamage(damage.Length() * 2, player); + self.player.addDamage(damage, player); } Nc.trigger(Nc.ns.channel.engine.worldQueue.add, callback) diff --git a/app/Game/Client/Loader/TiledLevel.js b/app/Game/Client/Loader/TiledLevel.js index cd5fb98..d5cff31 100644 --- a/app/Game/Client/Loader/TiledLevel.js +++ b/app/Game/Client/Loader/TiledLevel.js @@ -29,7 +29,8 @@ function (Parent, Settings) { var objects = this.getLayer(levelData, "items").objects; for (var i = 0; i < objects.length; i++) { var object = objects[i]; - var options = object.properties; + + var options = this.gatherOptions(object); var texturePath = Settings.GRAPHICS_PATH + Settings.GRAPHICS_SUBPATH_ITEMS diff --git a/app/Game/Config/Settings.js b/app/Game/Config/Settings.js index 9922ab4..ce32adf 100755 --- a/app/Game/Config/Settings.js +++ b/app/Game/Config/Settings.js @@ -18,7 +18,7 @@ define(function() { GRAPHICS_SUBPATH_CHARACTERS: 'Characters/', GRAPHICS_SUBPATH_TILES: 'Tiles/', MAPS_PATH: 'static/maps/tiled/', - DEFAULT_LEVELS: ['debug', 'stones2', 'debug'], + DEFAULT_LEVELS: ['stones2', 'debug', 'stones2', 'debug'], RATIO: 21, //35 // original tile size is 25 but we want it to resize to 20 diff --git a/app/Game/Core/GameObjects/Item.js b/app/Game/Core/GameObjects/Item.js index 29d7d4e..a04bac2 100644 --- a/app/Game/Core/GameObjects/Item.js +++ b/app/Game/Core/GameObjects/Item.js @@ -2,14 +2,17 @@ define([ "Game/" + GLOBALS.context + "/GameObjects/GameObject", "Lib/Vendor/Box2D", "Lib/Utilities/Options", - "Game/Config/Settings" + "Game/Config/Settings", + "Lib/Utilities/Exception" ], -function (Parent, Box2D, Options, Settings) { +function (Parent, Box2D, Options, Settings, Exception) { function Item(physicsEngine, uid, options) { + var floatOptions = { grabAngle: parseFloat(options.grabAngle), + danger: parseFloat(options.danger), weight: parseFloat(options.weight), width: parseFloat(options.width), height: parseFloat(options.height), @@ -21,6 +24,11 @@ function (Parent, Box2D, Options, Settings) { this.options = Options.merge(floatOptions, options); + if(!this.options.category) { + // FIXME add more validation + console.warn('item category empty (' + this.options.name + ')' ); + } + Parent.call(this, physicsEngine, uid); this.createFixture(); this.body.ResetMassData(); diff --git a/app/Game/Core/Loader/Level.js b/app/Game/Core/Loader/Level.js index 68a67e0..3e2d497 100755 --- a/app/Game/Core/Loader/Level.js +++ b/app/Game/Core/Loader/Level.js @@ -2,14 +2,13 @@ define([ "Game/Config/Settings", "Lib/Vendor/Box2D", "Lib/Utilities/NotificationCenter", - "Lib/Utilities/Exception", "Game/" + GLOBALS.context + "/Collision/Detector", "Game/" + GLOBALS.context + "/GameObjects/Tile", "Game/" + GLOBALS.context + "/GameObjects/Item", "Game/" + GLOBALS.context + "/GameObjects/Items/Skateboard", "Game/" + GLOBALS.context + "/GameObjects/Items/RagDoll" -], function (Settings, Box2D, Nc, Exception, CollisionDetector, Tile, Item, Skateboard, RagDoll) { +], function (Settings, Box2D, Nc, CollisionDetector, Tile, Item, Skateboard, RagDoll) { function Level (uid, engine, gameObjects) { this.uid = uid; diff --git a/app/Game/Core/Loader/TiledLevel.js b/app/Game/Core/Loader/TiledLevel.js index 4303faa..baf4d95 100755 --- a/app/Game/Core/Loader/TiledLevel.js +++ b/app/Game/Core/Loader/TiledLevel.js @@ -1,16 +1,20 @@ define([ "Game/" + GLOBALS.context + "/Loader/Level", "Game/Config/Settings", + "Game/Config/ItemSettings", "Lib/Vendor/Box2D", + "Lib/Utilities/Options", + "Lib/Utilities/Exception", "Game/" + GLOBALS.context + "/Collision/Detector", "Game/" + GLOBALS.context + "/GameObjects/Tile", "Game/" + GLOBALS.context + "/GameObjects/Item", "Game/" + GLOBALS.context + "/GameObjects/Items/Skateboard", -], function (Parent, Settings, Box2D, CollisionDetector, Tile, Item, Skateboard) { +], function (Parent, Settings, ItemSettings, Box2D, Options, Exception, CollisionDetector, Tile, Item, Skateboard) { // Public function TiledLevel (path, engine, gameObjects) { + this.levelData = null; Parent.call(this, path, engine, gameObjects); } @@ -57,19 +61,58 @@ define([ TiledLevel.prototype.createItems = function() { var objects = this.getLayer(this.levelData, "items").objects; + for (var i = 0; i < objects.length; i++) { var object = objects[i]; - var options = object.properties; - options.x = object.x / Settings.TILE_RATIO; - options.y = object.y / Settings.TILE_RATIO; + + var options = this.gatherOptions(object); + var uid = "item-" + i; var item = this.createItem(uid, options); this.gameObjects.animated.push(item); }; }; + TiledLevel.prototype.gatherOptions = function(tiledObject) { + var options = {}; + + 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.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); + //options = Options.merge(tiledObject.properties, options); + + return options; + }; + + + TiledLevel.prototype.getDefaultItemSettingsByName = function(name) { + + if(!name) { + throw new Exception('Item name cannot be be empty'); + } + + if(ItemSettings[name] === undefined) { + throw new Exception('Item name (' + name + ') cannot be found in item list'); + } + + var options = ItemSettings.Default; + + options = Options.merge(ItemSettings[name], options); + + return options; + }; + TiledLevel.prototype.getTileImagePath = function(gid) { - //console.log(this.levelData.tilesets) for (var i = 0; i < this.levelData.tilesets.length; i++) { var tileset = this.levelData.tilesets[i]; var offset = tileset.firstgid; diff --git a/app/Lib/Utilities/Options.js b/app/Lib/Utilities/Options.js index 31b7ae2..7b26b28 100644 --- a/app/Lib/Utilities/Options.js +++ b/app/Lib/Utilities/Options.js @@ -26,10 +26,18 @@ function (Exception) { return preset; } + // FIXME there is a bad bug here, the preset is being manipulated by reference, so no config can be used! + + // hotfix for the bug + preset = JSON.parse(JSON.stringify(preset)); + for (var key in options) { if(!preset.hasOwnProperty(key)) { preset[key] = options[key]; } else { + if(options[key] === undefined) { + continue; + } if(options[key].constructor !== Object) { preset[key] = options[key]; } else { diff --git a/static/img/Items/kitchen/spoon.gif b/static/img/Items/kitchen/spoon.gif index 7304ebe7a1f95eca41ad56142526d4dfd072af84..74a9c487094acae8f4f084cacd8c2f9f722c1d4d 100755 GIT binary patch literal 3293 zcmbW4cT`hJ7r^JemtH7Ih=7#Pn^YwP5GkRBB1MWIDlrKVAOS-HHdGK%ffYps1QbD5 zMO<)o1!S#=VqsA%*j+WuxpU{(4bT*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