mirror of
https://github.com/logsol/chuck.js.git
synced 2026-05-11 18:47:35 +00:00
moved client stuff from Engine to Client/Physics/Engine
This commit is contained in:
parent
fc22ac5643
commit
806a6e1d47
2 changed files with 18 additions and 45 deletions
|
|
@ -1,4 +1,4 @@
|
|||
define(["Lib/Vendor/Box2D", "Game/Config/Settings", "Game/Core/Collision/Detector"], function(Box2D, Settings, Detector) {
|
||||
define(["Lib/Vendor/Box2D", "Game/Config/Settings", "Game/Core/Collision/Detector"], function(Box2D, Settings, CollisionDetector) {
|
||||
|
||||
function Doll (physicsEngine, id){
|
||||
this.id = id;
|
||||
|
|
@ -18,7 +18,7 @@ define(["Lib/Vendor/Box2D", "Game/Config/Settings", "Game/Core/Collision/Detecto
|
|||
bodyDef.fixedRotation = true;
|
||||
bodyDef.linearDamping = Settings.PLAYER_LINEAR_DAMPING;
|
||||
bodyDef.type = Box2D.Dynamics.b2Body.b2_dynamicBody;
|
||||
bodyDef.userData = Detector.IDENTIFIER.PLAYER + '-' + this.id;
|
||||
bodyDef.userData = CollisionDetector.IDENTIFIER.PLAYER + '-' + this.id;
|
||||
|
||||
this.body = world.CreateBody(bodyDef);
|
||||
|
||||
|
|
@ -32,14 +32,14 @@ define(["Lib/Vendor/Box2D", "Game/Config/Settings", "Game/Core/Collision/Detecto
|
|||
headShape.SetLocalPosition(new Box2D.Common.Math.b2Vec2(0 / Settings.RATIO, -37 / Settings.RATIO));
|
||||
fixtureDef.shape = headShape;
|
||||
fixtureDef.isSensor = false;
|
||||
fixtureDef.userData = Detector.IDENTIFIER.PLAYER_HEAD;
|
||||
fixtureDef.userData = CollisionDetector.IDENTIFIER.PLAYER_HEAD;
|
||||
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, -21 / Settings.RATIO));
|
||||
fixtureDef.shape = bodyShape;
|
||||
fixtureDef.isSensor = false;
|
||||
fixtureDef.userData = Detector.IDENTIFIER.PLAYER_CHEST;
|
||||
fixtureDef.userData = CollisionDetector.IDENTIFIER.PLAYER_CHEST;
|
||||
this.body.CreateFixture(fixtureDef);
|
||||
|
||||
var legsShape = new Box2D.Collision.Shapes.b2CircleShape();
|
||||
|
|
@ -48,7 +48,7 @@ define(["Lib/Vendor/Box2D", "Game/Config/Settings", "Game/Core/Collision/Detecto
|
|||
fixtureDef.shape = legsShape;
|
||||
fixtureDef.friction = Settings.PLAYER_FRICTION;
|
||||
fixtureDef.isSensor = false;
|
||||
fixtureDef.userData = Detector.IDENTIFIER.PLAYER_LEGS;
|
||||
fixtureDef.userData = CollisionDetector.IDENTIFIER.PLAYER_LEGS;
|
||||
|
||||
this.legs = this.body.CreateFixture(fixtureDef);
|
||||
|
||||
|
|
@ -57,7 +57,7 @@ define(["Lib/Vendor/Box2D", "Game/Config/Settings", "Game/Core/Collision/Detecto
|
|||
feetShape.SetLocalPosition(new Box2D.Common.Math.b2Vec2(0 / Settings.RATIO, 0 / Settings.RATIO));
|
||||
fixtureDef.shape = feetShape;
|
||||
fixtureDef.isSensor = true;
|
||||
fixtureDef.userData = Detector.IDENTIFIER.FOOTSENSOR;
|
||||
fixtureDef.userData = CollisionDetector.IDENTIFIER.FOOTSENSOR;
|
||||
this.body.CreateFixture(fixtureDef);
|
||||
|
||||
this.body.SetActive(false);
|
||||
|
|
|
|||
|
|
@ -1,16 +1,16 @@
|
|||
define(["Chuck/Settings", "Client/Dom", "Vendor/Box2D", "Chuck/Collision/Detector"], function(Settings, Dom, Box2D, CollisionDetector){
|
||||
define([
|
||||
"Game/Config/Settings",
|
||||
"Lib/Vendor/Box2D",
|
||||
"Game/Core/Collision/Detector"
|
||||
],
|
||||
|
||||
function(Settings, Box2D, CollisionDetector) {
|
||||
|
||||
function Engine () {
|
||||
this.world;
|
||||
this.init();
|
||||
}
|
||||
|
||||
Engine.prototype.init = function() {
|
||||
this.world = new Box2D.Dynamics.b2World(new Box2D.Common.Math.b2Vec2(0, Settings.BOX2D_GRAVITY), Settings.BOX2D_ALLOW_SLEEP);
|
||||
|
||||
if(Settings.IS_BROWSER_ENVIRONMENT && Settings.DEBUG_MODE) {
|
||||
this.setupDebugDraw();
|
||||
}
|
||||
this.world = new Box2D.Dynamics.b2World(
|
||||
new Box2D.Common.Math.b2Vec2(0, Settings.BOX2D_GRAVITY),
|
||||
Settings.BOX2D_ALLOW_SLEEP
|
||||
);
|
||||
}
|
||||
|
||||
Engine.prototype.getWorld = function() {
|
||||
|
|
@ -19,36 +19,10 @@ define(["Chuck/Settings", "Client/Dom", "Vendor/Box2D", "Chuck/Collision/Detecto
|
|||
|
||||
Engine.prototype.setCollisionDetector = function(me) {
|
||||
|
||||
var detector = new CollisionDetector(me);
|
||||
var detector = new CollisionDetector(me); // FIXME: check if core collision detector works
|
||||
this.world.SetContactListener(detector.getListener());
|
||||
}
|
||||
|
||||
Engine.prototype.setupDebugDraw = function() {
|
||||
//var debugSprite = Settings.DEBUG_DRAW_CANVAS_SPRITE;
|
||||
var debugSprite = Dom.getDebugCanvas().getContext("2d");
|
||||
|
||||
// set debug draw
|
||||
var debugDraw = new Box2D.Dynamics.b2DebugDraw();
|
||||
|
||||
debugDraw.SetSprite(debugSprite);
|
||||
debugDraw.SetDrawScale(Settings.RATIO);
|
||||
debugDraw.SetFillAlpha(0.5);
|
||||
debugDraw.SetLineThickness(1.0);
|
||||
|
||||
debugDraw.SetFlags(null
|
||||
| Box2D.Dynamics.b2DebugDraw.e_shapeBit
|
||||
| Box2D.Dynamics.b2DebugDraw.e_jointBit
|
||||
//| Box2D.Dynamics.b2DebugDraw.e_coreShapeBit
|
||||
//| Box2D.Dynamics.b2DebugDraw.e_aabbBit
|
||||
//| Box2D.Dynamics.b2DebugDraw.e_centerOfMassBit
|
||||
//| Box2D.Dynamics.b2DebugDraw.e_obbBit
|
||||
//| Box2D.Dynamics.b2DebugDraw.e_pairBit
|
||||
);
|
||||
|
||||
this.world.SetDebugDraw(debugDraw);
|
||||
this.world.SetWarmStarting(true);
|
||||
}
|
||||
|
||||
Engine.prototype.createBody = function(bodyDef) {
|
||||
return this.world.CreateBody(bodyDef);
|
||||
}
|
||||
|
|
@ -56,7 +30,6 @@ define(["Chuck/Settings", "Client/Dom", "Vendor/Box2D", "Chuck/Collision/Detecto
|
|||
Engine.prototype.update = function() {
|
||||
this.world.Step(Settings.BOX2D_TIME_STEP, Settings.BOX2D_VELOCITY_ITERATIONS, Settings.BOX2D_POSITION_ITERATIONS);
|
||||
this.world.ClearForces();
|
||||
this.world.DrawDebugData();
|
||||
}
|
||||
|
||||
return Engine;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue