mirror of
https://github.com/logsol/chuck.js.git
synced 2026-05-11 18:47:35 +00:00
added Constants module. fixes #4
This commit is contained in:
parent
f3e186afb1
commit
3c1e7008e5
4 changed files with 29 additions and 13 deletions
|
|
@ -1,4 +1,4 @@
|
||||||
define(["Vendor/Box2D"], function(Box2D) {
|
define(["Vendor/Box2D", "Chuck/Constants"], function(Box2D, Constants) {
|
||||||
|
|
||||||
function Detector(me) {
|
function Detector(me) {
|
||||||
this.me = me;
|
this.me = me;
|
||||||
|
|
@ -15,7 +15,9 @@ define(["Vendor/Box2D"], function(Box2D) {
|
||||||
}
|
}
|
||||||
|
|
||||||
Detector.prototype.handleStand = function(point, isColliding) {
|
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);
|
this.me.onFootSensorDetection(isColliding);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -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;
|
||||||
|
|
||||||
|
});
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
define(["Chuck/Settings", "Vendor/Box2D"], function(Settings, Box2D) {
|
define(["Chuck/Settings", "Chuck/Constants", "Vendor/Box2D"], function(Settings, Constants, Box2D) {
|
||||||
|
|
||||||
// Public
|
// Public
|
||||||
function Level(path, engine) {
|
function Level(path, engine) {
|
||||||
|
|
@ -50,7 +50,7 @@ define(["Chuck/Settings", "Vendor/Box2D"], function(Settings, Box2D) {
|
||||||
fixtureDef.friction = Settings.TILE_FRICTION;
|
fixtureDef.friction = Settings.TILE_FRICTION;
|
||||||
fixtureDef.restitution = Settings.TILE_RESTITUTION;
|
fixtureDef.restitution = Settings.TILE_RESTITUTION;
|
||||||
fixtureDef.isSensor = false;
|
fixtureDef.isSensor = false;
|
||||||
fixtureDef.userData = 'tile';
|
fixtureDef.userData = Constants.COLLISION_IDENTIFIER_TILE;
|
||||||
|
|
||||||
this.engine.createBody(bodyDef).CreateFixture(fixtureDef);
|
this.engine.createBody(bodyDef).CreateFixture(fixtureDef);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -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){
|
function Doll (physicsEngine, id){
|
||||||
this.id = id;
|
this.id = id;
|
||||||
|
|
@ -18,7 +18,7 @@ define(["Vendor/Box2D", "Chuck/Settings"], function(Box2D, Settings){
|
||||||
bodyDef.fixedRotation = true;
|
bodyDef.fixedRotation = true;
|
||||||
bodyDef.linearDamping = Settings.PLAYER_LINEAR_DAMPING;
|
bodyDef.linearDamping = Settings.PLAYER_LINEAR_DAMPING;
|
||||||
bodyDef.type = Box2D.Dynamics.b2Body.b2_dynamicBody;
|
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);
|
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));
|
headShape.SetLocalPosition(new Box2D.Common.Math.b2Vec2(0 / Settings.RATIO, -37 / Settings.RATIO));
|
||||||
fixtureDef.shape = headShape;
|
fixtureDef.shape = headShape;
|
||||||
fixtureDef.isSensor = false;
|
fixtureDef.isSensor = false;
|
||||||
fixtureDef.userData = 'myHead-' + this.id;
|
fixtureDef.userData = Constants.COLLISION_IDENTIFIER_PLAYER_HEAD;
|
||||||
this.body.CreateFixture(fixtureDef);
|
this.body.CreateFixture(fixtureDef);
|
||||||
|
|
||||||
var bodyShape = new Box2D.Collision.Shapes.b2PolygonShape();
|
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));
|
bodyShape.SetAsOrientedBox(5 / Settings.RATIO, 16 / Settings.RATIO, new Box2D.Common.Math.b2Vec2(0 / Settings.RATIO, -21 / Settings.RATIO));
|
||||||
fixtureDef.shape = bodyShape;
|
fixtureDef.shape = bodyShape;
|
||||||
fixtureDef.isSensor = false;
|
fixtureDef.isSensor = false;
|
||||||
fixtureDef.userData = 'myBody-' + this.id;
|
fixtureDef.userData = Constants.COLLISION_IDENTIFIER_PLAYER_CHEST;
|
||||||
this.body.CreateFixture(fixtureDef);
|
this.body.CreateFixture(fixtureDef);
|
||||||
|
|
||||||
var legsShape = new Box2D.Collision.Shapes.b2CircleShape();
|
var legsShape = new Box2D.Collision.Shapes.b2CircleShape();
|
||||||
|
|
@ -48,7 +48,8 @@ define(["Vendor/Box2D", "Chuck/Settings"], function(Box2D, Settings){
|
||||||
fixtureDef.shape = legsShape;
|
fixtureDef.shape = legsShape;
|
||||||
fixtureDef.friction = Settings.PLAYER_FRICTION;
|
fixtureDef.friction = Settings.PLAYER_FRICTION;
|
||||||
fixtureDef.isSensor = false;
|
fixtureDef.isSensor = false;
|
||||||
fixtureDef.userData = 'myLegs-' + this.id;
|
fixtureDef.userData = Constants.COLLISION_IDENTIFIER_PLAYER_LEGS;
|
||||||
|
|
||||||
this.legs = this.body.CreateFixture(fixtureDef);
|
this.legs = this.body.CreateFixture(fixtureDef);
|
||||||
|
|
||||||
var feetShape = new Box2D.Collision.Shapes.b2CircleShape();
|
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));
|
feetShape.SetLocalPosition(new Box2D.Common.Math.b2Vec2(0 / Settings.RATIO, 0 / Settings.RATIO));
|
||||||
fixtureDef.shape = feetShape;
|
fixtureDef.shape = feetShape;
|
||||||
fixtureDef.isSensor = true;
|
fixtureDef.isSensor = true;
|
||||||
fixtureDef.userData = 'myFeet-' + this.id;
|
fixtureDef.userData = Constants.COLLISION_IDENTIFIER_FOOTSENSOR;
|
||||||
this.body.CreateFixture(fixtureDef);
|
this.body.CreateFixture(fixtureDef);
|
||||||
|
|
||||||
this.body.SetActive(false);
|
this.body.SetActive(false);
|
||||||
|
|
@ -74,8 +75,7 @@ define(["Vendor/Box2D", "Chuck/Settings"], function(Box2D, Settings){
|
||||||
Doll.prototype.setFriction = function (friction) {
|
Doll.prototype.setFriction = function (friction) {
|
||||||
if(!friction) friction = -1;
|
if(!friction) friction = -1;
|
||||||
|
|
||||||
if (this.legs.GetFriction() != friction)
|
if (this.legs.GetFriction() != friction) {
|
||||||
{
|
|
||||||
this.legs.SetFriction(friction);
|
this.legs.SetFriction(friction);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue