mirror of
https://github.com/logsol/chuck.js.git
synced 2026-05-11 10:37:34 +00:00
added ASSERT, fixed #103
This commit is contained in:
parent
55eff36f34
commit
dfa71bc8e5
17 changed files with 249 additions and 153 deletions
|
|
@ -5,10 +5,11 @@ define([
|
|||
"Game/Config/Settings",
|
||||
"Game/" + GLOBALS.context + "/Collision/Detector",
|
||||
"Game/" + GLOBALS.context + "/GameObjects/Item",
|
||||
"Lib/Utilities/NotificationCenter"
|
||||
"Lib/Utilities/NotificationCenter",
|
||||
"Lib/Utilities/Assert"
|
||||
],
|
||||
|
||||
function (Parent, Exception, Box2D, Settings, CollisionDetector, Item, Nc) {
|
||||
function (Parent, Exception, Box2D, Settings, CollisionDetector, Item, Nc, Assert) {
|
||||
|
||||
"use strict";
|
||||
|
||||
|
|
@ -27,8 +28,8 @@ function (Parent, Exception, Box2D, Settings, CollisionDetector, Item, Nc) {
|
|||
this.standing = false;
|
||||
this.moveDirection = 0;
|
||||
this.lookDirection = 0;
|
||||
this.legs;
|
||||
this.footSensor;
|
||||
this.legs = null;
|
||||
this.footSensor = null;
|
||||
this.actionState = null;
|
||||
this.lookAtXY = { x:0, y:0 };
|
||||
this.reachableItems = {
|
||||
|
|
@ -59,6 +60,10 @@ function (Parent, Exception, Box2D, Settings, CollisionDetector, Item, Nc) {
|
|||
};
|
||||
|
||||
Doll.prototype.createFixtures = function () {
|
||||
Assert.number(this.width, this.height);
|
||||
Assert.number(this.reachDistance);
|
||||
Assert.number(this.areaSize);
|
||||
|
||||
var self = this;
|
||||
|
||||
var fixtureDef = new Box2D.Dynamics.b2FixtureDef();
|
||||
|
|
@ -67,13 +72,15 @@ function (Parent, Exception, Box2D, Settings, CollisionDetector, Item, Nc) {
|
|||
fixtureDef.restitution = Settings.PLAYER_RESTITUTION;
|
||||
|
||||
var headShape = new Box2D.Collision.Shapes.b2CircleShape();
|
||||
headShape.SetRadius(this.width / 2 / Settings.RATIO);
|
||||
var radius = this.width / 2 / Settings.RATIO;
|
||||
headShape.SetRadius(radius);
|
||||
|
||||
headShape.SetLocalPosition(new Box2D.Common.Math.b2Vec2(0, -(this.height - (this.width / 2)) / Settings.RATIO));
|
||||
fixtureDef.shape = headShape;
|
||||
fixtureDef.isSensor = false;
|
||||
fixtureDef.userData = {
|
||||
onCollisionChange: this.onImpact.bind(this)
|
||||
}
|
||||
};
|
||||
|
||||
this.body.CreateFixture(fixtureDef);
|
||||
|
||||
|
|
@ -106,7 +113,7 @@ function (Parent, Exception, Box2D, Settings, CollisionDetector, Item, Nc) {
|
|||
|
||||
fixtureDef.userData = {
|
||||
onCollisionChange: this.onFootSensorDetection.bind(this)
|
||||
}
|
||||
};
|
||||
|
||||
this.footSensor = this.body.CreateFixture(fixtureDef);
|
||||
|
||||
|
|
@ -125,7 +132,7 @@ function (Parent, Exception, Box2D, Settings, CollisionDetector, Item, Nc) {
|
|||
onCollisionChange: function(isColliding, fixture) {
|
||||
self.onFixtureWithinReach(isColliding, "left", fixture);
|
||||
}
|
||||
}
|
||||
};
|
||||
this.body.CreateFixture(fixtureDef);
|
||||
|
||||
var grabSensorRightShape = new Box2D.Collision.Shapes.b2PolygonShape();
|
||||
|
|
@ -144,7 +151,7 @@ function (Parent, Exception, Box2D, Settings, CollisionDetector, Item, Nc) {
|
|||
onCollisionChange: function(isColliding, fixture) {
|
||||
self.onFixtureWithinReach(isColliding, "right", fixture);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
this.body.CreateFixture(fixtureDef);
|
||||
|
||||
|
|
@ -163,7 +170,7 @@ function (Parent, Exception, Box2D, Settings, CollisionDetector, Item, Nc) {
|
|||
|
||||
fixtureDef.userData = {
|
||||
onCollisionChange: function(isColliding, fixture) {
|
||||
var userData = fixture.GetBody().GetUserData()
|
||||
var userData = fixture.GetBody().GetUserData();
|
||||
if(userData instanceof Doll) {
|
||||
var doll = userData;
|
||||
var i = self.nearbyDolls.indexOf(doll);
|
||||
|
|
@ -178,28 +185,29 @@ function (Parent, Exception, Box2D, Settings, CollisionDetector, Item, Nc) {
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
this.body.CreateFixture(fixtureDef);
|
||||
}
|
||||
};
|
||||
|
||||
Doll.prototype.setActionState = function(state) {
|
||||
this.actionState = state;
|
||||
}
|
||||
};
|
||||
|
||||
Doll.prototype.getActionState = function() {
|
||||
return this.actionState;
|
||||
}
|
||||
};
|
||||
|
||||
Doll.prototype.isWalking = function() {
|
||||
return ["walk", "walkback", "run"].indexOf(this.actionState) >= 0;
|
||||
}
|
||||
};
|
||||
|
||||
Doll.prototype.spawn = function (x, y) {
|
||||
Assert.number(x, y);
|
||||
this.body.SetPosition(new Box2D.Common.Math.b2Vec2(x / Settings.RATIO, y / Settings.RATIO));
|
||||
this.body.SetActive(true);
|
||||
this.setActionState("fall");
|
||||
}
|
||||
};
|
||||
|
||||
Doll.prototype.getHeadPosition = function() {
|
||||
var pos = this.body.GetPosition();
|
||||
|
|
@ -212,10 +220,12 @@ function (Parent, Exception, Box2D, Settings, CollisionDetector, Item, Nc) {
|
|||
Doll.prototype.setFriction = function (friction) {
|
||||
if(!friction) friction = -1;
|
||||
|
||||
Assert.number(friction);
|
||||
|
||||
if (this.legs.GetFriction() != friction) {
|
||||
this.legs.SetFriction(friction);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
Doll.prototype.move = function (direction) {
|
||||
|
||||
|
|
@ -245,6 +255,8 @@ function (Parent, Exception, Box2D, Settings, CollisionDetector, Item, Nc) {
|
|||
|
||||
this.setFriction(Settings.PLAYER_MOTION_FRICTION);
|
||||
this.body.SetAwake(true);
|
||||
|
||||
Assert.number(speed, direction);
|
||||
var vector = new Box2D.Common.Math.b2Vec2(speed * direction, this.body.GetLinearVelocity().y);
|
||||
this.body.SetLinearVelocity(vector);
|
||||
|
||||
|
|
@ -261,7 +273,7 @@ function (Parent, Exception, Box2D, Settings, CollisionDetector, Item, Nc) {
|
|||
this.setActionState("walkback");
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
Doll.prototype.stop = function () {
|
||||
this.moveDirection = 0;
|
||||
|
|
@ -273,23 +285,20 @@ function (Parent, Exception, Box2D, Settings, CollisionDetector, Item, Nc) {
|
|||
vector.x *= Settings.JUMP_STOP_DAMPING_FACTOR;
|
||||
this.body.SetLinearVelocity(vector);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
Doll.prototype.jump = function () {
|
||||
if (this.isStanding()) {
|
||||
|
||||
this.body.SetAwake(true);
|
||||
|
||||
var jumpSpeed = Settings.JUMP_SPEED;
|
||||
|
||||
var vector = new Box2D.Common.Math.b2Vec2(0, -jumpSpeed);
|
||||
var vector = new Box2D.Common.Math.b2Vec2(0, -Settings.JUMP_SPEED);
|
||||
this.body.SetLinearVelocity(vector);
|
||||
|
||||
this.setStanding(false);
|
||||
|
||||
this.setActionState("jump");
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
Doll.prototype.jumpStop = function () {
|
||||
if (!this.isStanding() ) {
|
||||
|
|
@ -300,17 +309,17 @@ function (Parent, Exception, Box2D, Settings, CollisionDetector, Item, Nc) {
|
|||
this.body.SetLinearVelocity(vector);
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
Doll.prototype.setStanding = function (isStanding) {
|
||||
if (this.standing == isStanding) return;
|
||||
this.standing = isStanding;
|
||||
if(isStanding) this.setActionState("stand");
|
||||
}
|
||||
};
|
||||
|
||||
Doll.prototype.isStanding = function () {
|
||||
return this.standing;
|
||||
}
|
||||
};
|
||||
|
||||
Doll.prototype.lookAt = function(x, y) {
|
||||
var oldLookDirection = this.lookDirection;
|
||||
|
|
@ -344,6 +353,9 @@ function (Parent, Exception, Box2D, Settings, CollisionDetector, Item, Nc) {
|
|||
}
|
||||
|
||||
var bodyPosition = this.body.GetPosition();
|
||||
|
||||
Assert.number(this.width, this.height);
|
||||
Assert.number(this.lookDirection);
|
||||
var handPosition = new Box2D.Common.Math.b2Vec2(
|
||||
bodyPosition.x + ((this.width / 2 / Settings.RATIO) * this.lookDirection),
|
||||
bodyPosition.y - this.height / 4 * 2 / Settings.RATIO // 2/3 of the body height
|
||||
|
|
@ -382,7 +394,7 @@ function (Parent, Exception, Box2D, Settings, CollisionDetector, Item, Nc) {
|
|||
return this.nearbyDolls.length > 0;
|
||||
};
|
||||
|
||||
Doll.prototype.onFootSensorDetection = function(isColliding, fixture) {
|
||||
Doll.prototype.onFootSensorDetection = function(isColliding, fixture) { // jshint unused:false
|
||||
|
||||
var self = this;
|
||||
|
||||
|
|
@ -419,9 +431,9 @@ function (Parent, Exception, Box2D, Settings, CollisionDetector, Item, Nc) {
|
|||
self.setStanding(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
Doll.prototype.onImpact = function(isColliding, fixture) {
|
||||
Doll.prototype.onImpact = function(isColliding, fixture) { // jshint unused:false
|
||||
// overwrite if necessary
|
||||
};
|
||||
|
||||
|
|
@ -439,7 +451,7 @@ function (Parent, Exception, Box2D, Settings, CollisionDetector, Item, Nc) {
|
|||
this.reachableItems[side].splice(i, 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
Doll.prototype.getVelocities = function() {
|
||||
return {
|
||||
|
|
@ -450,7 +462,7 @@ function (Parent, Exception, Box2D, Settings, CollisionDetector, Item, Nc) {
|
|||
|
||||
Doll.prototype.update = function() {
|
||||
|
||||
if (this.body.GetLinearVelocity().x == 0 && this.isWalking()) {
|
||||
if (this.body.GetLinearVelocity().x === 0 && this.isWalking()) {
|
||||
this.stop();
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -4,10 +4,11 @@ define([
|
|||
"Lib/Utilities/Options",
|
||||
"Game/Config/Settings",
|
||||
"Lib/Utilities/Exception",
|
||||
"Lib/Utilities/NotificationCenter"
|
||||
"Lib/Utilities/NotificationCenter",
|
||||
"Lib/Utilities/Assert"
|
||||
],
|
||||
|
||||
function (Parent, Box2D, Options, Settings, Exception, Nc) {
|
||||
function (Parent, Box2D, Options, Settings, Exception, Nc, Assert) {
|
||||
|
||||
"use strict";
|
||||
|
||||
|
|
@ -37,13 +38,13 @@ function (Parent, Box2D, Options, Settings, Exception, Nc) {
|
|||
this.body.ResetMassData();
|
||||
this.flipDirection = 1;
|
||||
|
||||
Nc.trigger(Nc.ns.core.game.gameObject.add, 'animated', this);
|
||||
Nc.trigger(Nc.ns.core.game.gameObject.add, "animated", this);
|
||||
}
|
||||
|
||||
Item.prototype = Object.create(Parent.prototype);
|
||||
|
||||
Item.prototype.getBodyDef = function() {
|
||||
|
||||
Assert.number(this.options.x, this.options.y);
|
||||
var bodyDef = new Box2D.Dynamics.b2BodyDef();
|
||||
bodyDef.type = Box2D.Dynamics.b2Body.b2_dynamicBody;
|
||||
bodyDef.position.x = this.options.x / Settings.RATIO;
|
||||
|
|
@ -51,14 +52,18 @@ function (Parent, Box2D, Options, Settings, Exception, Nc) {
|
|||
bodyDef.angle = 0;
|
||||
|
||||
return bodyDef;
|
||||
}
|
||||
};
|
||||
|
||||
Item.prototype.getFixtureDef = function() {
|
||||
Assert.number(this.options.width, this.options.height);
|
||||
Assert.number(this.options.weight);
|
||||
Assert.number(this.options.bounce);
|
||||
|
||||
var itemShape;
|
||||
var w = this.options.width / Settings.RATIO;
|
||||
var h = this.options.height / Settings.RATIO;
|
||||
|
||||
if(this.options.type == 'circle'){
|
||||
if(this.options.type == "circle") {
|
||||
var r = (w + h) / 4 ;
|
||||
itemShape = new Box2D.Collision.Shapes.b2CircleShape();
|
||||
itemShape.SetRadius(r);
|
||||
|
|
@ -68,22 +73,19 @@ function (Parent, Box2D, Options, Settings, Exception, Nc) {
|
|||
itemShape.SetAsOrientedBox(w / 2, h / 2, new Box2D.Common.Math.b2Vec2(0, -(h/2)));
|
||||
}
|
||||
|
||||
|
||||
var fixtureDef = new Box2D.Dynamics.b2FixtureDef();
|
||||
fixtureDef.shape = itemShape;
|
||||
|
||||
fixtureDef.density = this.options.weight;
|
||||
fixtureDef.friction = Settings.ITEM_FRICTION;
|
||||
|
||||
fixtureDef.restitution = this.options.bounce
|
||||
? this.options.bounce / 10
|
||||
: Settings.ITEM_RESTITUTION;
|
||||
fixtureDef.restitution = this.options.bounce ? this.options.bounce / 10 : Settings.ITEM_RESTITUTION;
|
||||
|
||||
fixtureDef.isSensor = false;
|
||||
|
||||
fixtureDef.userData = {
|
||||
onCollisionChange: this.onCollisionChange.bind(this)
|
||||
}
|
||||
};
|
||||
|
||||
return fixtureDef;
|
||||
};
|
||||
|
|
@ -91,7 +93,7 @@ function (Parent, Box2D, Options, Settings, Exception, Nc) {
|
|||
Item.prototype.createFixture = function () {
|
||||
var fixtureDef = this.getFixtureDef();
|
||||
this.body.CreateFixture(fixtureDef);
|
||||
}
|
||||
};
|
||||
|
||||
Item.prototype.flip = function(direction) {
|
||||
this.flipDirection = direction;
|
||||
|
|
@ -99,24 +101,29 @@ function (Parent, Box2D, Options, Settings, Exception, Nc) {
|
|||
// FIXME: implement body flip if necessary
|
||||
};
|
||||
|
||||
Item.prototype.beingGrabbed = function(player) {
|
||||
Item.prototype.beingGrabbed = function(player) { // jshint unused:false
|
||||
// overwrite if necessary
|
||||
};
|
||||
|
||||
Item.prototype.beingReleased = function(player) {
|
||||
Item.prototype.beingReleased = function(player) { // jshint unused:false
|
||||
// overwrite if necessary
|
||||
};
|
||||
|
||||
Item.prototype.onCollisionChange = function(isColliding, fixture, info) {
|
||||
Item.prototype.onCollisionChange = function(isColliding, fixture, info) { // jshint unused:false
|
||||
// overwrite if necessary
|
||||
};
|
||||
|
||||
Item.prototype.reposition = function(handPosition, direction) {
|
||||
Assert.number(handPosition.x, handPosition.y);
|
||||
Assert.number(direction);
|
||||
Assert.number(this.options.width);
|
||||
Assert.number(this.options.grabAngle);
|
||||
|
||||
this.body.SetAwake(true);
|
||||
var position = new Box2D.Common.Math.b2Vec2(
|
||||
handPosition.x + ((this.options.width / Settings.RATIO / 2) * direction),
|
||||
handPosition.y
|
||||
)
|
||||
);
|
||||
this.body.SetPosition(position);
|
||||
this.flip(direction);
|
||||
this.body.SetAngle((this.options.grabAngle || 0) * direction);
|
||||
|
|
@ -131,20 +138,24 @@ function (Parent, Box2D, Options, Settings, Exception, Nc) {
|
|||
};
|
||||
|
||||
Item.prototype.accelerateBody = function(body, options, carrierVelocity) {
|
||||
Assert.number(this.options.weight);
|
||||
Assert.number(carrierVelocity.x, carrierVelocity.y);
|
||||
Assert.number(options.x, options.y);
|
||||
Assert.number(options.av);
|
||||
|
||||
body.SetAwake(true);
|
||||
|
||||
var vector = new Box2D.Common.Math.b2Vec2(
|
||||
options.x * Settings.MAX_THROW_FORCE / this.options.weight + carrierVelocity.x,
|
||||
-options.y * Settings.MAX_THROW_FORCE / this.options.weight + carrierVelocity.y
|
||||
);
|
||||
|
||||
var x = options.x * Settings.MAX_THROW_FORCE / this.options.weight + carrierVelocity.x;
|
||||
var y = -options.y * Settings.MAX_THROW_FORCE / this.options.weight + carrierVelocity.y;
|
||||
var vector = new Box2D.Common.Math.b2Vec2(x, y);
|
||||
body.SetLinearVelocity(vector);
|
||||
body.SetAngularVelocity(-options.av * Settings.MAX_THROW_ANGULAR_VELOCITY);
|
||||
|
||||
var av = -options.av * Settings.MAX_THROW_ANGULAR_VELOCITY;
|
||||
body.SetAngularVelocity(av);
|
||||
};
|
||||
|
||||
Item.prototype.destroy = function() {
|
||||
Nc.trigger(Nc.ns.core.game.gameObject.remove, 'animated', this);
|
||||
Nc.trigger(Nc.ns.core.game.gameObject.remove, "animated", this);
|
||||
Parent.prototype.destroy.call(this);
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -2,10 +2,13 @@ define([
|
|||
"Game/" + GLOBALS.context + "/GameObjects/Item",
|
||||
"Lib/Vendor/Box2D",
|
||||
"Game/Config/Settings",
|
||||
"Lib/Utilities/NotificationCenter"
|
||||
"Lib/Utilities/NotificationCenter",
|
||||
"Lib/Utilities/Assert",
|
||||
"Lib/Utilities/Options",
|
||||
"Game/Config/ItemSettings",
|
||||
],
|
||||
|
||||
function (Parent, Box2D, Settings, Nc) {
|
||||
function (Parent, Box2D, Settings, Nc, Assert, Options, ItemSettings) {
|
||||
|
||||
"use strict";
|
||||
|
||||
|
|
@ -92,10 +95,9 @@ function (Parent, Box2D, Settings, Nc) {
|
|||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// FIXME
|
||||
var ragdollOptions = Options.merge(ItemSettings.RagDoll, ItemSettings.Default);
|
||||
options = Options.merge(options, ragdollOptions);
|
||||
Parent.call(this, physicsEngine, uid, options);
|
||||
//this.createSensor();
|
||||
|
||||
|
|
@ -187,6 +189,8 @@ function (Parent, Box2D, Settings, Nc) {
|
|||
};
|
||||
|
||||
RagDoll.prototype.getFixtureDef = function() {
|
||||
Assert.number(this.options.limbs.chest.width, this.options.limbs.chest.height);
|
||||
|
||||
var fixtureDef = Parent.prototype.getFixtureDef.call(this);
|
||||
fixtureDef.density = Settings.PLAYER_DENSITY;
|
||||
fixtureDef.friction = Settings.PLAYER_FRICTION;
|
||||
|
|
@ -206,6 +210,8 @@ function (Parent, Box2D, Settings, Nc) {
|
|||
};
|
||||
|
||||
RagDoll.prototype.createSensor = function() {
|
||||
Assert.number(this.options.width, this.options.height);
|
||||
|
||||
var w = this.options.width / Settings.RATIO;
|
||||
var h = this.options.height / Settings.RATIO;
|
||||
|
||||
|
|
@ -218,12 +224,16 @@ function (Parent, Box2D, Settings, Nc) {
|
|||
|
||||
fixtureDef.userData = {
|
||||
onCollisionChange: this.onCollisionChange.bind(this)
|
||||
}
|
||||
};
|
||||
|
||||
this.body.CreateFixture(fixtureDef);
|
||||
};
|
||||
|
||||
RagDoll.prototype.addHead = function() {
|
||||
Assert.number(this.options.x, this.options.y);
|
||||
Assert.number(this.options.limbs.head.x, this.options.limbs.head.y);
|
||||
Assert.number(this.options.limbs.head.width);
|
||||
|
||||
var x = this.options.x + this.options.limbs.head.x,
|
||||
y = this.options.y + this.options.limbs.head.y;
|
||||
|
||||
|
|
@ -270,6 +280,11 @@ function (Parent, Box2D, Settings, Nc) {
|
|||
};
|
||||
|
||||
RagDoll.prototype.addLimb = function(name, connectTo, xOffset, yOffset) {
|
||||
Assert.number(xOffset, yOffset);
|
||||
Assert.number(this.options.x, this.options.y);
|
||||
Assert.number(this.options.limbs[name].x, this.options.limbs[name].y);
|
||||
Assert.number(this.options.limbs[name].width, this.options.limbs[name].height);
|
||||
|
||||
var x = this.options.x + this.options.limbs[name].x,
|
||||
y = this.options.y + this.options.limbs[name].y;
|
||||
|
||||
|
|
@ -322,6 +337,10 @@ function (Parent, Box2D, Settings, Nc) {
|
|||
};
|
||||
|
||||
RagDoll.prototype.reposition = function(handPosition, direction) {
|
||||
Assert.number(this.options.limbs.head.x, this.options.limbs.head.y);
|
||||
Assert.number(this.options.grabAngle);
|
||||
Assert.number(direction);
|
||||
|
||||
Parent.prototype.reposition.call(this, handPosition, direction);
|
||||
|
||||
var chestPosition = this.body.GetPosition();
|
||||
|
|
@ -329,7 +348,7 @@ function (Parent, Box2D, Settings, Nc) {
|
|||
var position = new Box2D.Common.Math.b2Vec2(
|
||||
chestPosition.x + this.options.limbs.head.x / Settings.RATIO,
|
||||
chestPosition.y + this.options.limbs.head.y / Settings.RATIO
|
||||
)
|
||||
);
|
||||
this.limbs.head.SetPosition(position);
|
||||
this.limbs.head.SetAngle((this.options.grabAngle || 0) * direction);
|
||||
};
|
||||
|
|
@ -345,6 +364,9 @@ function (Parent, Box2D, Settings, Nc) {
|
|||
};
|
||||
|
||||
RagDoll.prototype.setVelocities = function(options) {
|
||||
Assert.number(options.linearVelocity.x, options.linearVelocity.y);
|
||||
Assert.number(options.angularVelocity);
|
||||
|
||||
this.body.SetLinearVelocity(options.linearVelocity);
|
||||
this.body.SetAngularVelocity(options.angularVelocity);
|
||||
for(var name in this.limbs) {
|
||||
|
|
@ -354,7 +376,7 @@ function (Parent, Box2D, Settings, Nc) {
|
|||
|
||||
RagDoll.prototype.destroy = function() {
|
||||
|
||||
Nc.trigger(Nc.ns.core.game.gameObject.remove, 'animated', this);
|
||||
Nc.trigger(Nc.ns.core.game.gameObject.remove, "animated", this);
|
||||
var world = this.body.GetWorld();
|
||||
|
||||
for (var name in this.limbs) {
|
||||
|
|
|
|||
|
|
@ -2,10 +2,11 @@ define([
|
|||
"Game/" + GLOBALS.context + "/GameObjects/Item",
|
||||
"Lib/Vendor/RubeLoader",
|
||||
"Lib/Vendor/Box2D",
|
||||
"Game/Config/Settings"
|
||||
"Game/Config/Settings",
|
||||
"Lib/Utilities/Assert"
|
||||
],
|
||||
|
||||
function (Parent, RubeLoader, Box2D, Settings ) {
|
||||
function (Parent, RubeLoader, Box2D, Settings, Assert) {
|
||||
|
||||
"use strict";
|
||||
|
||||
|
|
@ -13,6 +14,7 @@ function (Parent, RubeLoader, Box2D, Settings ) {
|
|||
var __ragdollJson;
|
||||
|
||||
function Rube(physicsEngine, uid, options) {
|
||||
Assert.number(options.x, options.y);
|
||||
|
||||
this.rubeLoader = null;
|
||||
this.body = null;
|
||||
|
|
@ -1398,7 +1400,7 @@ function (Parent, RubeLoader, Box2D, Settings ) {
|
|||
"subStepping" : false,
|
||||
"velocityIterations" : 8,
|
||||
"warmStarting" : true
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -1,10 +1,11 @@
|
|||
define([
|
||||
"Game/" + GLOBALS.context + "/GameObjects/Item",
|
||||
"Lib/Vendor/Box2D",
|
||||
"Game/Config/Settings"
|
||||
"Game/Config/Settings",
|
||||
"Lib/Utilities/Assert"
|
||||
],
|
||||
|
||||
function (Parent, Box2D, Settings) {
|
||||
function (Parent, Box2D, Settings, Assert) {
|
||||
|
||||
"use strict";
|
||||
|
||||
|
|
@ -27,6 +28,8 @@ function (Parent, Box2D, Settings) {
|
|||
Skateboard.prototype = Object.create(Parent.prototype);
|
||||
|
||||
Skateboard.prototype.createFixture = function () {
|
||||
Assert.number(this.options.width, this.options.height);
|
||||
Assert.number(this.options.weight);
|
||||
|
||||
var deckShape = new Box2D.Collision.Shapes.b2PolygonShape();
|
||||
var w = this.options.width / Settings.RATIO;
|
||||
|
|
@ -45,10 +48,12 @@ function (Parent, Box2D, Settings) {
|
|||
fixtureDef.isSensor = false;
|
||||
|
||||
this.body.CreateFixture(fixtureDef);
|
||||
}
|
||||
};
|
||||
|
||||
Skateboard.prototype.addWheel = function(x, y) {
|
||||
|
||||
Assert.number(x, y);
|
||||
|
||||
var bodyDef = new Box2D.Dynamics.b2BodyDef();
|
||||
bodyDef.type = Box2D.Dynamics.b2Body.b2_dynamicBody;
|
||||
bodyDef.position.x = x / Settings.RATIO;
|
||||
|
|
|
|||
|
|
@ -3,10 +3,11 @@ define([
|
|||
"Lib/Vendor/Box2D",
|
||||
"Game/Config/Settings",
|
||||
"Lib/Utilities/Exception",
|
||||
"Lib/Utilities/NotificationCenter"
|
||||
"Lib/Utilities/NotificationCenter",
|
||||
"Lib/Utilities/Assert"
|
||||
],
|
||||
|
||||
function (Parent, Box2D, Settings, Exception, Nc) {
|
||||
function (Parent, Box2D, Settings, Exception, Nc, Assert) {
|
||||
|
||||
"use strict";
|
||||
|
||||
|
|
@ -15,12 +16,14 @@ function (Parent, Box2D, Settings, Exception, Nc) {
|
|||
Parent.call(this, physicsEngine, uid);
|
||||
this.createPhysicTile(this.options);
|
||||
|
||||
Nc.trigger(Nc.ns.core.game.gameObject.add, 'fixed', this);
|
||||
Nc.trigger(Nc.ns.core.game.gameObject.add, "fixed", this);
|
||||
}
|
||||
|
||||
Tile.prototype = Object.create(Parent.prototype);
|
||||
|
||||
Tile.prototype.getBodyDef = function() {
|
||||
Assert.number(this.options.x, this.options.y);
|
||||
Assert.number(this.options.r);
|
||||
|
||||
var bodyDef = new Box2D.Dynamics.b2BodyDef();
|
||||
bodyDef.type = Box2D.Dynamics.b2Body.b2_staticBody;
|
||||
|
|
@ -29,7 +32,7 @@ function (Parent, Box2D, Settings, Exception, Nc) {
|
|||
bodyDef.angle = (this.options.r || 0) * 90 * Math.PI / 180;
|
||||
|
||||
return bodyDef;
|
||||
}
|
||||
};
|
||||
|
||||
Tile.prototype.createPhysicTile = function (tile) {
|
||||
var vertices = this.createVertices(tile);
|
||||
|
|
@ -43,7 +46,7 @@ function (Parent, Box2D, Settings, Exception, Nc) {
|
|||
fixtureDef.restitution = Settings.TILE_RESTITUTION;
|
||||
fixtureDef.isSensor = false;
|
||||
this.body.CreateFixture(fixtureDef);
|
||||
}
|
||||
};
|
||||
|
||||
Tile.prototype.createVertices = function (tile) {
|
||||
var vs = [];
|
||||
|
|
@ -104,22 +107,21 @@ function (Parent, Box2D, Settings, Exception, Nc) {
|
|||
|
||||
default:
|
||||
throw new Exception("Tile Creation - no shape given");
|
||||
break;
|
||||
}
|
||||
|
||||
return vs;
|
||||
}
|
||||
};
|
||||
|
||||
Tile.prototype.mkArg = function (multiplier) {
|
||||
return Settings.TILE_SIZE / 2 / Settings.RATIO * multiplier;
|
||||
}
|
||||
};
|
||||
|
||||
Tile.prototype.addVec = function (vs, m1, m2) {
|
||||
return vs.push(new Box2D.Common.Math.b2Vec2(this.mkArg(m1), this.mkArg(m2)));
|
||||
}
|
||||
};
|
||||
|
||||
Tile.prototype.destroy = function() {
|
||||
Nc.trigger(Nc.ns.core.game.gameObject.remove, 'fixed', this);
|
||||
Nc.trigger(Nc.ns.core.game.gameObject.remove, "fixed", this);
|
||||
};
|
||||
|
||||
return Tile;
|
||||
|
|
|
|||
|
|
@ -12,6 +12,8 @@ define([
|
|||
|
||||
], function (Settings, Box2D, Nc, Abstract, CollisionDetector, Tile, Item, Skateboard, RagDoll, Rube) {
|
||||
|
||||
"use strict";
|
||||
|
||||
function Level (uid, engine) {
|
||||
this.uid = uid;
|
||||
this.engine = engine;
|
||||
|
|
|
|||
|
|
@ -14,6 +14,8 @@ define([
|
|||
|
||||
], function (Parent, Settings, ItemSettings, Box2D, Options, Exception, Nc, AbstractLayer, CollisionDetector, Tile, Item, Skateboard) {
|
||||
|
||||
"use strict";
|
||||
|
||||
function TiledLevel (path, engine) {
|
||||
|
||||
this.layerMapping = {
|
||||
|
|
@ -109,7 +111,7 @@ define([
|
|||
}
|
||||
|
||||
lastLayerId = layerOptions.layerId;
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
Parent.prototype.setup.call(this, levelData);
|
||||
|
|
@ -137,21 +139,21 @@ define([
|
|||
t: imagePath,
|
||||
x: i % options.width,
|
||||
y: parseInt(i / options.width , 10)
|
||||
}
|
||||
};
|
||||
|
||||
tilesOptions.push(tileOptions);
|
||||
}
|
||||
|
||||
Parent.prototype.createTiles.call(this, tilesOptions);
|
||||
}
|
||||
};
|
||||
|
||||
TiledLevel.prototype.createItems = function(options) {
|
||||
var objects = options.objects;
|
||||
var itemsOptions = []
|
||||
var itemsOptions = [];
|
||||
for (var i = 0; i < objects.length; i++) {
|
||||
var options = this.gatherOptions(objects[i]);
|
||||
options = this.gatherOptions(objects[i]);
|
||||
itemsOptions.push(options);
|
||||
};
|
||||
}
|
||||
|
||||
Parent.prototype.createItems.call(this, itemsOptions);
|
||||
};
|
||||
|
|
@ -188,18 +190,14 @@ define([
|
|||
TiledLevel.prototype.getDefaultItemSettingsByName = function(name) {
|
||||
|
||||
if(!name) {
|
||||
throw new Exception('Item name cannot be be empty');
|
||||
throw new Exception("Item name cannot be be empty");
|
||||
}
|
||||
|
||||
if(ItemSettings[name] === undefined) {
|
||||
throw new Exception('Item name (' + name + ') cannot be found in item list');
|
||||
throw new Exception("Item name (" + name + ") cannot be found in item list");
|
||||
}
|
||||
|
||||
var options = ItemSettings.Default;
|
||||
|
||||
options = Options.merge(ItemSettings[name], options);
|
||||
|
||||
return options;
|
||||
return Options.merge(ItemSettings[name], ItemSettings.Default);
|
||||
};
|
||||
|
||||
TiledLevel.prototype.getTileImagePath = function(gid) {
|
||||
|
|
@ -210,7 +208,7 @@ define([
|
|||
return tileset.tiles["" + (gid - offset)].image;
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
return TiledLevel;
|
||||
});
|
||||
Loading…
Add table
Add a link
Reference in a new issue