added ASSERT, fixed #103

This commit is contained in:
Jeena 2015-03-15 16:51:38 +01:00
parent 55eff36f34
commit dfa71bc8e5
17 changed files with 249 additions and 153 deletions

View file

@ -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) {

View file

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

View file

@ -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;