fixed debug view and ragdoll start positioning

This commit is contained in:
Jeena 2015-03-16 01:50:41 +01:00
parent b6d979fe7c
commit 16826b174a
12 changed files with 135 additions and 73 deletions

View file

@ -102,10 +102,10 @@ function (Parent, Box2D, Settings, Nc, Assert, Options, ItemSettings) {
//this.createSensor();
this.limbs = {};
this.addHead();
this.addLimb(
"upperLeftLeg",
this.body,
@ -137,7 +137,6 @@ function (Parent, Box2D, Settings, Nc, Assert, Options, ItemSettings) {
this.addLimb(
"upperLeftArm",
this.body,
@ -165,6 +164,7 @@ function (Parent, Box2D, Settings, Nc, Assert, Options, ItemSettings) {
0,
options.limbs.upperRightArm.height / 2
);
}
RagDoll.prototype = Object.create(Parent.prototype);
@ -185,6 +185,8 @@ function (Parent, Box2D, Settings, Nc, Assert, Options, ItemSettings) {
var bodyDef = Parent.prototype.getBodyDef.call(this);
bodyDef.linearDamping = Settings.PLAYER_LINEAR_DAMPING;
bodyDef.type = Box2D.Dynamics.b2Body.b2_dynamicBody;
bodyDef.position.y -= this.options.height / 2 / Settings.RATIO; // position it on top of ground
return bodyDef;
};
@ -235,7 +237,7 @@ function (Parent, Box2D, Settings, Nc, Assert, Options, ItemSettings) {
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;
y = this.options.y + this.options.limbs.head.y - this.options.height / 2; // position it on top of ground;
var bodyDef = new Box2D.Dynamics.b2BodyDef();
bodyDef.type = Box2D.Dynamics.b2Body.b2_dynamicBody;
@ -286,7 +288,7 @@ function (Parent, Box2D, Settings, Nc, Assert, Options, ItemSettings) {
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;
y = this.options.y + this.options.limbs[name].y - this.options.height / 2; // position it on top of ground;;
var bodyDef = new Box2D.Dynamics.b2BodyDef();
bodyDef.linearDamping = Settings.PLAYER_LINEAR_DAMPING;

View file

@ -51,7 +51,6 @@ function (Parent, Box2D, Settings, Assert) {
};
Skateboard.prototype.addWheel = function(x, y) {
Assert.number(x, y);
var bodyDef = new Box2D.Dynamics.b2BodyDef();
@ -71,15 +70,20 @@ function (Parent, Box2D, Settings, Assert) {
fixtureDef.density = density;
fixtureDef.shape = wheelShape;
fixtureDef.isSensor = false;
fixtureDef.friction = 0;
var wheelBody = this.body.GetWorld().CreateBody(bodyDef);
wheelBody.CreateFixture(fixtureDef);
var revoluteJointDef = new Box2D.Dynamics.Joints.b2RevoluteJointDef();
revoluteJointDef.enableMotor = false;
//var revoluteJointDef = new Box2D.Dynamics.Joints.b2RevoluteJointDef();
var revoluteJointDef = new Box2D.Dynamics.Joints.b2WeldJointDef();
//revoluteJointDef.enableMotor = false;
revoluteJointDef.Initialize(this.body, wheelBody, wheelBody.GetWorldCenter());
this.body.GetWorld().CreateJoint(revoluteJointDef);
var j = this.body.GetWorld().CreateJoint(revoluteJointDef);
// FIXME this means, that we will have bodies in the world, which must not be
// updated (wheels) because they are always connected to a body which will be updated.

View file

@ -25,13 +25,13 @@ define([
Level.prototype.load = function (uid) {
var self = this;
var path = Settings.MAPS_PATH + uid + ".json"
var path = Settings.MAPS_PATH + uid + ".json";
this.loadLevelDataFromPath(path, function (levelData) {
self.setup(levelData);
});
}
};
Level.prototype.setup = function(levelData) {
Level.prototype.setup = function(levelData) { // jshint unused:false
this.isLoaded = true;
Nc.trigger(Nc.ns.core.game.events.level.loaded);
};
@ -40,17 +40,17 @@ define([
for (var i = 0; i < options.length; i++) {
var uid = "item-" + i;
this.createItem(uid, options[i]);
};
}
};
Level.prototype.createItem = function(uid, options) {
switch(options.type) {
//case 'skateboard':
//case "skateboard":
// return new Skateboard(this.engine, uid, options);
case 'ragdoll':
case "ragdoll":
return new RagDoll(this.engine, uid, options);
case 'rube':
case "rube":
return new Rube(this.engine, uid, options);
default:
return new Item(this.engine, uid, options);
@ -60,19 +60,19 @@ define([
Level.prototype.createTiles = function(options) {
for (var i = 0; i < options.length; i++) {
new Tile(this.engine, "tile-" + i, options[i]);
};
}
};
Level.prototype.createSpawnPoints = function(points) {
this.spawnPoints = points;
};
Level.prototype.setupLayer = function(options, behind, referenceId) {
Level.prototype.setupLayer = function(options, behind, referenceId) { // jshint unused:false
// will be extended (so far only in client)
}
};
Level.prototype.createContainer = function(options) {
Level.prototype.createContainer = function(options) { // jshint unused:false
// nothing to do here yet, in the future perhaps synchronize day/night graphics
};
@ -90,12 +90,12 @@ define([
return {
x: object.x / Settings.TILE_RATIO,
y: object.y / Settings.TILE_RATIO
}
};
};
Level.prototype.destroy = function () {
this.isLoaded = false;
}
};
return Level;
});

View file

@ -6,13 +6,14 @@ define([
"Lib/Utilities/Options",
"Lib/Utilities/Exception",
"Lib/Utilities/NotificationCenter",
"Lib/Utilities/Assert",
"Game/Client/View/Abstract/Layer",
"Game/" + GLOBALS.context + "/Collision/Detector",
"Game/" + GLOBALS.context + "/GameObjects/Tile",
"Game/" + GLOBALS.context + "/GameObjects/Item",
"Game/" + GLOBALS.context + "/GameObjects/Items/Skateboard",
], function (Parent, Settings, ItemSettings, Box2D, Options, Exception, Nc, AbstractLayer, CollisionDetector, Tile, Item, Skateboard) {
], function (Parent, Settings, ItemSettings, Box2D, Options, Exception, Nc, Assert, AbstractLayer, CollisionDetector, Tile, Item, Skateboard) {
"use strict";
@ -40,7 +41,7 @@ define([
});
if (!spawnpointsExists) {
console.warn('No layerMapping for level file layer: ' + layerOptions.name);
console.warn("No layerMapping for level file layer: " + layerOptions.name);
return;
}
@ -49,7 +50,7 @@ define([
tiles: AbstractLayer.ID.TILE,
items: AbstractLayer.ID.ITEM,
spawnpoints: AbstractLayer.ID.SPAWN
}
};
if(mapping[name]) {
return mapping[name];
}
@ -167,26 +168,15 @@ define([
};
TiledLevel.prototype.gatherOptions = function(tiledObject) {
var options = {};
var options = this.getDefaultItemSettingsByName(tiledObject.name);
options.name = tiledObject.name;
options.rotation = tiledObject.rotation;
options.width = tiledObject.width / Settings.TILE_RATIO;
options.height = tiledObject.height / Settings.TILE_RATIO;
options.x = (tiledObject.x + tiledObject.width / 2) / Settings.TILE_RATIO;
options.x = (tiledObject.x + options.width / 2) / Settings.TILE_RATIO;
options.y = (tiledObject.y + options.height / 2) / Settings.TILE_RATIO;
if (!options.width) options.width = undefined;
if (!options.height) options.height = undefined;
var defaultOptions = this.getDefaultItemSettingsByName(options.name);
options = Options.merge(options, defaultOptions);
// FIXME: check RAD vs. DEG for options.rotation = tiledObject.rotation;
return options;
};
TiledLevel.prototype.getDefaultItemSettingsByName = function(name) {
if(!name) {