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"], function(Box2D) {
define(["Vendor/Box2D", "Chuck/Constants"], function(Box2D, Constants) {
function Detector(me) {
this.me = me;
@ -15,7 +15,9 @@ define(["Vendor/Box2D"], function(Box2D) {
}
Detector.prototype.handleStand = function(point, isColliding) {
if (point.GetFixtureA().GetUserData() == 'myFeet' || point.GetFixtureB().GetUserData() == 'myFeet') {
if (point.GetFixtureA().GetUserData() == Constants.COLLISION_IDENTIFIER_FOOTSENSOR
|| point.GetFixtureB().GetUserData() == Constants.COLLISION_IDENTIFIER_FOOTSENSOR) {
this.me.onFootSensorDetection(isColliding);
}
}

View file

@ -1 +1,15 @@
Constants.js
define(function() {
var Constants = {
COLLISION_IDENTIFIER_PLAYER: 'player',
COLLISION_IDENTIFIER_PLAYER_HEAD: 'head',
COLLISION_IDENTIFIER_PLAYER_CHEST: 'chest',
COLLISION_IDENTIFIER_PLAYER_LEGS: 'legs',
COLLISION_IDENTIFIER_PLAYER_FOOT_SENSOR: 'footsensor',
COLLISION_IDENTIFIER_TILE: 'tile'
}
return Constants;
});

View file

@ -1,4 +1,4 @@
define(["Chuck/Settings", "Vendor/Box2D"], function(Settings, Box2D) {
define(["Chuck/Settings", "Chuck/Constants", "Vendor/Box2D"], function(Settings, Constants, Box2D) {
// Public
function Level(path, engine) {
@ -50,7 +50,7 @@ define(["Chuck/Settings", "Vendor/Box2D"], function(Settings, Box2D) {
fixtureDef.friction = Settings.TILE_FRICTION;
fixtureDef.restitution = Settings.TILE_RESTITUTION;
fixtureDef.isSensor = false;
fixtureDef.userData = 'tile';
fixtureDef.userData = Constants.COLLISION_IDENTIFIER_TILE;
this.engine.createBody(bodyDef).CreateFixture(fixtureDef);
}

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);
}
}