From 3a07d946b04a7dedaaa2f46343d1188cffb1ccee Mon Sep 17 00:00:00 2001 From: Jeena Date: Fri, 10 Jan 2014 17:25:46 +0100 Subject: [PATCH] fixed throwing and meter --- app/Game/Config/Settings.js | 18 +++---- app/Game/Core/GameObjects/Doll.js | 10 +++- app/Game/Core/GameObjects/Item.js | 14 +++-- app/Game/Core/Loader/Level.js | 87 ++++++++++++++++++++----------- 4 files changed, 84 insertions(+), 45 deletions(-) diff --git a/app/Game/Config/Settings.js b/app/Game/Config/Settings.js index ac087a7..6f6d2e7 100755 --- a/app/Game/Config/Settings.js +++ b/app/Game/Config/Settings.js @@ -5,7 +5,7 @@ define({ // BOX2D INITIALATORS BOX2D_WORLD_AABB_SIZE: 3000, BOX2D_ALLOW_SLEEP: true, - BOX2D_GRAVITY: 16, + BOX2D_GRAVITY: 26, BOX2D_VELOCITY_ITERATIONS: 5, BOX2D_POSITION_ITERATIONS: 5, BOX2D_TIME_STEP: 1 / 60, @@ -16,27 +16,27 @@ define({ GRAPHICS_SUBPATH_CHARACTERS: 'Characters/', GRAPHICS_SUBPATH_TILES: 'Tiles/', - RATIO: 35, + RATIO: 21, //35 TILE_SIZE: 15, //15 CAMERA_IS_ORTHOGRAPHIC: true, VIEW_CONTROLLER: 0 ? 'Three' : 'Pixi', // GAME PLAY - WALK_SPEED: 2.5, - RUN_SPEED: 4, - FLY_SPEED: 3.2, - JUMP_SPEED: 4.0, - JUMP_UPLIFT: 0.05, + WALK_SPEED: 4, + RUN_SPEED: 6.4, + FLY_SPEED: 5.12, + JUMP_SPEED: 70, + MAX_THROW_FORCE: 15, // restitution: bouncyness, friction: rubbing, density: mass TILE_FRICTION: 0.99, TILE_RESTITUTION: 0.1, - PLAYER_DENSITY: 0.96, + PLAYER_DENSITY: 3.68, PLAYER_FRICTION: 5, PLAYER_MOTION_FRICTION: 0.1, PLAYER_RESTITUTION: 0.0, - PLAYER_LINEAR_DAMPING: .5, + PLAYER_LINEAR_DAMPING: 0.8, ITEM_DENSITY: 0.9, ITEM_FRICTION: 0.99, diff --git a/app/Game/Core/GameObjects/Doll.js b/app/Game/Core/GameObjects/Doll.js index 688dba2..361ac67 100755 --- a/app/Game/Core/GameObjects/Doll.js +++ b/app/Game/Core/GameObjects/Doll.js @@ -269,7 +269,15 @@ function (Parent, Box2D, Settings, CollisionDetector, Item) { var body = item.body; body.SetAwake(true); - body.ApplyImpulse(new Box2D.Common.Math.b2Vec2(x * 3, -y * 3), body.GetPosition()); + + body.ApplyImpulse( + new Box2D.Common.Math.b2Vec2( + x * Settings.MAX_THROW_FORCE, + -y * Settings.MAX_THROW_FORCE * 2 // 2 is to throw higher then far + ), + body.GetLocalCenter() + ); + body.SetAngularVelocity(5); }; Doll.prototype.onFootSensorDetection = function(isColliding, fixture) { diff --git a/app/Game/Core/GameObjects/Item.js b/app/Game/Core/GameObjects/Item.js index eaf1f31..7c05a85 100644 --- a/app/Game/Core/GameObjects/Item.js +++ b/app/Game/Core/GameObjects/Item.js @@ -10,6 +10,7 @@ function (Parent, Box2D, Settings) { this.options = options; Parent.call(this, physicsEngine, uid); this.createFixture(); + this.body.ResetMassData(); } Item.prototype = Object.create(Parent.prototype); @@ -28,16 +29,21 @@ function (Parent, Box2D, Settings) { Item.prototype.createFixture = function () { var itemShape = new Box2D.Collision.Shapes.b2PolygonShape(); - var w = this.options.width / 2 / Settings.RATIO; - var h = this.options.height / 2 / Settings.RATIO; - itemShape.SetAsOrientedBox(w, h, new Box2D.Common.Math.b2Vec2(0, -h)); + var w = this.options.width / Settings.RATIO; + var h = this.options.height / Settings.RATIO; + itemShape.SetAsOrientedBox(w / 2, h / 2, new Box2D.Common.Math.b2Vec2(0, -(h/2))); var fixtureDef = new Box2D.Dynamics.b2FixtureDef(); fixtureDef.shape = itemShape; - fixtureDef.density = Settings.ITEM_DENSITY; + + var offset = 4, + factor = 80; + var density = ((this.options.weight + offset) / this.options.width / this.options.height) * factor; + fixtureDef.density = density; fixtureDef.friction = Settings.ITEM_FRICTION; fixtureDef.restitution = Settings.ITEM_RESTITUTION; fixtureDef.isSensor = false; + this.body.CreateFixture(fixtureDef); } diff --git a/app/Game/Core/Loader/Level.js b/app/Game/Core/Loader/Level.js index cc11cc1..f004bc9 100755 --- a/app/Game/Core/Loader/Level.js +++ b/app/Game/Core/Loader/Level.js @@ -104,16 +104,51 @@ define([ // o o o this.levelObject = { + /* +Material densities (g/cm^3): + +wood: 0.63 +steel: 7.859 +banana: 0.95 +microwave: 3.744 + + */ items: [ { name:'Banana', image:'banana.gif', shape:'rectangle', category:'kitchen', - weight:0.2, + weight: 1, width:5, height:9, - x:20, + depth: 3, + x:40, + y:0, + rotation: 0 + }, + { + name:'Refridgerator', + image:'fridge.gif', + shape:'rectangle', + category:'kitchen', + weight: 10, + width:31, + height:53, + x:120, + y:0, + rotation: 0 + }, + { + name:'Microwave', + image:'microwave.gif', + shape:'rectangle', + category:'kitchen', + weight: 4, + width:19, + height:12, + depth: 12, + x:100, y:0, rotation: 0 }, @@ -122,7 +157,7 @@ define([ image:'cleaver_large.gif', shape:'rectangle', category:'kitchen', - weight:1.1, + weight: 3, width:8, height:22, x:40, @@ -134,7 +169,7 @@ define([ image:'cleaver_small.gif', shape:'rectangle', category:'kitchen', - weight:0.8, + weight:2, width:6, height:17, x:60, @@ -146,43 +181,19 @@ define([ image:'coffeemachine.gif', shape:'rectangle', category:'kitchen', - weight:3, + weight:2.4, width:11, height:14, x:80, y:0, rotation: 0 }, - { - name:'Microwave', - image:'microwave.gif', - shape:'rectangle', - category:'kitchen', - weight:7, - width:19, - height:12, - x:100, - y:0, - rotation: 0 - }, - { - name:'Refridgerator', - image:'fridge.gif', - shape:'rectangle', - category:'kitchen', - weight:5, - width:31, - height:53, - x:120, - y:200, - rotation: 0 - }, { name:'Knife', image:'knife.gif', shape:'rectangle', category:'kitchen', - weight:0.3, + weight:1.5, width:4, height:15, x:140, @@ -190,7 +201,21 @@ define([ rotation: 0 } ], - tiles: [ + tiles: /* + (function() { + var tiles = []; + for (var i = 0; i < 50; i++) { + tiles.push({ + s:1, + x:i, + y:5 + }) + }; + return tiles; + })() +*/ + + [ {s:1, x:1, y:1, r:0}, {s:1, x:3, y:18}, {s:1, x:37, y:27},