From bdab2a5760a9a3ae38bd50d180f9f884d31f2a2c Mon Sep 17 00:00:00 2001 From: Jeena Date: Thu, 16 Jan 2014 19:33:37 +0100 Subject: [PATCH] fixed skateboard and mesh positioning --- app/Game/Client/GameObjects/Doll.js | 2 +- app/Game/Client/GameObjects/Tile.js | 7 +- app/Game/Client/View/Views/PixiView.js | 29 ++++---- app/Game/Config/Settings.js | 6 +- app/Game/Core/GameObjects/Doll.js | 64 ++++++++++++++---- app/Game/Core/GameObjects/Items/Skateboard.js | 10 +-- app/Game/Core/Loader/Level.js | 4 +- app/Game/Core/Player.js | 6 ++ .../WithArms/ChuckAnimations0001.png | Bin 721 -> 749 bytes 9 files changed, 83 insertions(+), 45 deletions(-) mode change 100755 => 100644 static/img/Animation/WithArms/ChuckAnimations0001.png diff --git a/app/Game/Client/GameObjects/Doll.js b/app/Game/Client/GameObjects/Doll.js index 2a5c4df..c0b7135 100755 --- a/app/Game/Client/GameObjects/Doll.js +++ b/app/Game/Client/GameObjects/Doll.js @@ -138,7 +138,7 @@ function (Parent, Settings, NotificationCenter, Exception) { this.headMesh, { x: this.body.GetPosition().x * Settings.RATIO, - y: this.body.GetPosition().y * Settings.RATIO - 31 + y: this.body.GetPosition().y * Settings.RATIO - this.height + this.headHeight } ) } diff --git a/app/Game/Client/GameObjects/Tile.js b/app/Game/Client/GameObjects/Tile.js index 116d097..c02dbc3 100755 --- a/app/Game/Client/GameObjects/Tile.js +++ b/app/Game/Client/GameObjects/Tile.js @@ -31,8 +31,7 @@ function (Parent, Settings, NotificationCenter) { callback, { width: Settings.TILE_SIZE, - height: Settings.TILE_SIZE, - pivot: "mb" + height: Settings.TILE_SIZE } ); }; @@ -47,8 +46,8 @@ function (Parent, Settings, NotificationCenter) { NotificationCenter.trigger("view/updateMesh", this.mesh, { - x: this.options.x * Settings.TILE_SIZE, - y: this.options.y * Settings.TILE_SIZE, + x: this.body.GetPosition().x * Settings.RATIO - Settings.TILE_SIZE / 2, + y: this.body.GetPosition().y * Settings.RATIO - Settings.TILE_SIZE / 2 } ); } diff --git a/app/Game/Client/View/Views/PixiView.js b/app/Game/Client/View/Views/PixiView.js index 08caef4..538044e 100755 --- a/app/Game/Client/View/Views/PixiView.js +++ b/app/Game/Client/View/Views/PixiView.js @@ -89,12 +89,18 @@ function (Parent, DomController, PIXI, Settings, NotificationCenter) { if (options.height) mesh.height = options.height; if (options.visible === true || options.visible === false) mesh.visible = options.visible; if (options.pivot) { - switch(options.pivot.length) { - default: - mesh.pivot.x = mesh.width / 2; - mesh.pivot.y = mesh.height; - break; + if(options.pivot.length) { + switch(options.pivot) { + case "lb": + mesh.pivot.x = mesh.width / 2; + mesh.pivot.y = mesh.height / 2; + break; + default: + mesh.pivot.x = mesh.width / 2; + mesh.pivot.y = mesh.height; + break; + } } }; } @@ -105,16 +111,11 @@ function (Parent, DomController, PIXI, Settings, NotificationCenter) { } PixiView.prototype.calculateCameraPosition = function() { - - var reference = this.me.getPosition(); - var pos = {}; - - pos.x = -reference.x; - pos.y = reference.y; - var zoom = this.container.scale.x; - pos.x = pos.x * Settings.RATIO * zoom; - pos.y = -(pos.y * Settings.RATIO) * zoom; + + var pos = this.me.getHeadPosition(); + pos.x *= -Settings.RATIO * zoom; + pos.y *= -Settings.RATIO * zoom; pos.x -= this.me.playerController.xyInput.x * Settings.STAGE_WIDTH / 4; pos.y += this.me.playerController.xyInput.y * Settings.STAGE_HEIGHT / 4; diff --git a/app/Game/Config/Settings.js b/app/Game/Config/Settings.js index 889edb3..5c38de0 100755 --- a/app/Game/Config/Settings.js +++ b/app/Game/Config/Settings.js @@ -17,7 +17,7 @@ define({ GRAPHICS_SUBPATH_TILES: 'Tiles/', RATIO: 21, //35 - TILE_SIZE: 15, //15 + TILE_SIZE: 65, //15, 25 is original picture CAMERA_IS_ORTHOGRAPHIC: true, VIEW_CONTROLLER: 0 ? 'Three' : 'Pixi', @@ -45,9 +45,7 @@ define({ // BROWSER CANVAS_DOM_ID: 'canvasContainer', IS_BROWSER_ENVIRONMENT: typeof window !== 'undefined', - USE_WEGBL: true, - - DEBUG_MODE: 1, + USE_WEGBL: true, // NETWORKING WORLD_UPDATE_BROADCAST_INTERVAL: 70, diff --git a/app/Game/Core/GameObjects/Doll.js b/app/Game/Core/GameObjects/Doll.js index f6639cc..be169bf 100755 --- a/app/Game/Core/GameObjects/Doll.js +++ b/app/Game/Core/GameObjects/Doll.js @@ -10,6 +10,11 @@ function (Parent, Box2D, Settings, CollisionDetector, Item) { function Doll (physicsEngine, uid) { + this.height = 43; + this.width = 9; + this.headHeight = 12; + this.reachDistance = 20; + Parent.call(this, physicsEngine, uid); this.standing = false; @@ -33,8 +38,8 @@ function (Parent, Box2D, Settings, CollisionDetector, Item) { Doll.prototype.getBodyDef = function() { var bodyDef = new Box2D.Dynamics.b2BodyDef(); - bodyDef.position.x = 220 / Settings.RATIO; - bodyDef.position.y = 0 / Settings.RATIO; + bodyDef.position.x = 0; + bodyDef.position.y = 0; bodyDef.fixedRotation = true; bodyDef.linearDamping = Settings.PLAYER_LINEAR_DAMPING; bodyDef.type = Box2D.Dynamics.b2Body.b2_dynamicBody; @@ -50,21 +55,25 @@ function (Parent, Box2D, Settings, CollisionDetector, Item) { fixtureDef.restitution = Settings.PLAYER_RESTITUTION; var headShape = new Box2D.Collision.Shapes.b2CircleShape(); - headShape.SetRadius(5 / Settings.RATIO); - headShape.SetLocalPosition(new Box2D.Common.Math.b2Vec2(0 / Settings.RATIO, -35 / Settings.RATIO)); + headShape.SetRadius(this.width / 2 / Settings.RATIO); + headShape.SetLocalPosition(new Box2D.Common.Math.b2Vec2(0, -(this.height - (this.width / 2)) / Settings.RATIO)); fixtureDef.shape = headShape; fixtureDef.isSensor = false; this.body.CreateFixture(fixtureDef); var bodyShape = new Box2D.Collision.Shapes.b2PolygonShape(); - bodyShape.SetAsOrientedBox(5 / Settings.RATIO, 16 / Settings.RATIO, new Box2D.Common.Math.b2Vec2(0 / Settings.RATIO, -19 / Settings.RATIO)); + bodyShape.SetAsOrientedBox( + this.width / 2 / Settings.RATIO, + (this.height - this.width) / 2 / Settings.RATIO, + new Box2D.Common.Math.b2Vec2(0, -this.height / 2 / Settings.RATIO) + ); fixtureDef.shape = bodyShape; fixtureDef.isSensor = false; this.body.CreateFixture(fixtureDef); var legsShape = new Box2D.Collision.Shapes.b2CircleShape(); - legsShape.SetRadius(5 / Settings.RATIO); - legsShape.SetLocalPosition(new Box2D.Common.Math.b2Vec2(0 / Settings.RATIO, -3 / Settings.RATIO)); + legsShape.SetRadius(this.width / 2 / Settings.RATIO); + legsShape.SetLocalPosition(new Box2D.Common.Math.b2Vec2(0, -this.width / 2 / Settings.RATIO)); fixtureDef.shape = legsShape; fixtureDef.friction = Settings.PLAYER_FRICTION; fixtureDef.isSensor = false; @@ -74,8 +83,8 @@ function (Parent, Box2D, Settings, CollisionDetector, Item) { fixtureDef.density = 0; var feetShape = new Box2D.Collision.Shapes.b2CircleShape(); - feetShape.SetRadius(4 / Settings.RATIO); - feetShape.SetLocalPosition(new Box2D.Common.Math.b2Vec2(0 / Settings.RATIO, 2 / Settings.RATIO)); + feetShape.SetRadius((this.width - 1) / 2 / Settings.RATIO); // the -1 one prevents collisions with walls + feetShape.SetLocalPosition(new Box2D.Common.Math.b2Vec2(0, 2 / Settings.RATIO)); // 2 is offset into ground fixtureDef.shape = feetShape; fixtureDef.isSensor = true; @@ -86,7 +95,14 @@ function (Parent, Box2D, Settings, CollisionDetector, Item) { this.body.CreateFixture(fixtureDef); var grabSensorLeftShape = new Box2D.Collision.Shapes.b2PolygonShape(); - grabSensorLeftShape.SetAsOrientedBox(10 / Settings.RATIO, 20 / Settings.RATIO, new Box2D.Common.Math.b2Vec2(-10 / Settings.RATIO, -10 / Settings.RATIO)); + grabSensorLeftShape.SetAsOrientedBox( + this.reachDistance / 2 / Settings.RATIO, + ((this.height / 2) + this.reachDistance / 4) / Settings.RATIO, + new Box2D.Common.Math.b2Vec2( + -this.reachDistance / 2 / Settings.RATIO, + -this.height / 2 / Settings.RATIO + ) + ); fixtureDef.shape = grabSensorLeftShape; fixtureDef.isSensor = true; fixtureDef.userData = { @@ -97,7 +113,14 @@ function (Parent, Box2D, Settings, CollisionDetector, Item) { this.body.CreateFixture(fixtureDef); var grabSensorRightShape = new Box2D.Collision.Shapes.b2PolygonShape(); - grabSensorRightShape.SetAsOrientedBox(10 / Settings.RATIO, 20 / Settings.RATIO, new Box2D.Common.Math.b2Vec2(10 / Settings.RATIO, -10 / Settings.RATIO)); + grabSensorRightShape.SetAsOrientedBox( + this.reachDistance / 2 / Settings.RATIO, + ((this.height / 2) + this.reachDistance / 4) / Settings.RATIO, + new Box2D.Common.Math.b2Vec2( + this.reachDistance / 2 / Settings.RATIO, + -this.height / 2 / Settings.RATIO + ) + ); fixtureDef.shape = grabSensorRightShape; fixtureDef.isSensor = true; @@ -129,7 +152,19 @@ function (Parent, Box2D, Settings, CollisionDetector, Item) { } Doll.prototype.getPosition = function() { - return this.body.GetPosition(); + var pos = this.body.GetPosition(); + return { + x: pos.x, + y: pos.y + }; + }; + + Doll.prototype.getHeadPosition = function() { + var pos = this.body.GetPosition(); + return { + x: pos.x, + y: pos.y - (this.height - this.headHeight / 2) / Settings.RATIO + }; }; Doll.prototype.setFriction = function (friction) { @@ -249,11 +284,10 @@ function (Parent, Box2D, Settings, CollisionDetector, Item) { var p = this.body.GetPosition(); this.holdingItem.body.SetPosition(new Box2D.Common.Math.b2Vec2( - p.x + ((this.holdingItem.options.width / Settings.RATIO / 2 + 5 / Settings.RATIO) * this.lookDirection), - p.y - 1 + p.x + ((this.holdingItem.options.width / Settings.RATIO / 2 + this.width / 2 / Settings.RATIO) * this.lookDirection), + p.y - 1 // 1m in the air )); this.holdingItem.flip(this.lookDirection); - //this.holdingItem.body.SetAngle(Math.PI * 2 / 180 * 20 * -this.lookDirection); this.holdingItem.body.SetAngle((this.holdingItem.options.grabAngle || 0) * this.lookDirection); var jointDef = new Box2D.Dynamics.Joints.b2WeldJointDef(); diff --git a/app/Game/Core/GameObjects/Items/Skateboard.js b/app/Game/Core/GameObjects/Items/Skateboard.js index 678f8c5..72b0b92 100755 --- a/app/Game/Core/GameObjects/Items/Skateboard.js +++ b/app/Game/Core/GameObjects/Items/Skateboard.js @@ -13,11 +13,11 @@ function (Parent, Box2D, Settings) { this.wheels = [ this.addWheel( options.x + 8, - options.y + 1.5 + options.y - 1.5 ), this.addWheel( options.x - 8, - options.y + 1.5 + options.y - 1.5 ) ]; } @@ -26,13 +26,13 @@ function (Parent, Box2D, Settings) { Skateboard.prototype.createFixture = function () { - var itemShape = new Box2D.Collision.Shapes.b2PolygonShape(); + var deckShape = new Box2D.Collision.Shapes.b2PolygonShape(); var w = this.options.width / Settings.RATIO; var h = 1.5 / Settings.RATIO; - itemShape.SetAsOrientedBox(w / 2, h / 2, new Box2D.Common.Math.b2Vec2(0, -(1.5 / Settings.RATIO))); + deckShape.SetAsOrientedBox(w / 2, h / 2, new Box2D.Common.Math.b2Vec2(0, -(4.5 / Settings.RATIO))); var fixtureDef = new Box2D.Dynamics.b2FixtureDef(); - fixtureDef.shape = itemShape; + fixtureDef.shape = deckShape; var offset = 4, factor = 80; diff --git a/app/Game/Core/Loader/Level.js b/app/Game/Core/Loader/Level.js index 40c84c0..a23a937 100755 --- a/app/Game/Core/Loader/Level.js +++ b/app/Game/Core/Loader/Level.js @@ -43,7 +43,6 @@ define([ for (var i = 0; i < tiles.length; i++) { var options = tiles[i]; options.m = this.tileAtPositionExists(options.x, options.y - 1) ? "Soil" : "GrassSoil"; - this.gameObjects.fixed.push(new Tile(this.engine, "tile-" + i, options)); } } @@ -118,7 +117,7 @@ define([ // o o o // o o o - this.levelObject = { + this.levelObject = this.levelObject || { /* Material densities (g/cm^3): @@ -277,6 +276,7 @@ microwave: 3.744 */ [ + {s:1, x:0, y:0, r:0}, {s:1, x:1, y:1, r:0}, {s:1, x:3, y:18}, {s:1, x:37, y:27}, diff --git a/app/Game/Core/Player.js b/app/Game/Core/Player.js index d74dd9c..e5383f8 100755 --- a/app/Game/Core/Player.js +++ b/app/Game/Core/Player.js @@ -30,6 +30,12 @@ function (Doll, Settings) { return this.doll.getPosition(); } + Player.prototype.getHeadPosition = function () { + if(!this.doll) return false; + return this.doll.getHeadPosition(); + } + + Player.prototype.move = function (direction) { this.doll.move(direction); } diff --git a/static/img/Animation/WithArms/ChuckAnimations0001.png b/static/img/Animation/WithArms/ChuckAnimations0001.png old mode 100755 new mode 100644 index d77775bc2fa6aca53f5adccbf534f16f644fac43..237d80cabbdbba223287d4203ba42769da711893 GIT binary patch delta 726 zcmV;{0xA8`1?>fpBYyxHbVXQnQ*UN;cVTj606}DLVr3vnZDD6+Qe|Oed2z{QJOBU! zk4Z#9RCwC#SHEx5KooxO?8a6TV3Wj-e;#*s+|Uq&lEzLEd4JN$pDpYB`MvM`IHZ)q zUNHiD$VOyFWd3O~VlOWv;&0E+F3!J>@aoF?nF#k&GQ{2f4FZ-1(+#+IeSz~>Vz;-G2vezPSOIWs z53)H02*J+SX@9W`m>Va;Nkry39yD6yw!Px1vpaJfPK$-aAVUQIy2@I1nW6#jWr6z5_mbGrQa1=mDgl_1YNp>5b;*ASXI z4Hi05*Q|@L9k^JLMOrE-B1~syfCvb>9%izt^5|@Fq0c2krfN>YF=aEr#}AJ|RhJ-> zNw;fE`F~zGLX;oHUuQo2H~=p{&jwf`VZ}8~6CB4L-VA(mH3y&UsW5a+PR2==Ox#D| z(NSfPBSa+yX7P|}6=h!s*Q$?~~dY#3iMSv%0RI!JN~WVSfI zdVf8+(*d{XT!t4mFq*74*%l}n8TKjT0UinXS5LESXQ*U$Ox(8Z4v!2w=B|zE%-^hV za58M5A2(p;=oH+!GEX7Fvo@g1svYSF6>VQBw#U<6?56+&0I+xmzB1wRd;kCd07*qo IM6N<$f*YAmXaE2J delta 698 zcmV;r0!97p1dmSgo2pK$z^E+KsOR_q zgh5Pie*sNvaE8D-6d2F(34?h1ISyksx8UlMiCAnq%*V%LrxGc+_x>vYVxQ>n9G^sm zBrObytRMuFLw|idTZ;e){fJzTQEOWcw=R^>WWtNK!|bE1p<}JC1K_*C7IW18Ws+iV zOY?NmC?NGiMQOW|k_p&#LF?#U*lv`!6!5S7L*&+*A* zTI1k!R-|06H@mf3CdE-glE~T>#Q?n@9$hip4kHCG>woQX*TGwmCiL@dhq*ZMg_QJoz{Jr(&ihFn-W{ zje!=y1VPjaGioqGi20Vhy+Qw1%#;U;ln06|eKT62JWyoj`iPvF967XqZA6q