added Constants module. fixes #4

This commit is contained in:
logsol 2012-07-15 22:32:44 +02:00
parent f3e186afb1
commit 3c1e7008e5
4 changed files with 29 additions and 13 deletions

View file

@ -1,4 +1,4 @@
define(["Vendor/Box2D", "Chuck/Settings"], function(Box2D, Settings){
define(["Vendor/Box2D", "Chuck/Constants", "Chuck/Settings"], function(Box2D, Constants, Settings){
function Doll (physicsEngine, id){
this.id = id;
@ -18,7 +18,7 @@ define(["Vendor/Box2D", "Chuck/Settings"], function(Box2D, Settings){
bodyDef.fixedRotation = true;
bodyDef.linearDamping = Settings.PLAYER_LINEAR_DAMPING;
bodyDef.type = Box2D.Dynamics.b2Body.b2_dynamicBody;
bodyDef.userData = 'player-' + this.id;
bodyDef.userData = Constants.COLLISION_IDENTIFIER_PLAYER + '-' + this.id;
this.body = world.CreateBody(bodyDef);
@ -32,14 +32,14 @@ define(["Vendor/Box2D", "Chuck/Settings"], function(Box2D, Settings){
headShape.SetLocalPosition(new Box2D.Common.Math.b2Vec2(0 / Settings.RATIO, -37 / Settings.RATIO));
fixtureDef.shape = headShape;
fixtureDef.isSensor = false;
fixtureDef.userData = 'myHead-' + this.id;
fixtureDef.userData = Constants.COLLISION_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 = 'myBody-' + this.id;
fixtureDef.userData = Constants.COLLISION_IDENTIFIER_PLAYER_CHEST;
this.body.CreateFixture(fixtureDef);
var legsShape = new Box2D.Collision.Shapes.b2CircleShape();
@ -48,7 +48,8 @@ define(["Vendor/Box2D", "Chuck/Settings"], function(Box2D, Settings){
fixtureDef.shape = legsShape;
fixtureDef.friction = Settings.PLAYER_FRICTION;
fixtureDef.isSensor = false;
fixtureDef.userData = 'myLegs-' + this.id;
fixtureDef.userData = Constants.COLLISION_IDENTIFIER_PLAYER_LEGS;
this.legs = this.body.CreateFixture(fixtureDef);
var feetShape = new Box2D.Collision.Shapes.b2CircleShape();
@ -56,7 +57,7 @@ define(["Vendor/Box2D", "Chuck/Settings"], function(Box2D, Settings){
feetShape.SetLocalPosition(new Box2D.Common.Math.b2Vec2(0 / Settings.RATIO, 0 / Settings.RATIO));
fixtureDef.shape = feetShape;
fixtureDef.isSensor = true;
fixtureDef.userData = 'myFeet-' + this.id;
fixtureDef.userData = Constants.COLLISION_IDENTIFIER_FOOTSENSOR;
this.body.CreateFixture(fixtureDef);
this.body.SetActive(false);
@ -74,8 +75,7 @@ define(["Vendor/Box2D", "Chuck/Settings"], function(Box2D, Settings){
Doll.prototype.setFriction = function (friction) {
if(!friction) friction = -1;
if (this.legs.GetFriction() != friction)
{
if (this.legs.GetFriction() != friction) {
this.legs.SetFriction(friction);
}
}