This commit is contained in:
Jeena 2014-02-18 13:15:46 +01:00
commit 0405910c7a
49 changed files with 32827 additions and 126 deletions

View file

@ -25,6 +25,7 @@ function (Parent, KeyboardInput, MouseInput, NotificationCenter) {
f:70,
g:71,
k:75,
up: 38,
left: 37,
@ -49,14 +50,16 @@ function (Parent, KeyboardInput, MouseInput, NotificationCenter) {
this.keyboardInput.registerKey(keys.d, 'moveRight', 'stop');
this.keyboardInput.registerKey(keys.right, 'moveRight', 'stop');
this.keyboardInput.registerKey(keys.w, 'jump');
this.keyboardInput.registerKey(keys.up, 'jump');
this.keyboardInput.registerKey(keys.space, 'jump');
this.keyboardInput.registerKey(keys.w, 'jump', 'jumpStop');
this.keyboardInput.registerKey(keys.up, 'jump', 'jumpStop');
this.keyboardInput.registerKey(keys.space, 'jump', 'jumpStop');
this.keyboardInput.registerKey(keys.tab, 'showInfo', 'hideInfo');
this.keyboardInput.registerKey(keys.f, 'handActionLeft');
this.keyboardInput.registerKey(keys.g, 'handActionRight');
this.keyboardInput.registerKey(keys.k, 'suicide');
}
PlayerController.prototype.moveLeft = function () {
@ -79,6 +82,11 @@ function (Parent, KeyboardInput, MouseInput, NotificationCenter) {
NotificationCenter.trigger('sendGameCommand', 'jump');
}
PlayerController.prototype.jumpStop = function () {
Parent.prototype.jumpStop.call(this);
NotificationCenter.trigger('sendGameCommand', 'jumpStop');
}
PlayerController.prototype.setXY = function(x, y) {
var options = {x:x, y:y};
Parent.prototype.lookAt.call(this, options);
@ -93,6 +101,10 @@ function (Parent, KeyboardInput, MouseInput, NotificationCenter) {
this.handActionRequest(0.5, 0.5);
};
PlayerController.prototype.suicide = function() {
NotificationCenter.trigger("sendGameCommand", "suicide");
};
PlayerController.prototype.handActionRequest = function(x, y) {
var options = {x:x, y:y};
NotificationCenter.trigger("sendGameCommand", "handActionRequest", options);

View file

@ -25,7 +25,6 @@ function (Parent, Box2D, PhysicsEngine, ViewManager, PlayerController, Notificat
GameController.prototype = Object.create(Parent.prototype);
GameController.prototype.destruct = function() {
//destroy box2d world etc.
};
@ -35,6 +34,9 @@ function (Parent, Box2D, PhysicsEngine, ViewManager, PlayerController, Notificat
}
GameController.prototype.update = function () {
Parent.prototype.update.call(this);
DomController.statsBegin();
requestAnimFrame(this.update.bind(this));
@ -111,7 +113,7 @@ function (Parent, Box2D, PhysicsEngine, ViewManager, PlayerController, Notificat
var player = this.players[playerId];
player.spawn(x, y);
this.gameObjects.animated.push(player.getDoll());
this.gameObjects.animated.push(player);
if(options.holdingItemUid) {
this.onHandActionResponse({
@ -148,7 +150,7 @@ function (Parent, Box2D, PhysicsEngine, ViewManager, PlayerController, Notificat
GameController.prototype.onUpdateStats = function(options) {
var player = this.players[options.playerId];
player.stats = options.stats;
player.setStats(options.stats);
// FIXME: move to canvas later
if(player == this.me) {
@ -156,23 +158,32 @@ function (Parent, Box2D, PhysicsEngine, ViewManager, PlayerController, Notificat
}
};
GameController.prototype.onPlayerKill = function(playerId) {
GameController.prototype.onPlayerKill = function(options) {
var player = this.players[options.playerId];
player.kill();
var killedByPlayer = this.players[options.killedByPlayerId];
player.kill(killedByPlayer);
};
GameController.prototype.onRemoveGameObject = function(options) {
var object = null;
for (var i = 0; i < this.gameObjects[options.type].length; i++) {
if(this.gameObjects[options.type][i].uid == options.uid) {
object = this.gameObjects[options.type][i];
break;
}
}
if(object) {
this.onGameObjectRemove(options.type, object);
object.destroy();
} else {
console.warn("GameObject for removal can not be found locally. " + options.uid);
}
};
GameController.prototype.loadLevel = function (path) {
Parent.prototype.loadLevel.call(this, path);
}
GameController.prototype.userLeft = function(user) {
var doll = this.players[user.id].doll;
var i = this.gameObjects.animated.indexOf(doll);
if(i>=0) this.gameObjects.animated.splice(i, 1);
Parent.prototype.userLeft.call(this, user);
}
GameController.prototype.toggleInfo = function(show) {
var playersArray = [];

View file

@ -31,7 +31,6 @@ function (Parent, CoreItem, Settings, NotificationCenter) {
+ this.characterName + '/';
var callback = function(mesh) {
console.log(name, self.baseMeshName)
if(name == self.baseMeshName) {
self.mesh = mesh;
} else {
@ -97,8 +96,14 @@ function (Parent, CoreItem, Settings, NotificationCenter) {
);
};
}
};
RagDoll.prototype.destroy = function() {
for (var name in this.limbMeshes) {
NotificationCenter.trigger("view/removeMesh", this.limbMeshes[name]);
};
Parent.prototype.destroy.call(this);
};
return RagDoll;

View file

@ -0,0 +1,21 @@
define([
"Game/Core/GameObjects/SpectatorDoll"
],
function (Parent) {
function SpectatorDoll(physicsEngine, uid) {
Parent.call(this, physicsEngine, uid);
}
SpectatorDoll.prototype = Object.create(Parent.prototype);
SpectatorDoll.prototype.render = function() {
// warning is not being called yet!
}
SpectatorDoll.prototype.createMesh = function() {
}
return SpectatorDoll;
});

View file

@ -1,9 +1,111 @@
define([
"Game/Core/Player"
"Game/Core/Player",
"Lib/Utilities/NotificationCenter",
"Game/Config/Settings"
],
function(Parent) {
function (Parent, NotificationCenter, Settings) {
return Parent;
function Player(id, physicsEngine) {
Parent.call(this, id, physicsEngine);
this.playerInfoView = null;
this.playerInfoViewVisibleTimeout = null;
this.playerInfoViewVisible = false;
this.initHealthBar();
}
Player.prototype = Object.create(Parent.prototype);
Player.prototype.setStats = function(stats) {
var oldHealth = this.stats.health;
this.stats = stats;
if(oldHealth != this.stats.health) {
this.onHealthChange();
}
}
Player.prototype.initHealthBar = function() {
var self = this;
this.playerInfoViewVisible = false;
var options = {
x: 100,
y: 100,
healthFactor: this.stats.health / 100,
visible: this.playerInfoViewVisible
};
var callback = function(playerInfoView) {
self.playerInfoView = playerInfoView;
}
NotificationCenter.trigger("view/createAndAddPlayerInfo", callback, options);
};
Player.prototype.onHealthChange = function() {
if(this.stats.health != 100) {
this.setPlayerInfoVisible(true);
}
};
Player.prototype.kill = function(killedByPlayer) {
Parent.prototype.kill.call(this, killedByPlayer);
};
Player.prototype.spawn = function(x, y) {
Parent.prototype.spawn.call(this, x, y);
this.setPlayerInfoVisible(false);
};
Player.prototype.setPlayerInfoVisible = function(visible) {
var self = this;
this.playerInfoViewVisible = visible;
if(this.playerInfoViewVisibleTimeout) clearTimeout(this.playerInfoViewVisibleTimeout);
if(visible) {
var position = this.getPosition();
var options = {
x: position.x * Settings.RATIO,
y: position.y * Settings.RATIO,
healthFactor: this.stats.health / 100,
visible: this.playerInfoViewVisible
};
NotificationCenter.trigger("view/updatePlayerInfo", this.playerInfoView, options);
this.playerInfoViewVisibleTimeout = setTimeout(function() {
self.playerInfoViewVisible = false;
NotificationCenter.trigger("view/updatePlayerInfo", self.playerInfoView, {visible: self.playerInfoViewVisible});
}, Settings.HEALTH_DISPLAY_TIME * 1000);
} else {
NotificationCenter.trigger("view/updatePlayerInfo", this.playerInfoView, {visible: this.playerInfoViewVisible});
}
};
Player.prototype.render = function() {
// dolls are self responsible
if(this.playerInfoViewVisible) {
var position = this.getPosition();
var options = {
healthFactor: this.stats.health / 100,
x: position.x * Settings.RATIO,
y: position.y * Settings.RATIO,
}
NotificationCenter.trigger("view/updatePlayerInfo", this.playerInfoView, options);
}
};
Player.prototype.destroy = function() {
Parent.prototype.destroy.call(this);
NotificationCenter.trigger("view/removePlayerInfo", this.playerInfoView);
};
return Player;
});

View file

@ -22,6 +22,10 @@ function (DomController, Settings, Exception, NotificationCenter) {
NotificationCenter.on("view/toggleDebugMode", this.onToggleDebugMode, this);
NotificationCenter.on("view/toggleInfo", this.onToggleInfo, this);
NotificationCenter.on("view/createAndAddPlayerInfo", this.onCreateAndAddPlayerInfo, this);
NotificationCenter.on("view/updatePlayerInfo", this.onUpdatePlayerInfo, this);
NotificationCenter.on("view/removePlayerInfo", this.onRemovePlayerInfo, this);
}
AbstractView.prototype.isWebGlEnabled = function () {
@ -131,5 +135,17 @@ function (DomController, Settings, Exception, NotificationCenter) {
throw new Exception('Abstract Function showInfo not overwritten');
};
AbstractView.prototype.onCreateAndAddPlayerInfo = function(options) {
throw new Exception('Abstract Function onCreateAndAddPlayerInfo not overwritten');
};
AbstractView.prototype.onUpdatePlayerInfo = function(playerInfo, options) {
throw new Exception('Abstract Function onUpdatePlayerInfo not overwritten');
};
AbstractView.prototype.onRemovePlayerInfo = function(playerInfo) {
throw new Exception('Abstract Function onRemovePlayerInfo not overwritten');
};
return AbstractView;
});

View file

@ -32,7 +32,7 @@ function (Parent, DomController, PIXI, Settings, NotificationCenter) {
console.log('WebGLRenderer')
} else {
this.renderer = new PIXI.CanvasRenderer(Settings.STAGE_WIDTH, Settings.STAGE_HEIGHT);
console.log('CanvasRenderer')
console.log('CanvasRenderer - not using WebGL!')
}
this.stage = new PIXI.Stage(0x333333);
@ -43,35 +43,8 @@ function (Parent, DomController, PIXI, Settings, NotificationCenter) {
this.setCanvas(this.renderer.view);
}
PixiView.prototype.initCamera = function () {
this.container = new PIXI.DisplayObjectContainer();
this.stage.addChild(this.container);
}
PixiView.prototype.initInfo = function() {
this.infoContainer = new PIXI.DisplayObjectContainer();
this.stage.addChild(this.infoContainer);
var blurFilter = new PIXI.BlurFilter();
blurFilter.blurX = 12;
blurFilter.blurY = 12;
var grayFilter = new PIXI.GrayFilter();
grayFilter.gray = 0.85;
this.infoFilters = [blurFilter, grayFilter];
this.infoText = new PIXI.Text("", {font: "normal 20px monospace", fill: "red", align: "center"});
this.infoBox = new PIXI.Graphics();
this.infoBox.alpha = 0.7;
this.infoContainer.addChild(this.infoBox);
this.infoContainer.addChild(this.infoText);
this.infoContainer.visible = false;
};
PixiView.prototype.render = function () {
if(this.me && this.me.isSpawned) {
if(this.me) {
var pos = this.calculateCameraPosition();
this.setCameraPosition(pos.x, pos.y);
}
@ -79,6 +52,8 @@ function (Parent, DomController, PIXI, Settings, NotificationCenter) {
this.renderer.render(this.stage);
}
// Meshes
PixiView.prototype.addMesh = function(mesh) {
this.container.addChild(mesh);
};
@ -89,9 +64,10 @@ function (Parent, DomController, PIXI, Settings, NotificationCenter) {
PixiView.prototype.createMesh = function (texturePath, callback, options) {
var texture = PIXI.Texture.fromImage(texturePath);
var texture = PIXI.Texture.fromImage(texturePath, false, PIXI.BaseTexture.SCALE_MODE.NEAREST);
var mesh = new PIXI.Sprite(texture);
if(options) this.updateMesh(mesh, options);
callback(mesh);
@ -129,6 +105,13 @@ function (Parent, DomController, PIXI, Settings, NotificationCenter) {
if (options.pivot) mesh.pivot = new PIXI.Point(options.pivot.x, options.pivot.y);
}
// Camera
PixiView.prototype.initCamera = function () {
this.container = new PIXI.DisplayObjectContainer();
this.stage.addChild(this.container);
}
PixiView.prototype.calculateCameraPosition = function() {
var zoom = this.container.scale.x;
@ -167,6 +150,29 @@ function (Parent, DomController, PIXI, Settings, NotificationCenter) {
}
};
// Info Overlay
PixiView.prototype.initInfo = function() {
this.infoContainer = new PIXI.DisplayObjectContainer();
this.stage.addChild(this.infoContainer);
var blurFilter = new PIXI.BlurFilter();
blurFilter.blurX = 12;
blurFilter.blurY = 12;
var grayFilter = new PIXI.GrayFilter();
grayFilter.gray = 0.85;
this.infoFilters = [blurFilter, grayFilter];
this.infoText = new PIXI.Text("", {font: "normal 20px monospace", fill: "red", align: "center"});
this.infoBox = new PIXI.Graphics();
this.infoBox.alpha = 0.7;
this.infoContainer.addChild(this.infoBox);
this.infoContainer.addChild(this.infoText);
this.infoContainer.visible = false;
};
PixiView.prototype.toggleInfo = function(show, string) {
if(show) {
this.infoText.setText(string);
@ -197,5 +203,47 @@ function (Parent, DomController, PIXI, Settings, NotificationCenter) {
}
};
// Player Info
PixiView.prototype.onCreateAndAddPlayerInfo = function(callback, options) {
var playerInfo = new PIXI.Graphics();
this.container.addChild(playerInfo);
this.onUpdatePlayerInfo(playerInfo, options);
callback(playerInfo);
};
PixiView.prototype.onUpdatePlayerInfo = function(playerInfo, options) {
var width = 14,
height = 2,
borderWidth = 1,
offsetX = -8,
offsetY = -52;
if(typeof options.healthFactor != 'undefined') {
playerInfo.clear();
playerInfo.beginFill(0x000000);
playerInfo.lineStyle(borderWidth, 0x000000);
playerInfo.drawRect(0, 0, width, height);
playerInfo.endFill();
if(options.healthFactor > 0) {
playerInfo.beginFill(0x00FF00);
playerInfo.lineStyle(0, 0x000000);
playerInfo.drawRect(borderWidth, borderWidth, width * options.healthFactor, height);
playerInfo.endFill();
}
}
if (options.x && options.y) playerInfo.position = new PIXI.Point(offsetX + options.x, offsetY + options.y);
if (options.visible === true || options.visible === false) playerInfo.visible = options.visible;
};
PixiView.prototype.onRemovePlayerInfo = function(playerInfo) {
this.container.removeChild(playerInfo);
};
return PixiView;
});

View file

@ -18,7 +18,7 @@ define(function() {
GRAPHICS_SUBPATH_CHARACTERS: 'Characters/',
GRAPHICS_SUBPATH_TILES: 'Tiles/',
MAPS_PATH: 'static/maps/tiled/',
DEFAULT_LEVELS: ['debug', 'stones2'],
DEFAULT_LEVELS: ['stones2', 'debug'],
RATIO: 21, //35
// original tile size is 25 but we want it to resize to 20
@ -32,10 +32,13 @@ define(function() {
RUN_SPEED: 8,
FLY_SPEED: 6.2,
JUMP_SPEED: 20,
JUMP_STOP_DAMPING_FACTOR: 0.5,
MAX_THROW_FORCE: 18,
MAX_THROW_ANGULAR_VELOCITY: 0,
MAX_RUNNING_WEIGHT: 9,
RESPAWN_TIME: 0.5,
RESPAWN_TIME: 6,
HEALTH_DISPLAY_TIME: 2,
RAGDOLL_DESTRUCTION_TIME: 25,
// restitution: bouncyness, friction: rubbing, density: mass
TILE_FRICTION: 0.99,
@ -45,11 +48,12 @@ define(function() {
PLAYER_FRICTION: 5,
PLAYER_MOTION_FRICTION: 0.1,
PLAYER_RESTITUTION: 0.0,
PLAYER_LINEAR_DAMPING: 0.8,
PLAYER_LINEAR_DAMPING: 0.4,
ITEM_DENSITY: 0.9,
ITEM_FRICTION: 0.99,
ITEM_RESTITUTION: 0.02,
ITEM_LINEAR_DAMPING: 0.02,
// BROWSER
CANVAS_DOM_ID: 'canvasContainer',

View file

@ -29,6 +29,10 @@ define(function () {
this.player.jump();
}
PlayerController.prototype.jumpStop = function () {
this.player.jumpStop();
}
PlayerController.prototype.lookAt = function (options) {
if(options) this.player.lookAt(options.x, options.y);
}

View file

@ -10,19 +10,36 @@ function (PhysicsEngine, TiledLevel, Player, NotificationCenter) {
function GameController () {
this.players = {};
this.level = null;
this.gameObjects = {
animated: [],
fixed: []
};
this.gameObjects = null;
this.resetGameObjects();
this.physicsEngine = new PhysicsEngine();
this.physicsEngine.setCollisionDetector();
NotificationCenter.on("game/level/loaded", this.onLevelLoaded, this);
NotificationCenter.on("game/object/add", this.onGameObjectAdd, this);
NotificationCenter.on("game/object/remove", this.onGameObjectRemove, this);
}
GameController.prototype.update = function() {
// extend for both sides if necessary
};
GameController.prototype.resetGameObjects = function() {
this.gameObjects = {
fixed: [],
animated: []
};
};
GameController.prototype.onGameObjectAdd = function(type, object) {
this.gameObjects[type].push(object);
};
GameController.prototype.onGameObjectRemove = function(type, object) {
var i = this.gameObjects[type].indexOf(object);
if(i>=0) this.gameObjects[type].splice(i, 1);
};
GameController.prototype.getPhysicsEngine = function () {
@ -33,10 +50,7 @@ function (PhysicsEngine, TiledLevel, Player, NotificationCenter) {
if (this.level) {
this.level.destroy();
this.gameObjects = {
animated: [],
fixed: []
};
this.resetGameObjects();
}
this.level = new TiledLevel(levelUid, this.physicsEngine, this.gameObjects);
@ -63,6 +77,10 @@ function (PhysicsEngine, TiledLevel, Player, NotificationCenter) {
GameController.prototype.userLeft = function (user) {
var player = this.players[user.id];
var i = this.gameObjects.animated.indexOf(player);
if(i>=0) this.gameObjects.animated.splice(i, 1);
player.destroy();
delete this.players[user.id];
}

View file

@ -158,16 +158,8 @@ function (Parent, Box2D, Settings, CollisionDetector, Item) {
this.setActionState("fall");
}
Doll.prototype.kill = function() {
this.body.SetFixedRotation(false);
};
Doll.prototype.getPosition = function() {
var pos = this.body.GetPosition();
return {
x: pos.x,
y: pos.y
};
return this.body.GetPosition().Copy();
};
Doll.prototype.getHeadPosition = function() {
@ -235,7 +227,13 @@ function (Parent, Box2D, Settings, CollisionDetector, Item) {
Doll.prototype.stop = function () {
this.moveDirection = 0;
this.setFriction(Settings.PLAYER_FRICTION);
if(this.isStanding()) this.setActionState("stand");
if(this.isStanding()) {
this.setActionState("stand");
} else {
var vector = this.body.GetLinearVelocity().Copy();
vector.x *= Settings.JUMP_STOP_DAMPING_FACTOR;
this.body.SetLinearVelocity(vector);
}
}
Doll.prototype.jump = function () {
@ -251,6 +249,17 @@ function (Parent, Box2D, Settings, CollisionDetector, Item) {
}
}
Doll.prototype.jumpStop = function () {
if (!this.isStanding() ) {
this.body.SetAwake(true);
var vector = this.body.GetLinearVelocity().Copy();
if(vector.y < 0) {
vector.y *= Settings.JUMP_STOP_DAMPING_FACTOR;
this.body.SetLinearVelocity(vector);
}
}
}
Doll.prototype.setStanding = function (isStanding) {
if (this.standing == isStanding) return;
this.standing = isStanding;
@ -344,6 +353,13 @@ function (Parent, Box2D, Settings, CollisionDetector, Item) {
}
}
Doll.prototype.getVelocities = function() {
return {
linearVelocity: this.body.GetLinearVelocity(),
angularVelocity: this.body.GetAngularVelocity()
};
};
Doll.prototype.update = function() {
if (this.body.GetLinearVelocity().x == 0 && this.isWalking()) {

View file

@ -1,10 +1,11 @@
define([
"Game/" + GLOBALS.context + "/GameObjects/Item",
"Lib/Vendor/Box2D",
"Game/Config/Settings"
"Game/Config/Settings",
"Lib/Utilities/NotificationCenter"
],
function (Parent, Box2D, Settings) {
function (Parent, Box2D, Settings, NotificationCenter) {
function RagDoll(physicsEngine, uid, options) {
@ -160,6 +161,9 @@ function (Parent, Box2D, Settings) {
0,
options.limbs.upperRightArm.height / 2
);
NotificationCenter.trigger("game/object/add", 'animated', this);
}
RagDoll.prototype = Object.create(Parent.prototype);
@ -168,6 +172,14 @@ function (Parent, Box2D, Settings) {
return 55; //parseInt(this.uid.split("-")[1], 10);
};
RagDoll.prototype.getPosition = function() {
return this.body.GetPosition().Copy();
};
RagDoll.prototype.getHeadPosition = function() {
return this.limbs.head.GetPosition().Copy();
};
RagDoll.prototype.getBodyDef = function() {
var bodyDef = Parent.prototype.getBodyDef.call(this);
bodyDef.linearDamping = Settings.PLAYER_LINEAR_DAMPING;
@ -212,11 +224,6 @@ function (Parent, Box2D, Settings) {
this.body.CreateFixture(fixtureDef);
};
RagDoll.prototype.destroy = function() {
Parent.prototype.destroy.call(this);
// remove head!!11
};
RagDoll.prototype.addHead = function() {
var x = this.options.x + this.options.limbs.head.x,
y = this.options.y + this.options.limbs.head.y;
@ -341,11 +348,29 @@ function (Parent, Box2D, Settings) {
x * Settings.MAX_THROW_FORCE * limbDampingFactor,
-y * Settings.MAX_THROW_FORCE * 1.5 *limbDampingFactor // 1.5 is to throw higher then far
);
this.body.SetLinearVelocity(vector);
body.SetLinearVelocity(vector);
// body.SetAngularVelocity(Settings.MAX_THROW_ANGULAR_VELOCITY * x);
}
};
RagDoll.prototype.setVelocities = function(options) {
this.body.SetLinearVelocity(options.linearVelocity);
this.body.SetAngularVelocity(options.angularVelocity);
for(var name in this.limbs) {
this.limbs[name].SetLinearVelocity(options.linearVelocity);
}
};
RagDoll.prototype.destroy = function() {
NotificationCenter.trigger("game/object/remove", 'animated', this);
var world = this.body.GetWorld();
Parent.prototype.destroy.call(this);
for (var name in this.limbs) {
world.DestroyBody(this.limbs[name]);
}
};
return RagDoll;
});

View file

@ -0,0 +1,565 @@
define([
"Game/" + GLOBALS.context + "/GameObjects/Item",
"Lib/Vendor/Box2D",
"Game/Config/Settings"
],
function (Parent, Box2D, Settings) {
function RagDoll(physicsEngine, uid, options) {
Parent.call(this, physicsEngine, uid, options);
this.body.GetWorld().DestroyBody(this.body);
this.limbs = {};
this.initBodies();
}
RagDoll.prototype = Object.create(Parent.prototype);
RagDoll.prototype.initBodies = function() {
var world = this.body.GetWorld();
var bodies = [];
var joints = [];
{
var bd = new Box2D.Dynamics.b2BodyDef();
bd.type = Box2D.Dynamics.b2Body.b2_dynamicBody;
bd.position.Set(-1.917114257812500e-01, 1.433728694915771e+00);
bodies[0] = world.CreateBody(bd);
{
var fd = new Box2D.Dynamics.b2FixtureDef();
fd.friction = Settings.PLAYER_FRICTION;
fd.restitution = Settings.PLAYER_RESTITUTION;
fd.density = Settings.PLAYER_DENSITY;
fd.filter.groupIndex = -1;
var shape = new Box2D.Collision.Shapes.b2PolygonShape();
var vs = [];
vs[0] = new Box2D.Common.Math.b2Vec2(6.299880146980286e-02, -2.545155882835388e-01);
vs[1] = new Box2D.Common.Math.b2Vec2(6.299880146980286e-02, 2.545149326324463e-01);
vs[2] = new Box2D.Common.Math.b2Vec2(-6.299890577793121e-02, 2.545149326324463e-01);
vs[3] = new Box2D.Common.Math.b2Vec2(-6.299890577793121e-02, -2.545155882835388e-01);
shape.SetAsArray(vs, 4);
fd.shape = shape;
bodies[0].CreateFixture(fd);
}
}
{
var bd = new Box2D.Dynamics.b2BodyDef();
bd.type = Box2D.Dynamics.b2Body.b2_dynamicBody;
bd.position.Set(-6.397294998168945e-02, 1.267420768737793e+00);
bodies[1] = world.CreateBody(bd);
{
var fd = new Box2D.Dynamics.b2FixtureDef();
fd.friction = Settings.PLAYER_FRICTION;
fd.restitution = Settings.PLAYER_RESTITUTION;
fd.density = Settings.PLAYER_DENSITY;
fd.filter.groupIndex = -1;
var shape = new Box2D.Collision.Shapes.b2PolygonShape();
var vs = [];
vs[0] = new Box2D.Common.Math.b2Vec2(1.883362084627151e-01, -4.305148720741272e-01);
vs[1] = new Box2D.Common.Math.b2Vec2(1.846363544464111e-01, 5.393795371055603e-01);
vs[2] = new Box2D.Common.Math.b2Vec2(1.850083470344543e-03, 5.393795371055603e-01);
vs[3] = new Box2D.Common.Math.b2Vec2(-1.883361339569092e-01, 4.209862351417542e-01);
vs[4] = new Box2D.Common.Math.b2Vec2(-1.883361339569092e-01, -4.607573151588440e-01);
vs[5] = new Box2D.Common.Math.b2Vec2(1.600667834281921e-03, -4.952520132064819e-01);
shape.SetAsArray(vs, 6);
fd.shape = shape;
bodies[1].CreateFixture(fd);
}
{
var fd = new Box2D.Dynamics.b2FixtureDef();
fd.friction = Settings.PLAYER_FRICTION;
fd.restitution = Settings.PLAYER_RESTITUTION;
fd.density = Settings.PLAYER_DENSITY;
fd.filter.groupIndex = -1;
var shape = new Box2D.Collision.Shapes.b2PolygonShape();
var vs = [];
vs[0] = new Box2D.Common.Math.b2Vec2(1.840525716543198e-01, 4.875739216804504e-01);
vs[1] = new Box2D.Common.Math.b2Vec2(1.840525716543198e-01, 6.762337088584900e-01);
vs[2] = new Box2D.Common.Math.b2Vec2(-4.607129842042923e-03, 6.762337088584900e-01);
vs[3] = new Box2D.Common.Math.b2Vec2(-4.607129842042923e-03, 4.875739216804504e-01);
shape.SetAsArray(vs, 4);
fd.shape = shape;
bodies[1].CreateFixture(fd);
}
}
{
var bd = new Box2D.Dynamics.b2BodyDef();
bd.type = Box2D.Dynamics.b2Body.b2_dynamicBody;
bd.position.Set(4.118728637695312e-02, 2.199305295944214e+00);
bodies[2] = world.CreateBody(bd);
{
var fd = new Box2D.Dynamics.b2FixtureDef();
fd.friction = 2.000000029802322e-01;
fd.restitution = 0.000000000000000e+00;
fd.density = 2.204959988594055e-01;
fd.filter.groupIndex = -1;
var shape = new Box2D.Collision.Shapes.b2CircleShape();
shape.m_radius = 3.009769916534424e-01;
shape.m_p.Set(-8.219080045819283e-03, 4.109379835426807e-03);
fd.shape = shape;
bodies[2].CreateFixture(fd);
}
{
var fd = new Box2D.Dynamics.b2FixtureDef();
fd.friction = 2.000000029802322e-01;
fd.restitution = 0.000000000000000e+00;
fd.density = 2.204959988594055e-01;
fd.filter.groupIndex = -1;
var shape = new Box2D.Collision.Shapes.b2CircleShape();
shape.m_radius = 2.723909914493561e-01;
shape.m_p.Set(-3.647049888968468e-02, -1.517499983310699e-01);
fd.shape = shape;
bodies[2].CreateFixture(fd);
}
}
{
var bd = new Box2D.Dynamics.b2BodyDef();
bd.type = Box2D.Dynamics.b2Body.b2_dynamicBody;
bd.position.Set(1.235442161560059e-01, 1.142371892929077e+00);
bodies[3] = world.CreateBody(bd);
{
var fd = new Box2D.Dynamics.b2FixtureDef();
fd.friction = Settings.PLAYER_FRICTION;
fd.restitution = Settings.PLAYER_RESTITUTION;
fd.density = Settings.PLAYER_DENSITY;
fd.filter.groupIndex = -1;
var shape = new Box2D.Collision.Shapes.b2PolygonShape();
var vs = [];
vs[0] = new Box2D.Common.Math.b2Vec2(6.299892067909241e-02, -1.556134223937988e-01);
vs[1] = new Box2D.Common.Math.b2Vec2(6.299892067909241e-02, 1.556134223937988e-01);
vs[2] = new Box2D.Common.Math.b2Vec2(-6.299898028373718e-02, 1.556134223937988e-01);
vs[3] = new Box2D.Common.Math.b2Vec2(-6.299898028373718e-02, -1.556134223937988e-01);
shape.SetAsArray(vs, 4);
fd.shape = shape;
bodies[3].CreateFixture(fd);
}
}
{
var bd = new Box2D.Dynamics.b2BodyDef();
bd.type = Box2D.Dynamics.b2Body.b2_dynamicBody;
bd.position.Set(-9.663248062133789e-02, 3.554300665855408e-01);
bodies[4] = world.CreateBody(bd);
{
var fd = new Box2D.Dynamics.b2FixtureDef();
fd.friction = Settings.PLAYER_FRICTION;
fd.restitution = Settings.PLAYER_RESTITUTION;
fd.density = Settings.PLAYER_DENSITY;
fd.filter.groupIndex = -1;
var shape = new Box2D.Collision.Shapes.b2PolygonShape();
var vs = [];
vs[0] = new Box2D.Common.Math.b2Vec2(1.550966501235962e-01, -1.253567039966583e-01);
vs[1] = new Box2D.Common.Math.b2Vec2(1.550966501235962e-01, -6.225190684199333e-02);
vs[2] = new Box2D.Common.Math.b2Vec2(-9.268096834421158e-02, -6.225190684199333e-02);
vs[3] = new Box2D.Common.Math.b2Vec2(-9.268096834421158e-02, -1.253567039966583e-01);
shape.SetAsArray(vs, 4);
fd.shape = shape;
bodies[4].CreateFixture(fd);
}
{
var fd = new Box2D.Dynamics.b2FixtureDef();
fd.friction = Settings.PLAYER_FRICTION;
fd.restitution = Settings.PLAYER_RESTITUTION;
fd.density = Settings.PLAYER_DENSITY;
fd.filter.groupIndex = -1;
var shape = new Box2D.Collision.Shapes.b2PolygonShape();
var vs = [];
vs[0] = new Box2D.Common.Math.b2Vec2(9.449840337038040e-02, -1.247676759958267e-01);
vs[1] = new Box2D.Common.Math.b2Vec2(9.449840337038040e-02, 1.715210527181625e-01);
vs[2] = new Box2D.Common.Math.b2Vec2(-9.449829906225204e-02, 1.715210527181625e-01);
vs[3] = new Box2D.Common.Math.b2Vec2(-9.449829906225204e-02, -1.247676759958267e-01);
shape.SetAsArray(vs, 4);
fd.shape = shape;
bodies[4].CreateFixture(fd);
}
}
{
var bd = new Box2D.Dynamics.b2BodyDef();
bd.type = Box2D.Dynamics.b2Body.b2_dynamicBody;
bd.position.Set(-1.917138099670410e-01, 1.142371892929077e+00);
bodies[5] = world.CreateBody(bd);
{
var fd = new Box2D.Dynamics.b2FixtureDef();
fd.friction = Settings.PLAYER_FRICTION;
fd.restitution = Settings.PLAYER_RESTITUTION;
fd.density = Settings.PLAYER_DENSITY;
fd.filter.groupIndex = -1;
var shape = new Box2D.Collision.Shapes.b2PolygonShape();
var vs = [];
vs[0] = new Box2D.Common.Math.b2Vec2(6.299891322851181e-02, -1.556134223937988e-01);
vs[1] = new Box2D.Common.Math.b2Vec2(6.299891322851181e-02, 1.556134223937988e-01);
vs[2] = new Box2D.Common.Math.b2Vec2(-6.299878656864166e-02, 1.556134223937988e-01);
vs[3] = new Box2D.Common.Math.b2Vec2(-6.299878656864166e-02, -1.556134223937988e-01);
shape.SetAsArray(vs, 4);
fd.shape = shape;
bodies[5].CreateFixture(fd);
}
}
{
var bd = new Box2D.Dynamics.b2BodyDef();
bd.type = Box2D.Dynamics.b2Body.b2_dynamicBody;
bd.position.Set(1.235442161560059e-01, 1.433728694915771e+00);
bodies[6] = world.CreateBody(bd);
{
var fd = new Box2D.Dynamics.b2FixtureDef();
fd.friction = Settings.PLAYER_FRICTION;
fd.restitution = Settings.PLAYER_RESTITUTION;
fd.density = Settings.PLAYER_DENSITY;
fd.filter.groupIndex = -1;
var shape = new Box2D.Collision.Shapes.b2PolygonShape();
var vs = [];
vs[0] = new Box2D.Common.Math.b2Vec2(6.299892067909241e-02, -2.545155882835388e-01);
vs[1] = new Box2D.Common.Math.b2Vec2(6.299892067909241e-02, 2.545149326324463e-01);
vs[2] = new Box2D.Common.Math.b2Vec2(-6.299898028373718e-02, 2.545149326324463e-01);
vs[3] = new Box2D.Common.Math.b2Vec2(-6.299898028373718e-02, -2.545155882835388e-01);
shape.SetAsArray(vs, 4);
fd.shape = shape;
bodies[6].CreateFixture(fd);
}
}
{
var bd = new Box2D.Dynamics.b2BodyDef();
bd.type = Box2D.Dynamics.b2Body.b2_dynamicBody;
bd.position.Set(2.897095680236816e-02, 6.702435612678528e-01);
bodies[7] = world.CreateBody(bd);
{
var fd = new Box2D.Dynamics.b2FixtureDef();
fd.friction = Settings.PLAYER_FRICTION;
fd.restitution = Settings.PLAYER_RESTITUTION;
fd.density = Settings.PLAYER_DENSITY;
fd.filter.groupIndex = -1;
var shape = new Box2D.Collision.Shapes.b2PolygonShape();
var vs = [];
vs[0] = new Box2D.Common.Math.b2Vec2(9.449830651283264e-02, -2.537839412689209e-01);
vs[1] = new Box2D.Common.Math.b2Vec2(9.449830651283264e-02, 2.537844777107239e-01);
vs[2] = new Box2D.Common.Math.b2Vec2(-9.449817240238190e-02, 2.537844777107239e-01);
vs[3] = new Box2D.Common.Math.b2Vec2(-9.449817240238190e-02, -2.537839412689209e-01);
shape.SetAsArray(vs, 4);
fd.shape = shape;
bodies[7].CreateFixture(fd);
}
}
{
var bd = new Box2D.Dynamics.b2BodyDef();
bd.type = Box2D.Dynamics.b2Body.b2_dynamicBody;
bd.position.Set(-9.663248062133789e-02, 6.702435612678528e-01);
bodies[8] = world.CreateBody(bd);
{
var fd = new Box2D.Dynamics.b2FixtureDef();
fd.friction = Settings.PLAYER_FRICTION;
fd.restitution = Settings.PLAYER_RESTITUTION;
fd.density = Settings.PLAYER_DENSITY;
fd.filter.groupIndex = -1;
var shape = new Box2D.Collision.Shapes.b2PolygonShape();
var vs = [];
vs[0] = new Box2D.Common.Math.b2Vec2(9.449842572212219e-02, -2.537839412689209e-01);
vs[1] = new Box2D.Common.Math.b2Vec2(9.449842572212219e-02, 2.537844777107239e-01);
vs[2] = new Box2D.Common.Math.b2Vec2(-9.449826925992966e-02, 2.537844777107239e-01);
vs[3] = new Box2D.Common.Math.b2Vec2(-9.449826925992966e-02, -2.537839412689209e-01);
shape.SetAsArray(vs, 4);
fd.shape = shape;
bodies[8].CreateFixture(fd);
}
}
{
var bd = new Box2D.Dynamics.b2BodyDef();
bd.type = Box2D.Dynamics.b2Body.b2_dynamicBody;
bd.position.Set(2.897095680236816e-02, 3.554300665855408e-01);
bodies[9] = world.CreateBody(bd);
{
var fd = new Box2D.Dynamics.b2FixtureDef();
fd.friction = Settings.PLAYER_FRICTION;
fd.restitution = Settings.PLAYER_RESTITUTION;
fd.density = Settings.PLAYER_DENSITY;
fd.filter.groupIndex = -1;
var shape = new Box2D.Collision.Shapes.b2PolygonShape();
var vs = [];
vs[0] = new Box2D.Common.Math.b2Vec2(1.550965905189514e-01, -1.253567039966583e-01);
vs[1] = new Box2D.Common.Math.b2Vec2(1.550965905189514e-01, -6.225190684199333e-02);
vs[2] = new Box2D.Common.Math.b2Vec2(-9.268099069595337e-02, -6.225190684199333e-02);
vs[3] = new Box2D.Common.Math.b2Vec2(-9.268099069595337e-02, -1.253567039966583e-01);
shape.SetAsArray(vs, 4);
fd.shape = shape;
bodies[9].CreateFixture(fd);
}
{
var fd = new Box2D.Dynamics.b2FixtureDef();
fd.friction = Settings.PLAYER_FRICTION;
fd.restitution = Settings.PLAYER_RESTITUTION;
fd.density = Settings.PLAYER_DENSITY;
fd.filter.groupIndex = -1;
var shape = new Box2D.Collision.Shapes.b2PolygonShape();
var vs = [];
vs[0] = new Box2D.Common.Math.b2Vec2(9.449830651283264e-02, -1.247680261731148e-01);
vs[1] = new Box2D.Common.Math.b2Vec2(9.449830651283264e-02, 1.713046580553055e-01);
vs[2] = new Box2D.Common.Math.b2Vec2(-9.449817240238190e-02, 1.713046580553055e-01);
vs[3] = new Box2D.Common.Math.b2Vec2(-9.449817240238190e-02, -1.247680261731148e-01);
shape.SetAsArray(vs, 4);
fd.shape = shape;
bodies[9].CreateFixture(fd);
}
}
/*{
ground body
var bd = new Box2D.Dynamics.b2BodyDef();
bd.type = b2BodyType(0);
bd.position.Set(3.118395805358887e-03, -6.553649902343750e-03);
bodies[10] = world.CreateBody(bd);
{
var fd = new Box2D.Dynamics.b2FixtureDef();
fd.friction = Settings.PLAYER_FRICTION;
fd.restitution = Settings.PLAYER_RESTITUTION;
fd.density = Settings.PLAYER_DENSITY;
fd.filter.groupIndex = int16(0);
b2ChainShape shape;
b2Vec2 vs[2];
vs[0] = new Box2D.Common.Math.b2Vec2(-4.179394245147705e+00, 0.000000000000000e+00);
vs[1] = new Box2D.Common.Math.b2Vec2(4.179394245147705e+00, 0.000000000000000e+00);
shape.CreateChain(vs, 2);
shape.m_prevVertex.Set(-1.998532295227051e+00, -2.391039296991059e-23);
shape.m_nextVertex.Set(4.949933242915726e-38, 3.363116314379561e-44);
shape.m_hasPrevVertex = false;
shape.m_hasNextVertex = false;
fd.shape = shape;
bodies[10].CreateFixture(fd);
}
}*/
{
var jd = new Box2D.Dynamics.Joints.b2RevoluteJointDef();
jd.bodyA = bodies[1];
jd.bodyB = bodies[8];
jd.collideConnected = false;
jd.localAnchorA.Set(-9.128235280513763e-02, -3.880688548088074e-01);
jd.localAnchorB.Set(-6.031601130962372e-02, 2.092975974082947e-01);
jd.referenceAngle = 0.000000000000000e+00;
jd.enableLimit = true;
jd.lowerAngle = -6.981316804885864e-01;
jd.upperAngle = 1.919862151145935e+00;
jd.enableMotor = false;
jd.motorSpeed = 0.000000000000000e+00;
jd.maxMotorTorque = 1.000000000000000e+00;
joints[0] = world.CreateJoint(jd);
}
{
var jd = new Box2D.Dynamics.Joints.b2RevoluteJointDef();
jd.bodyA = bodies[1];
jd.bodyB = bodies[7];
jd.collideConnected = false;
jd.localAnchorA.Set(1.498610228300095e-01, -3.952181935310364e-01);
jd.localAnchorB.Set(5.541206151247025e-02, 2.019590735435486e-01);
jd.referenceAngle = 0.000000000000000e+00;
jd.enableLimit = true;
jd.lowerAngle = -6.981316804885864e-01;
jd.upperAngle = 1.919862151145935e+00;
jd.enableMotor = false;
jd.motorSpeed = 0.000000000000000e+00;
jd.maxMotorTorque = 1.000000000000000e+00;
joints[1] = world.CreateJoint(jd);
}
{
var jd = new Box2D.Dynamics.Joints.b2RevoluteJointDef();
jd.bodyA = bodies[1];
jd.bodyB = bodies[6];
jd.collideConnected = false;
jd.localAnchorA.Set(1.874177008867264e-01, 3.626269102096558e-01);
jd.localAnchorB.Set(-1.000612974166870e-04, 1.963189840316772e-01);
jd.referenceAngle = 0.000000000000000e+00;
jd.enableLimit = false;
jd.lowerAngle = -2.268928050994873e+00;
jd.upperAngle = 3.141592741012573e+00;
jd.enableMotor = false;
jd.motorSpeed = 0.000000000000000e+00;
jd.maxMotorTorque = 1.000000000000000e+00;
joints[2] = world.CreateJoint(jd);
}
{
var jd = new Box2D.Dynamics.Joints.b2RevoluteJointDef();
jd.bodyA = bodies[1];
jd.bodyB = bodies[0];
jd.collideConnected = false;
jd.localAnchorA.Set(-1.277616322040558e-01, 3.649693727493286e-01);
jd.localAnchorB.Set(-2.339482307434082e-05, 1.986622810363770e-01);
jd.referenceAngle = 0.000000000000000e+00;
jd.enableLimit = false;
jd.lowerAngle = -2.268928050994873e+00;
jd.upperAngle = 3.141592741012573e+00;
jd.enableMotor = false;
jd.motorSpeed = 0.000000000000000e+00;
jd.maxMotorTorque = 1.000000000000000e+00;
joints[3] = world.CreateJoint(jd);
}
{
var jd = new Box2D.Dynamics.Joints.b2RevoluteJointDef();
jd.bodyA = bodies[8];
jd.bodyB = bodies[4];
jd.collideConnected = false;
jd.localAnchorA.Set(-1.047469675540924e-03, -1.993342936038971e-01);
jd.localAnchorB.Set(-1.047216355800629e-03, 1.156357824802399e-01);
jd.referenceAngle = 0.000000000000000e+00;
jd.enableLimit = true;
jd.lowerAngle = -2.268928050994873e+00;
jd.upperAngle = 0.000000000000000e+00;
jd.enableMotor = false;
jd.motorSpeed = 0.000000000000000e+00;
jd.maxMotorTorque = 1.000000000000000e+00;
joints[4] = world.CreateJoint(jd);
}
{
var jd = new Box2D.Dynamics.Joints.b2RevoluteJointDef();
jd.bodyA = bodies[0];
jd.bodyB = bodies[5];
jd.collideConnected = false;
jd.localAnchorA.Set(1.148343086242676e-03, -1.961904764175415e-01);
jd.localAnchorB.Set(1.148715615272522e-03, 9.516614675521851e-02);
jd.referenceAngle = 0.000000000000000e+00;
jd.enableLimit = true;
jd.lowerAngle = 0.000000000000000e+00;
jd.upperAngle = 1.919862151145935e+00;
jd.enableMotor = false;
jd.motorSpeed = 0.000000000000000e+00;
jd.maxMotorTorque = 1.000000000000000e+00;
joints[5] = world.CreateJoint(jd);
}
{
var jd = new Box2D.Dynamics.Joints.b2RevoluteJointDef();
jd.bodyA = bodies[3];
jd.bodyB = bodies[6];
jd.collideConnected = false;
jd.localAnchorA.Set(4.750192165374756e-04, 9.541386365890503e-02);
jd.localAnchorB.Set(4.747509956359863e-04, -1.959429979324341e-01);
jd.referenceAngle = 0.000000000000000e+00;
jd.enableLimit = true;
jd.lowerAngle = 0.000000000000000e+00;
jd.upperAngle = 1.919862151145935e+00;
jd.enableMotor = false;
jd.motorSpeed = 0.000000000000000e+00;
jd.maxMotorTorque = 1.000000000000000e+00;
joints[6] = world.CreateJoint(jd);
}
{
var jd = new Box2D.Dynamics.Joints.b2RevoluteJointDef();
jd.bodyA = bodies[7];
jd.bodyB = bodies[9];
jd.collideConnected = false;
jd.localAnchorA.Set(2.657793462276459e-03, -2.022806107997894e-01);
jd.localAnchorB.Set(2.657927572727203e-03, 1.125320196151733e-01);
jd.referenceAngle = 0.000000000000000e+00;
jd.enableLimit = true;
jd.lowerAngle = -2.268928050994873e+00;
jd.upperAngle = 0.000000000000000e+00;
jd.enableMotor = false;
jd.motorSpeed = 0.000000000000000e+00;
jd.maxMotorTorque = 1.000000000000000e+00;
joints[7] = world.CreateJoint(jd);
}
{
var jd = new Box2D.Dynamics.Joints.b2RevoluteJointDef();
jd.bodyA = bodies[1];
jd.bodyB = bodies[2];
jd.collideConnected = false;
jd.localAnchorA.Set(8.169807493686676e-02, 5.554057359695435e-01);
jd.localAnchorB.Set(-2.346399985253811e-02, -3.764809966087341e-01);
jd.referenceAngle = 0.000000000000000e+00;
jd.enableLimit = true;
jd.lowerAngle = -1.221730470657349e+00;
jd.upperAngle = 6.981316804885864e-01;
jd.enableMotor = false;
jd.motorSpeed = 0.000000000000000e+00;
jd.maxMotorTorque = 1.000000000000000e+00;
joints[8] = world.CreateJoint(jd);
}
this.body = bodies[1];
this.limbs = {
head: bodies[2],
upperLeftArm: bodies[0],
lowerLeftArm: bodies[5],
upperRightArm: bodies[6],
lowerRightArm: bodies[3],
upperLeftLeg: bodies[8],
lowerLeftLeg: bodies[4],
upperRightLeg: bodies[7],
lowerRightLeg: bodies[9]
};
this.body.SetPosition(new Box2D.Common.Math.b2Vec2(20,0));
};
RagDoll.prototype.destroy = function() {
var world = this.body.GetWorld();
Parent.prototype.destroy.call(this); // chest destruction
for(var key in this.limbs) {
world.DestroyBody(this.limbs[key]);
}
};
return RagDoll;
});

View file

@ -0,0 +1,37 @@
define([
"Game/" + GLOBALS.context + "/GameObjects/GameObject",
"Lib/Vendor/Box2D"
],
function (Parent, Box2D) {
function SpectatorDoll(physicsEngine, uid, player) {
Parent.call(this, physicsEngine, uid);
}
SpectatorDoll.prototype = Object.create(Parent.prototype);
SpectatorDoll.prototype.getBodyDef = function() {
var bodyDef = new Box2D.Dynamics.b2BodyDef();
bodyDef.type = Box2D.Dynamics.b2Body.b2_dynamicBody;
bodyDef.position.x = this.getPosition().x;
bodyDef.position.y = this.getPosition().y;
bodyDef.angle = 0;
return bodyDef;
};
SpectatorDoll.prototype.getPosition = function() {
return {x: 10, y: 10};
}
SpectatorDoll.prototype.getHeadPosition = function() {
return {x: 10, y: 10};
}
SpectatorDoll.prototype.update = function() {
};
return SpectatorDoll;
});

View file

@ -1,11 +1,14 @@
define([
"Game/" + GLOBALS.context + "/GameObjects/Doll",
"Game/Config/Settings",
"Lib/Utilities/NotificationCenter"
"Lib/Utilities/NotificationCenter",
"Lib/Utilities/Exception",
"Game/" + GLOBALS.context + "/GameObjects/SpectatorDoll",
"Game/" + GLOBALS.context + "/GameObjects/Items/RagDoll"
],
function (Doll, Settings, NotificationCenter) {
function (Doll, Settings, NotificationCenter, Exception, SpectatorDoll, RagDoll) {
function Player (id, physicsEngine) {
this.stats = {
@ -20,28 +23,36 @@ function (Doll, Settings, NotificationCenter) {
this.id = id;
this.isSpawned = false;
this.holdingItem = null;
this.spectatorDoll = new SpectatorDoll(this.physicsEngine, "spectatorDoll-" + this.id, this);
}
Player.prototype.getDoll = function() {
throw new Exception('-- PLEASE REMOVE getDoll Calls --');
return this.doll;
};
Player.prototype.spawn = function (x, y) {
if(this.doll) {
this.doll.destroy();
Player.prototype.getActiveDoll = function() {
if(this.isSpawned) {
return this.doll;
} else if (this.ragDoll) {
return this.ragDoll;
}
return this.spectatorDoll;
};
Player.prototype.spawn = function (x, y) {
this.doll = new Doll(this.physicsEngine, "doll-" + this.id, this);
this.doll.spawn(x, y);
this.isSpawned = true;
NotificationCenter.trigger("game/object/add", 'animated', this.doll);
}
Player.prototype.getPosition = function () {
return this.doll.getPosition();
return this.getActiveDoll().getPosition();
}
Player.prototype.getHeadPosition = function () {
if(!this.isSpawned) return false;
return this.doll.getHeadPosition();
return this.getActiveDoll().getHeadPosition();
}
@ -60,8 +71,14 @@ function (Doll, Settings, NotificationCenter) {
this.doll.jump();
}
Player.prototype.jumpStop = function () {
if(!this.isSpawned) return false;
this.doll.jumpStop();
}
Player.prototype.lookAt = function (x, y) {
if(!this.isSpawned) return false;
// FIXME implement spectator movement here
this.doll.lookAt(x, y);
}
@ -79,15 +96,42 @@ function (Doll, Settings, NotificationCenter) {
this.holdingItem = null;
};
Player.prototype.kill = function(killedBy) {
Player.prototype.kill = function(killedByPlayer) {
if(!this.isSpawned) return false;
// FIXME: do something better then just respawn in GameController
if(this.holdingItem) {
this.throw(0, 0, this.holdingItem)
}
this.doll.kill();
// get forces
var options = {
x: this.getPosition().x * Settings.RATIO,
y: this.getPosition().y * Settings.RATIO,
category: "graveyard",
grabAngle: -0.3,
image: "chest.png",
name: "RagDoll",
rotation: 0,
type: "ragdoll",
weight: 3,
width: 5,
height: 12
};
var ragDoll = new RagDoll(this.physicsEngine, "ragDoll-" + this.id, options);
ragDoll.setVelocities(this.doll.getVelocities());
this.isSpawned = false;
NotificationCenter.trigger("game/object/remove", 'animated', this.doll);
this.doll.destroy();
this.doll = null;
this.ragDoll = ragDoll;
NotificationCenter.trigger("player/killed", this);
};
@ -106,7 +150,10 @@ function (Doll, Settings, NotificationCenter) {
if(this.holdingItem) {
this.throw(0, 0, this.holdingItem);
}
this.doll.destroy();
this.spectatorDoll.destroy();
if(this.doll) this.doll.destroy();
if(this.ragDoll) this.ragDoll.destroy();
}
Player.prototype.setPlayerController = function(playerController) {

View file

@ -35,6 +35,10 @@ function(Parent, NotificationCenter, Parser) {
if (options) this.player.handActionRequest(options.x, options.y);
};
PlayerController.prototype.suicide = function() {
this.player.suicide();
};
return PlayerController;
});

View file

@ -34,6 +34,8 @@ function (Parent, PhysicsEngine, Settings, PlayerController, requestAnimFrame, N
GameController.prototype.update = function () {
Parent.prototype.update.call(this);
requestAnimFrame(this.update.bind(this));
this.physicsEngine.update();
@ -51,16 +53,21 @@ function (Parent, PhysicsEngine, Settings, PlayerController, requestAnimFrame, N
Parent.prototype.userJoined.call(this, user);
var player = this.players[user.id];
user.setPlayer(player);
this.spawnPlayer(player);
this.spawnPlayer(player, 0);
}
GameController.prototype.spawnPlayer = function(player) {
GameController.prototype.spawnPlayer = function(player, respawnTime) {
var self = this;
var spawnPoint = this.level.getRandomSpawnPoint();
respawnTime = typeof respawnTime == 'undefined'
? Settings.RESPAWN_TIME
: respawnTime;
setTimeout(function() {
player.spawn(spawnPoint.x, spawnPoint.y);
self.gameObjects.animated.push(player.getDoll());
// put it into
self.gameObjects.animated.push(player);
var message = {
spawnPlayer: {
@ -71,7 +78,7 @@ function (Parent, PhysicsEngine, Settings, PlayerController, requestAnimFrame, N
};
NotificationCenter.trigger("broadcastControlCommand", "gameCommand", message);
}, Settings.RESPAWN_TIME * 1000);
}, respawnTime * 1000);
};
GameController.prototype.createPlayer = function(user) {

View file

@ -1,9 +1,47 @@
define([
"Game/Core/GameObjects/Items/RagDoll"
"Game/Core/GameObjects/Items/RagDoll",
"Game/Config/Settings",
"Lib/Utilities/NotificationCenter"
],
function (Parent) {
function (Parent, Settings, NotificationCenter) {
return Parent;
function RagDoll(physicsEngine, uid, options) {
this.scheduledForDestruction = false;
this.destructionTimeout = null;
Parent.call(this, physicsEngine, uid, options);
}
RagDoll.prototype = Object.create(Parent.prototype);
RagDoll.prototype.beingGrabbed = function(player) {
Parent.prototype.beingGrabbed.call(this, player);
if(this.scheduledForDestruction) {
clearTimeout(this.destructionTimeout);
}
};
RagDoll.prototype.beingReleased = function(player) {
Parent.prototype.beingReleased.call(this, player);
if(this.scheduledForDestruction) {
this.delayedDestroy();
}
};
RagDoll.prototype.delayedDestroy = function() {
this.scheduledForDestruction = true;
this.destructionTimeout = setTimeout(this.destroy.bind(this), Settings.RAGDOLL_DESTRUCTION_TIME * 1000);
};
RagDoll.prototype.destroy = function() {
NotificationCenter.trigger("broadcastGameCommand", 'removeGameObject', {
type: 'animated',
uid: this.uid
});
Parent.prototype.destroy.call(this);
};
return RagDoll;
});

View file

@ -0,0 +1,9 @@
define([
"Game/Core/GameObjects/SpectatorDoll"
],
function (Parent) {
return Parent;
});

View file

@ -56,12 +56,18 @@ function (Parent, NotificationCenter) {
}
};
Player.prototype.suicide = function() {
this.addDamage(100, this);
};
Player.prototype.addDamage = function(damage, enemy) {
this.stats.health -= damage;
if(this.stats.health < 0) this.stats.health = 0;
if(this.stats.health <= 0) {
enemy.score();
this.kill();
if(enemy != this) enemy.score();
this.kill(enemy);
} else {
this.broadcastStats();
}
@ -73,11 +79,18 @@ function (Parent, NotificationCenter) {
this.broadcastStats();
};
Player.prototype.kill = function() {
Parent.prototype.kill.call(this);
Player.prototype.kill = function(killedByPlayer) {
Parent.prototype.kill.call(this, killedByPlayer);
this.stats.deaths++;
this.broadcastStats();
NotificationCenter.trigger("broadcastGameCommand", "playerKill", this.id);
NotificationCenter.trigger("broadcastGameCommand", "playerKill", {
playerId: this.id,
killedByPlayerId: killedByPlayer.id
});
if(this.ragDoll) {
this.ragDoll.delayedDestroy();
}
};
Player.prototype.score = function() {

11072
lab/rube/js/box2dweb.js Normal file

File diff suppressed because it is too large Load diff

78
lab/rube/js/index.html Normal file
View file

@ -0,0 +1,78 @@
<html>
<head>
<title>Box2D javascript (box2dweb) testbed</title>
<script type="text/javascript" src="box2dweb.js"></script>
<script type="text/javascript" src="loadrube.js"></script>
<script type="text/javascript" src="testbed.js"></script>
<script type="text/javascript" src="jack-min.js"></script>
<script type="text/javascript" src="jackinthebox.js"></script>
<script type="text/javascript" src="ragdoll-min.js"></script>
<script type="text/javascript" src="ragdoll.js"></script>
<style>
html, body {
margin: 0;
padding: 0;
}
</style>
</head>
<body>
<canvas id="canvas" width="640" height="480" tabindex='1'></canvas>
<div style="display: none;text-align:center">
<br>
Try the latest version of Chrome or Firefox for best performance.<br>
<br>
<div style="margin:auto;width:640px;padding:2px;border:1px solid #888;text-align:left">
<!--
If you change the size of the canvas, you'll also need to change
the value of 'viewCenterPixel' in testbed.js
-->
<div style="width:636px;padding:2px;background-color:#ddd">
<div style="text-align:center">
Select test: <select id="testSelection" onchange="changeTest();">
<option value="ragdoll">Ragdoll of Chuck</option>
<option value="jackinthebox">Jack-in-the-box</option>
</select><br>
<div style="height:6px"></div>
<div id="sceneinfo" style="width:500px;margin:auto;background-color:#eee;text-align:left">
Loading...
</div>
<div id="testcomments" style="width:500px;margin:auto;background-color:#eee;text-align:left">
</div>
<br>
<button id="reloadButton" onclick="resetScene();">Reset</button>
<button id="pauseButton" onclick="pause();">Pause</button>
<button id="stepButton" onclick="step();">Single step</button>
(Keyboard: R, P, S)<br>
Zoom
<button id="zoomInButton" onclick="zoomIn();">+</button>
<button id="zoomOutButton" onclick="zoomOut();">-</button>
(Keyboard: X, Z)<br>
Hold down Shift while moving the mouse to pan (Keyboard: arrow keys)<br>
You need to click on the canvas before using the keyboard.<br>
</div>
<br>
Debug draw flags:<br>
<input id="drawShapesCheck" type="checkbox" onclick="updateWorldFromDebugDrawCheckboxes();">Shapes<br>
<input id="drawJointsCheck" type="checkbox" onclick="updateWorldFromDebugDrawCheckboxes();">Joints<br>
<input id="drawAABBsCheck" type="checkbox" onclick="updateWorldFromDebugDrawCheckboxes();">AABBs<br>
<input id="drawTransformsCheck" type="checkbox" onclick="updateWorldFromDebugDrawCheckboxes();">Transforms<br>
<br>
<input id="showStatsCheck" type="checkbox" onclick="updateContinuousRefreshStatus();">Show stats<br>
<span id="feedbackSpan"></span>
<br>
</div>
</div>
</div>
</body>
</html>

12
lab/rube/js/jack-min.js vendored Normal file

File diff suppressed because one or more lines are too long

View file

@ -0,0 +1,26 @@
var jackinthebox = function() {
//constructor
}
jackinthebox.prototype.setNiceViewCenter = function() {
//called once when the user changes to this test from another test
PTM = 70;
setViewCenterWorld( new b2Vec2(0, 10.5), true );
}
jackinthebox.prototype.setup = function() {
//set up the Box2D scene here - the world is already created
if ( loadSceneFromRUBE(jack_scene) ) //jack_scene is defined in jack-min.js
console.log("RUBE scene loaded successfully.");
else
console.log("Failed to load RUBE scene");
doAfterLoading();
}
jackinthebox.prototype.getComments = function(canvas, evt) {
return "Created in R.U.B.E editor. Pull the latch to the side to open the box.";
}

416
lab/rube/js/loadrube.js Normal file
View file

@ -0,0 +1,416 @@
Object.prototype.hasOwnProperty = function(property) {
return typeof(this[property]) !== 'undefined'
};
function loadBodyFromRUBE(bodyJso, world) {
//console.log(bodyJso);
if ( ! bodyJso.hasOwnProperty('type') ) {
console.log("Body does not have a 'type' property");
return null;
}
var bd = new b2BodyDef();
if ( bodyJso.type == 2 )
bd.type = b2_dynamicBody;
else if ( bodyJso.type == 1 )
bd.type = b2_kinematicBody;
if ( bodyJso.hasOwnProperty('angle') )
bd.angle = bodyJso.angle;
if ( bodyJso.hasOwnProperty('angularVelocity') )
bd.angularVelocity = bodyJso.angularVelocity;
if ( bodyJso.hasOwnProperty('active') )
bd.awake = bodyJso.active;
if ( bodyJso.hasOwnProperty('fixedRotation') )
bd.fixedRotation = bodyJso.fixedRotation;
if ( bodyJso.hasOwnProperty('linearVelocity') && bodyJso.linearVelocity instanceof Object )
bd.linearVelocity.SetV( bodyJso.linearVelocity );
if ( bodyJso.hasOwnProperty('position') && bodyJso.position instanceof Object )
bd.position.SetV( bodyJso.position );
if ( bodyJso.hasOwnProperty('awake') )
bd.awake = bodyJso.awake;
else
bd.awake = false;
var body = world.CreateBody(bd);
if ( bodyJso.hasOwnProperty('fixture') ) {
for (k = 0; k < bodyJso['fixture'].length; k++) {
var fixtureJso = bodyJso['fixture'][k];
loadFixtureFromRUBE(body, fixtureJso);
}
}
if ( bodyJso.hasOwnProperty('name') )
body.name = bodyJso.name;
if ( bodyJso.hasOwnProperty('customProperties') )
body.customProperties = bodyJso.customProperties;
return body;
}
function loadFixtureFromRUBE(body, fixtureJso) {
//console.log(fixtureJso);
var fd = new b2FixtureDef();
if (fixtureJso.hasOwnProperty('friction'))
fd.friction = fixtureJso.friction;
if (fixtureJso.hasOwnProperty('density'))
fd.density = fixtureJso.density;
if (fixtureJso.hasOwnProperty('restitution'))
fd.restitution = fixtureJso.restitution;
if (fixtureJso.hasOwnProperty('sensor'))
fd.isSensor = fixtureJso.sensor;
if ( fixtureJso.hasOwnProperty('filter-categoryBits') )
fd.filter.categoryBits = fixtureJso['filter-categoryBits'];
if ( fixtureJso.hasOwnProperty('filter-maskBits') )
fd.filter.maskBits = fixtureJso['filter-maskBits'];
if ( fixtureJso.hasOwnProperty('filter-groupIndex') )
fd.filter.groupIndex = fixtureJso['filter-groupIndex'];
if (fixtureJso.hasOwnProperty('circle')) {
fd.shape = new b2CircleShape();
fd.shape.m_radius = fixtureJso.circle.radius;
if ( fixtureJso.circle.center )
fd.shape.m_p.SetV(fixtureJso.circle.center);
var fixture = body.CreateFixture(fd);
if ( fixtureJso.name )
fixture.name = fixtureJso.name;
}
else if (fixtureJso.hasOwnProperty('polygon')) {
fd.shape = new b2PolygonShape();
var verts = [];
for (v = 0; v < fixtureJso.polygon.vertices.x.length; v++)
verts.push( new b2Vec2( fixtureJso.polygon.vertices.x[v], fixtureJso.polygon.vertices.y[v] ) );
fd.shape.SetAsArray(verts, verts.length);
var fixture = body.CreateFixture(fd);
if ( fixture && fixtureJso.name )
fixture.name = fixtureJso.name;
}
else if (fixtureJso.hasOwnProperty('chain')) {
fd.shape = new b2PolygonShape();
var lastVertex = new b2Vec2();
for (v = 0; v < fixtureJso.chain.vertices.x.length; v++) {
var thisVertex = new b2Vec2( fixtureJso.chain.vertices.x[v], fixtureJso.chain.vertices.y[v] );
if ( v > 0 ) {
fd.shape.SetAsEdge( lastVertex, thisVertex );
var fixture = body.CreateFixture(fd);
if ( fixtureJso.name )
fixture.name = fixtureJso.name;
}
lastVertex = thisVertex;
}
}
else {
console.log("Could not find shape type for fixture");
}
}
function getVectorValue(val) {
if ( val instanceof Object )
return val;
else
return { x:0, y:0 };
}
function loadJointCommonProperties(jd, jointJso, loadedBodies) {
jd.bodyA = loadedBodies[jointJso.bodyA];
jd.bodyB = loadedBodies[jointJso.bodyB];
jd.localAnchorA.SetV( getVectorValue(jointJso.anchorA) );
jd.localAnchorB.SetV( getVectorValue(jointJso.anchorB) );
if ( jointJso.collideConnected )
jd.collideConnected = jointJso.collideConnected;
}
function loadJointFromRUBE(jointJso, world, loadedBodies)
{
if ( ! jointJso.hasOwnProperty('type') ) {
console.log("Joint does not have a 'type' property");
return null;
}
if ( jointJso.bodyA >= loadedBodies.length ) {
console.log("Index for bodyA is invalid: " + jointJso.bodyA );
return null;
}
if ( jointJso.bodyB >= loadedBodies.length ) {
console.log("Index for bodyB is invalid: " + jointJso.bodyB );
return null;
}
var joint = null;
if ( jointJso.type == "revolute" ) {
var jd = new b2RevoluteJointDef();
loadJointCommonProperties(jd, jointJso, loadedBodies);
if ( jointJso.hasOwnProperty('refAngle') )
jd.referenceAngle = jointJso.refAngle;
if ( jointJso.hasOwnProperty('lowerLimit') )
jd.lowerAngle = jointJso.lowerLimit;
if ( jointJso.hasOwnProperty('upperLimit') )
jd.upperAngle = jointJso.upperLimit;
if ( jointJso.hasOwnProperty('maxMotorTorque') )
jd.maxMotorTorque = jointJso.maxMotorTorque;
if ( jointJso.hasOwnProperty('motorSpeed') )
jd.motorSpeed = jointJso.motorSpeed;
if ( jointJso.hasOwnProperty('enableLimit') )
jd.enableLimit = jointJso.enableLimit;
if ( jointJso.hasOwnProperty('enableMotor') )
jd.enableMotor = jointJso.enableMotor;
joint = world.CreateJoint(jd);
}
else if ( jointJso.type == "distance" || jointJso.type == "rope" ) {
if ( jointJso.type == "rope" )
console.log("Replacing unsupported rope joint with distance joint!");
var jd = new b2DistanceJointDef();
loadJointCommonProperties(jd, jointJso, loadedBodies);
if ( jointJso.hasOwnProperty('length') )
jd.length = jointJso.length;
if ( jointJso.hasOwnProperty('dampingRatio') )
jd.dampingRatio = jointJso.dampingRatio;
if ( jointJso.hasOwnProperty('frequency') )
jd.frequencyHz = jointJso.frequency;
joint = world.CreateJoint(jd);
}
else if ( jointJso.type == "prismatic" ) {
var jd = new b2PrismaticJointDef();
loadJointCommonProperties(jd, jointJso, loadedBodies);
if ( jointJso.hasOwnProperty('localAxisA') )
jd.localAxisA.SetV( getVectorValue(jointJso.localAxisA) );
if ( jointJso.hasOwnProperty('refAngle') )
jd.referenceAngle = jointJso.refAngle;
if ( jointJso.hasOwnProperty('enableLimit') )
jd.enableLimit = jointJso.enableLimit;
if ( jointJso.hasOwnProperty('lowerLimit') )
jd.lowerTranslation = jointJso.lowerLimit;
if ( jointJso.hasOwnProperty('upperLimit') )
jd.upperTranslation = jointJso.upperLimit;
if ( jointJso.hasOwnProperty('enableMotor') )
jd.enableMotor = jointJso.enableMotor;
if ( jointJso.hasOwnProperty('maxMotorForce') )
jd.maxMotorForce = jointJso.maxMotorForce;
if ( jointJso.hasOwnProperty('motorSpeed') )
jd.motorSpeed = jointJso.motorSpeed;
joint = world.CreateJoint(jd);
}
else if ( jointJso.type == "wheel" ) {
//Make a fake wheel joint using a line joint and a distance joint.
//Return the line joint because it has the linear motor controls.
//Use ApplyTorque on the bodies to spin the wheel...
var jd = new b2DistanceJointDef();
loadJointCommonProperties(jd, jointJso, loadedBodies);
jd.length = 0.0;
if ( jointJso.hasOwnProperty('springDampingRatio') )
jd.dampingRatio = jointJso.springDampingRatio;
if ( jointJso.hasOwnProperty('springFrequency') )
jd.frequencyHz = jointJso.springFrequency;
world.CreateJoint(jd);
jd = new b2LineJointDef();
loadJointCommonProperties(jd, jointJso, loadedBodies);
if ( jointJso.hasOwnProperty('localAxisA') )
jd.localAxisA.SetV( getVectorValue(jointJso.localAxisA) );
joint = world.CreateJoint(jd);
}
else if ( jointJso.type == "friction" ) {
var jd = new b2FrictionJointDef();
loadJointCommonProperties(jd, jointJso, loadedBodies);
if ( jointJso.hasOwnProperty('maxForce') )
jd.maxForce = jointJso.maxForce;
if ( jointJso.hasOwnProperty('maxTorque') )
jd.maxTorque = jointJso.maxTorque;
joint = world.CreateJoint(jd);
}
else if ( jointJso.type == "weld" ) {
var jd = new b2WeldJointDef();
loadJointCommonProperties(jd, jointJso, loadedBodies);
if ( jointJso.hasOwnProperty('referenceAngle') )
jd.referenceAngle = jointJso.referenceAngle;
joint = world.CreateJoint(jd);
}
else {
console.log("Unsupported joint type: " + jointJso.type);
console.log(jointJso);
}
if ( joint && jointJso.name )
joint.name = jointJso.name;
return joint;
}
function makeClone(obj) {
var newObj = (obj instanceof Array) ? [] : {};
for (var i in obj) {
if (obj[i] && typeof obj[i] == "object")
newObj[i] = makeClone(obj[i]);
else
newObj[i] = obj[i];
}
return newObj;
};
function loadImageFromRUBE(imageJso, world, loadedBodies)
{
var image = makeClone(imageJso);
if ( image.hasOwnProperty('body') && image.body >= 0 )
image.body = loadedBodies[image.body];//change index to the actual body
else
image.body = null;
image.center = new b2Vec2();
image.center.SetV( getVectorValue(imageJso.center) );
return image;
}
//mainly just a convenience for the testbed - uses global 'world' variable
function loadSceneFromRUBE(worldJso) {
return loadSceneIntoWorld(worldJso, world);
}
//load the scene into an already existing world variable
function loadSceneIntoWorld(worldJso, world) {
var success = true;
var loadedBodies = [];
if ( worldJso.hasOwnProperty('body') ) {
for (var i = 0; i < worldJso.body.length; i++) {
var bodyJso = worldJso.body[i];
var body = loadBodyFromRUBE(bodyJso, world);
if ( body )
loadedBodies.push( body );
else
success = false;
}
}
var loadedJoints = [];
if ( worldJso.hasOwnProperty('joint') ) {
for (var i = 0; i < worldJso.joint.length; i++) {
var jointJso = worldJso.joint[i];
var joint = loadJointFromRUBE(jointJso, world, loadedBodies);
if ( joint )
loadedJoints.push( joint );
//else
// success = false;
}
}
var loadedImages = [];
if ( worldJso.hasOwnProperty('image') ) {
for (var i = 0; i < worldJso.image.length; i++) {
var imageJso = worldJso.image[i];
var image = loadImageFromRUBE(imageJso, world, loadedBodies);
if ( image )
loadedImages.push( image );
else
success = false;
}
world.images = loadedImages;
}
return success;
}
//create a world variable and return it if loading succeeds
function loadWorldFromRUBE(worldJso) {
var gravity = new b2Vec2(0,0);
if ( worldJso.hasOwnProperty('gravity') && worldJso.gravity instanceof Object )
gravity.SetV( worldJso.gravity );
var world = new b2World( gravity );
if ( ! loadSceneIntoWorld(worldJso, world) )
return false;
return world;
}
function getNamedBodies(world, name) {
var bodies = [];
for (b = world.m_bodyList; b; b = b.m_next) {
if ( b.name == name )
bodies.push(b);
}
return bodies;
}
function getNamedFixtures(world, name) {
var fixtures = [];
for (b = world.m_bodyList; b; b = b.m_next) {
for (f = b.m_fixtureList; f; f = f.m_next) {
if ( f.name == name )
fixtures.push(f);
}
}
return fixtures;
}
function getNamedJoints(world, name) {
var joints = [];
for (j = world.m_jointList; j; j = j.m_next) {
if ( j.name == name )
joints.push(j);
}
return joints;
}
function getNamedImages(world, name) {
var images = [];
for (i = 0; i < world.images.length; i++) {
if ( world.images[i].name == name )
images.push(world.images[i].name);
}
return images;
}
//custom properties
function getBodiesByCustomProperty(world, propertyType, propertyName, valueToMatch) {
var bodies = [];
for (b = world.m_bodyList; b; b = b.m_next) {
if ( ! b.hasOwnProperty('customProperties') )
continue;
for (var i = 0; i < b.customProperties.length; i++) {
if ( ! b.customProperties[i].hasOwnProperty("name") )
continue;
if ( ! b.customProperties[i].hasOwnProperty(propertyType) )
continue;
if ( b.customProperties[i].name == propertyName &&
b.customProperties[i][propertyType] == valueToMatch)
bodies.push(b);
}
}
return bodies;
}
function hasCustomProperty(item, propertyType, propertyName) {
if ( !item.hasOwnProperty('customProperties') )
return false;
for (var i = 0; i < item.customProperties.length; i++) {
if ( ! item.customProperties[i].hasOwnProperty("name") )
continue;
if ( ! item.customProperties[i].hasOwnProperty(propertyType) )
continue;
return true;
}
return false;
}
function getCustomProperty(item, propertyType, propertyName, defaultValue) {
if ( !item.hasOwnProperty('customProperties') )
return defaultValue;
for (var i = 0; i < item.customProperties.length; i++) {
if ( ! item.customProperties[i].hasOwnProperty("name") )
continue;
if ( ! item.customProperties[i].hasOwnProperty(propertyType) )
continue;
if ( item.customProperties[i].name == propertyName )
return item.customProperties[i][propertyType];
}
return defaultValue;
}

1379
lab/rube/js/ragdoll-min.js vendored Normal file

File diff suppressed because it is too large Load diff

40
lab/rube/js/ragdoll.js Normal file
View file

@ -0,0 +1,40 @@
var ragdoll = function() {
//constructor
}
ragdoll.prototype.setNiceViewCenter = function() {
//called once when the user changes to this test from another test
PTM = 70;
setViewCenterWorld( new b2Vec2(0, 1), true );
}
ragdoll.prototype.setup = function() {
//set up the Box2D scene here - the world is already created
var c = document.getElementById('canvas');
var ctx = c.getContext("2d");
if(ctx) {
ctx.imageSmoothingEnabled = false;
ctx.mozImageSmoothingEnabled = false;
ctx.webkitImageSmoothingEnabled = false;
}
setTimeout(function(){
document.getElementById('drawShapesCheck').checked = false;
updateWorldFromDebugDrawCheckboxes();
}, 10);
if ( loadSceneFromRUBE(ragdoll_scene) ) //jack_scene is defined in jack-min.js
console.log("RUBE scene loaded successfully.");
else
console.log("Failed to load RUBE scene");
doAfterLoading();
}
ragdoll.prototype.getComments = function(canvas, evt) {
return "Created in R.U.B.E editor. Pull the latch to the side to open the box.";
}

830
lab/rube/js/testbed.js Normal file
View file

@ -0,0 +1,830 @@
//Having to type 'Box2D.' in front of everything makes porting
//existing C++ code a pain in the butt. This function can be used
//to make everything in the Box2D namespace available without
//needing to do that.
/*function using(ns, pattern) {
if (pattern == undefined) {
// import all
for (var name in ns) {
//console.log(this[name]);
this[name] = ns[name];
}
} else {
if (typeof(pattern) == 'string') {
pattern = new RegExp(pattern);
}
// import only stuff matching given pattern
for (var name in ns) {
//console.log(name);
if (name.match(pattern)) {
//console.log(ns[name]);
this[name] = ns[name];
}
}
}
}*/
var e_shapeBit = 0x0001;
var e_jointBit = 0x0002;
var e_aabbBit = 0x0004;
var e_pairBit = 0x0008;
var e_centerOfMassBit = 0x0010;
var PTM = 32;
var world = null;
var mouseJointGroundBody;
var canvas;
var context;
var myDebugDraw;
var mouseDownQueryCallback;
var visibleFixturesQueryCallback;
var mouseJoint = null;
var run = true;
var frameTime60 = 0;
var statusUpdateCounter = 0;
var showStats = false;
var mouseDown = false;
var shiftDown = false;
var originTransform;
var mousePosPixel = {
x: 0,
y: 0
};
var prevMousePosPixel = {
x: 0,
y: 0
};
var mousePosWorld = {
x: 0,
y: 0
};
var canvasOffset = {
x: 0,
y: 0
};
var viewCenterPixel = {
x:320,
y:240
};
var viewAABB;
function myRound(val,places) {
var c = 1;
for (var i = 0; i < places; i++)
c *= 10;
return Math.round(val*c)/c;
}
function getWorldPointFromPixelPoint(pixelPoint) {
return {
x: (pixelPoint.x - canvasOffset.x)/PTM,
y: (pixelPoint.y - (canvas.height - canvasOffset.y))/PTM
};
}
function updateMousePos(canvas, evt) {
var rect = canvas.getBoundingClientRect();
mousePosPixel = {
x: evt.clientX - rect.left,
y: canvas.height - (evt.clientY - rect.top)
};
mousePosWorld = getWorldPointFromPixelPoint(mousePosPixel);
}
function setViewCenterWorld(b2vecpos, instantaneous) {
var currentViewCenterWorld = getWorldPointFromPixelPoint( viewCenterPixel );
var toMoveX = b2vecpos.x - currentViewCenterWorld.x;
var toMoveY = b2vecpos.y - currentViewCenterWorld.y;
var fraction = instantaneous ? 1 : 0.25;
canvasOffset.x -= myRound(fraction * toMoveX * PTM, 0);
canvasOffset.y += myRound(fraction * toMoveY * PTM, 0);
}
function onMouseMove(canvas, evt) {
prevMousePosPixel = mousePosPixel;
updateMousePos(canvas, evt);
updateStats();
if ( shiftDown ) {
canvasOffset.x += (mousePosPixel.x - prevMousePosPixel.x);
canvasOffset.y -= (mousePosPixel.y - prevMousePosPixel.y);
draw();
}
else if ( mouseDown && mouseJoint != null ) {
mouseJoint.SetTarget( new b2Vec2(mousePosWorld.x, mousePosWorld.y) );
}
}
var getBodyCB = function(fixture) {
if(fixture.GetBody().GetType() != Box2D.Dynamics.b2BodyDef.b2_staticBody) {
if(fixture.GetShape().TestPoint(fixture.GetBody().GetTransform(), mousePosWorld)) {
selectedBody = fixture.GetBody();
return false;
}
}
return true;
};
function startMouseJoint() {
if ( mouseJoint != null )
return;
// Make a small box.
var aabb = new b2AABB();
var d = 0.001;
aabb.lowerBound.Set(mousePosWorld.x - d, mousePosWorld.y - d);
aabb.upperBound.Set(mousePosWorld.x + d, mousePosWorld.y + d);
// Query the world for overlapping shapes.
mouseDownQueryCallback.m_fixture = null;
mouseDownQueryCallback.m_point.Set(mousePosWorld.x, mousePosWorld.y);
world.QueryAABB(mouseDownQueryCallback, aabb);
if (mouseDownQueryCallback.m_fixture)
{
var body = mouseDownQueryCallback.m_fixture.GetBody();
/*selectedBody = null;
world.QueryAABB(getBodyCB, aabb);
if (selectedBody)
{
var body = selectedBody;*/
var md = new b2MouseJointDef();
md.bodyA = mouseJointGroundBody;
md.bodyB = body;
md.target.Set(mousePosWorld.x, mousePosWorld.y);
md.maxForce = 1000 * body.GetMass();
md.collideConnected = true;
mouseJoint = world.CreateJoint(md);
body.SetAwake(true);
}
}
function onMouseDown(canvas, evt) {
updateMousePos(canvas, evt);
if ( !mouseDown )
startMouseJoint();
mouseDown = true;
updateStats();
}
function onMouseUp(canvas, evt) {
mouseDown = false;
updateMousePos(canvas, evt);
updateStats();
if ( mouseJoint != null ) {
world.DestroyJoint(mouseJoint);
mouseJoint = null;
}
}
function onMouseOut(canvas, evt) {
onMouseUp(canvas,evt);
}
function onKeyDown(canvas, evt) {
//console.log(evt.keyCode);
if ( evt.keyCode == 80 ) {//p
pause();
}
else if ( evt.keyCode == 82 ) {//r
resetScene();
}
else if ( evt.keyCode == 83 ) {//s
step();
}
else if ( evt.keyCode == 88 ) {//x
zoomIn();
}
else if ( evt.keyCode == 90 ) {//z
zoomOut();
}
else if ( evt.keyCode == 37 ) {//left
canvasOffset.x += 32;
}
else if ( evt.keyCode == 39 ) {//right
canvasOffset.x -= 32;
}
else if ( evt.keyCode == 38 ) {//up
canvasOffset.y += 32;
}
else if ( evt.keyCode == 40 ) {//down
canvasOffset.y -= 32;
}
else if ( evt.keyCode == 16 ) {//shift
shiftDown = true;
}
if ( window['currentTest'] && window['currentTest']['onKeyDown'] )
window['currentTest']['onKeyDown'](canvas, evt);
draw();
}
function onKeyUp(canvas, evt) {
if ( evt.keyCode == 16 ) {//shift
shiftDown = false;
}
if ( window['currentTest'] && window['currentTest']['onKeyUp'] )
window['currentTest']['onKeyUp'](canvas, evt);
}
function zoomIn() {
var currentViewCenterWorld = getWorldPointFromPixelPoint( viewCenterPixel );
PTM *= 1.1;
var newViewCenterWorld = getWorldPointFromPixelPoint( viewCenterPixel );
canvasOffset.x += (newViewCenterWorld.x-currentViewCenterWorld.x) * PTM;
canvasOffset.y -= (newViewCenterWorld.y-currentViewCenterWorld.y) * PTM;
draw();
}
function zoomOut() {
var currentViewCenterWorld = getWorldPointFromPixelPoint( viewCenterPixel );
PTM /= 1.1;
var newViewCenterWorld = getWorldPointFromPixelPoint( viewCenterPixel );
canvasOffset.x += (newViewCenterWorld.x-currentViewCenterWorld.x) * PTM;
canvasOffset.y -= (newViewCenterWorld.y-currentViewCenterWorld.y) * PTM;
draw();
}
function updateDebugDrawCheckboxesFromWorld() {
var flags = myDebugDraw.GetFlags();
document.getElementById('drawShapesCheck').checked = (( flags & e_shapeBit ) != 0);
document.getElementById('drawJointsCheck').checked = (( flags & e_jointBit ) != 0);
document.getElementById('drawAABBsCheck').checked = (( flags & e_aabbBit ) != 0);
//document.getElementById('drawPairsCheck').checked = (( flags & e_pairBit ) != 0);
document.getElementById('drawTransformsCheck').checked = (( flags & e_centerOfMassBit ) != 0);
}
function updateWorldFromDebugDrawCheckboxes() {
var flags = 0;
if ( document.getElementById('drawShapesCheck').checked )
flags |= e_shapeBit;
if ( document.getElementById('drawJointsCheck').checked )
flags |= e_jointBit;
if ( document.getElementById('drawAABBsCheck').checked )
flags |= e_aabbBit;
/*if ( document.getElementById('drawPairsCheck').checked )
flags |= e_pairBit;*/
if ( document.getElementById('drawTransformsCheck').checked )
flags |= e_centerOfMassBit;
myDebugDraw.SetFlags( flags );
}
function updateContinuousRefreshStatus() {
showStats = ( document.getElementById('showStatsCheck').checked );
if ( !showStats ) {
var fbSpan = document.getElementById('feedbackSpan');
fbSpan.innerHTML = "";
}
else
updateStats();
}
function init() {
canvas = document.getElementById("canvas");
context = canvas.getContext( '2d' );
canvasOffset.x = canvas.width/2;
canvasOffset.y = canvas.height/2;
canvas.addEventListener('mousemove', function(evt) {
onMouseMove(canvas,evt);
}, false);
canvas.addEventListener('mousedown', function(evt) {
onMouseDown(canvas,evt);
}, false);
canvas.addEventListener('mouseup', function(evt) {
onMouseUp(canvas,evt);
}, false);
canvas.addEventListener('mouseout', function(evt) {
onMouseOut(canvas,evt);
}, false);
canvas.addEventListener('keydown', function(evt) {
onKeyDown(canvas,evt);
}, false);
canvas.addEventListener('keyup', function(evt) {
onKeyUp(canvas,evt);
}, false);
myDebugDraw = new b2DebugDraw();
myDebugDraw.SetSprite(document.getElementById("canvas").getContext("2d"));
myDebugDraw.SetDrawScale(1.0);
myDebugDraw.SetFillAlpha(0.5);
myDebugDraw.SetLineThickness(1.0);
myDebugDraw.SetXFormScale(0.25);
myDebugDraw.SetFlags(b2DebugDraw.e_shapeBit /*| b2DebugDraw.e_jointBit*/);
originTransform = new b2Transform();
var MouseDownQueryCallback = function() {
this.m_fixture = null;
this.m_point = new b2Vec2();
}
MouseDownQueryCallback.prototype.ReportFixture = function(fixture) {
if(fixture.GetBody().GetType() == 2) { //dynamic bodies only
if ( fixture.TestPoint(this.m_point) ) {
this.m_fixture = fixture;
return false;
}
}
return true;
};
mouseDownQueryCallback = new MouseDownQueryCallback();
var VisibleFixturesQueryCallback = function() {
this.m_fixtures = [];
}
VisibleFixturesQueryCallback.prototype.ReportFixture = function(fixture) {
this.m_fixtures.push(fixture);
return true;
};
viewAABB = new b2AABB();
visibleFixturesQueryCallback = new VisibleFixturesQueryCallback();
}
function changeTest() {
resetScene();
if ( window['currentTest'] && window['currentTest']['setNiceViewCenter'] )
window['currentTest']['setNiceViewCenter']();
updateDebugDrawCheckboxesFromWorld();
draw();
}
function createWorld() {
var sceneInfoDiv = document.getElementById('sceneinfo');
var commentsDiv = document.getElementById('testcomments');
sceneInfoDiv.innerHTML = "Loading...";
commentsDiv.innerHTML = "";
if ( world != null )
//Box2D.destroy(world);
world = null;
world = new b2World( new b2Vec2(0.0, -10.0) );
//world = new Box2D.Dynamics.b2World(new Box2D.Common.Math.b2Vec2(0, 9.8) /* gravity */, true /* allowSleep */);
world.SetDebugDraw(myDebugDraw);
mouseJointGroundBody = world.CreateBody( new b2BodyDef() );
var e = document.getElementById("testSelection");
var v = e.options[e.selectedIndex].value;
eval( "window['currentTest']= new "+v+"();" );
window['currentTest']['setup']();
}
function getWorldInfo() {
var numBodies = 0;
var numFixtures = 0;
var numJoints = 0;
for (b = world.m_bodyList; b; b = b.m_next) {
numBodies++;
for (f = b.m_fixtureList; f; f = f.m_next)
numFixtures++;
}
for (j = world.m_jointList; j; j = j.m_next)
numJoints++;
return ""+numBodies+" bodies, "+numFixtures+" fixtures, "+numJoints+" joints";
}
var resettingScene = false;
function resetScene() {
resettingScene = true;
createWorld();
draw();
}
//the RUBE scenes are loaded via jQuery post, so the draw() call above usually
//does not catch them. Call this at the end of the post function.
function doAfterLoading() {
if ( world.images ) {
for (var i = 0; i < world.images.length; i++) {
var imageObj = new Image();
imageObj.src = world.images[i].file;
world.images[i].imageObj = imageObj;
}
}
var sceneInfoDiv = document.getElementById('sceneinfo');
sceneInfoDiv.innerHTML = "Scene info: "+getWorldInfo();;
var comments = "";
if ( window['currentTest']['getComments'] )
comments = window['currentTest']['getComments']();
var commentsDiv = document.getElementById('testcomments');
commentsDiv.innerHTML = "About: "+comments;
resettingScene = false;
draw();
}
function step(timestamp) {
if ( resettingScene )
return;
if ( window['currentTest'] && window['currentTest']['step'] )
window['currentTest']['step']();
if ( ! showStats ) {
world.Step(1/60, 10, 6);
draw();
//logBodyPositions();
return;
}
var current = Date.now();
world.Step(1/60, 10, 6);
var frametime = (Date.now() - current);
frameTime60 = frameTime60 * (59/60) + frametime * (1/60);
draw();
statusUpdateCounter++;
if ( statusUpdateCounter > 20 ) {
updateStats();
statusUpdateCounter = 0;
}
}
function setColorFromBodyType(color, b) {
if (b.IsActive() == false)
color.Set(0.5, 0.5, 0.3);
else if (b.GetType() == b2_staticBody)
color.Set(0.5, 0.9, 0.5);
else if (b.GetType() == b2_kinematicBody)
color.Set(0.5, 0.5, 0.9);
else if (b.IsAwake() == false)
color.Set(0.6, 0.6, 0.6);
else
color.Set(0.9, 0.7, 0.7);
}
//for drawing polygons as one path
function drawLinePolygon(poly, xf) {
var vertexCount = parseInt(poly.GetVertexCount());
var localVertices = poly.GetVertices();
var vertices = new Vector(vertexCount);
for (var i = 0; i < vertexCount; ++i) {
vertices[i] = b2Math.MulX(xf, localVertices[i]);
}
var drawScale = myDebugDraw.m_drawScale;
context.moveTo(vertices[0].x * drawScale, vertices[0].y * drawScale);
for (var i = 1; i < vertexCount; i++) {
context.lineTo(vertices[i].x * drawScale, vertices[i].y * drawScale);
}
context.lineTo(vertices[0].x * drawScale, vertices[0].y * drawScale);
}
function draw() {
//black background
context.fillStyle = 'rgb(0,0,0)';
context.fillRect( 0, 0, canvas.width, canvas.height );
context.save();
context.translate(canvasOffset.x, canvasOffset.y);
context.scale(1,-1);
context.scale(PTM,PTM);
context.lineWidth /= PTM;
//draw images
context.save();
context.scale(1,-1);
if ( world.images ) {
for (var i = 0; i < world.images.length; i++) {
var imageObj = world.images[i].imageObj;
context.save();
if ( world.images[i].body ) {
//body position in world
var bodyPos = world.images[i].body.GetPosition();
context.translate(bodyPos.x, -bodyPos.y);
context.rotate(-world.images[i].body.GetAngle());
//image position in body
var imageLocalCenter = world.images[i].center;
context.translate(imageLocalCenter.x, -imageLocalCenter.y);
context.rotate(-world.images[i].angle);
}
var ratio = 1 / imageObj.height;
ratio *= world.images[i].scale;
context.scale(ratio, ratio);
context.translate(-imageObj.width / 2, -imageObj.height / 2);
context.drawImage(imageObj, 0, 0);
context.restore();
}
}
context.restore();
myDebugDraw.DrawTransform(originTransform);
var flags = myDebugDraw.GetFlags();
myDebugDraw.SetFlags(flags & ~e_shapeBit);
world.DrawDebugData();
myDebugDraw.SetFlags(flags);
if (( flags & e_shapeBit ) != 0) {
//query the world for visible fixtures
var currentViewCenterWorld = getWorldPointFromPixelPoint( viewCenterPixel );
var viewHalfwidth = 0.5 * canvas.width / PTM;
var viewHalfheight = 0.5 * canvas.height / PTM;
viewAABB.lowerBound.Set(currentViewCenterWorld.x - viewHalfwidth, currentViewCenterWorld.y - viewHalfheight);
viewAABB.upperBound.Set(currentViewCenterWorld.x + viewHalfwidth, currentViewCenterWorld.y + viewHalfheight);
visibleFixturesQueryCallback.m_fixtures = [];
world.QueryAABB(visibleFixturesQueryCallback, viewAABB);
var f, b, xf, s;
var color = new b2Color(0, 0, 0);
var circleFixtures = [];
var polygonFixtures = [];
var staticPolygonFixtures = [];
var kinematicPolygonFixtures = [];
var dynamicPolygonFixtures = [];
for (var i = 0; i < visibleFixturesQueryCallback.m_fixtures.length; i++) {
f = visibleFixturesQueryCallback.m_fixtures[i];
s = f.GetShape();
if ( s.GetType() == b2Shape.e_circleShape ) {
circleFixtures.push(f);
}
else if ( s.GetType() == b2Shape.e_polygonShape ) {
polygonFixtures.push(f);
}
}
for (var i = 0; i < circleFixtures.length; i++) {
f = circleFixtures[i];
s = f.GetShape();
b = f.GetBody();
xf = b.GetTransform();
setColorFromBodyType(color, b);
world.DrawShape(s, xf, color);
}
for (var i = 0; i < polygonFixtures.length; i++) {
f = polygonFixtures[i];
b = f.GetBody();
if (b.GetType() == b2_staticBody)
staticPolygonFixtures.push(f);
else if (b.GetType() == b2_kinematicBody)
kinematicPolygonFixtures.push(f);
else
dynamicPolygonFixtures.push(f);
}
context.strokeStyle = "rgb(128,230,128)";
context.beginPath();//draw all static polygons as one path
for (var i = 0; i < staticPolygonFixtures.length; i++) {
f = staticPolygonFixtures[i];
s = f.GetShape();
b = f.GetBody();
xf = b.GetTransform();
//world.DrawShape(s, xf, color);
drawLinePolygon(s, xf);
}
context.closePath();
context.stroke();
context.strokeStyle = "rgb(128,128,230)";
context.beginPath();//draw all kinematic polygons as one path
for (var i = 0; i < kinematicPolygonFixtures.length; i++) {
f = kinematicPolygonFixtures[i];
s = f.GetShape();
b = f.GetBody();
xf = b.GetTransform();
//world.DrawShape(s, xf, color);
drawLinePolygon(s, xf);
}
context.closePath();
context.stroke();
context.strokeStyle = "rgb(230,178,178)";
context.beginPath();//draw all dynamic polygons as one path
for (var i = 0; i < dynamicPolygonFixtures.length; i++) {
f = dynamicPolygonFixtures[i];
s = f.GetShape();
b = f.GetBody();
xf = b.GetTransform();
//world.DrawShape(s, xf, color);
drawLinePolygon(s, xf);
}
context.closePath();
context.stroke();
}
if ( mouseJoint != null ) {
//mouse joint is not drawn with regular joints in debug draw
var p1 = mouseJoint.GetAnchorB();
var p2 = mouseJoint.GetTarget();
context.strokeStyle = 'rgb(204,204,204)';
context.beginPath();
context.moveTo(p1.x,p1.y);
context.lineTo(p2.x,p2.y);
context.stroke();
}
context.restore();
}
function updateStats() {
if ( ! showStats )
return;
var currentViewCenterWorld = getWorldPointFromPixelPoint( viewCenterPixel );
var fbSpan = document.getElementById('feedbackSpan');
fbSpan.innerHTML =
"Status: "+(run?'running':'paused') +
"<br>Physics step time (average of last 60 steps): "+myRound(frameTime60,2)+"ms" +
//"<br>Mouse down: "+mouseDown +
"<br>PTM: "+myRound(PTM,2) +
"<br>View center: "+myRound(currentViewCenterWorld.x,3)+", "+myRound(currentViewCenterWorld.y,3) +
//"<br>Canvas offset: "+myRound(canvasOffset.x,0)+", "+myRound(canvasOffset.y,0) +
"<br>Mouse pos (pixel): "+mousePosPixel.x+", "+mousePosPixel.y +
"<br>Mouse pos (world): "+myRound(mousePosWorld.x,3)+", "+myRound(mousePosWorld.y,3);
}
window.requestAnimFrame = (function(){
return window.requestAnimationFrame ||
window.webkitRequestAnimationFrame ||
window.mozRequestAnimationFrame ||
window.oRequestAnimationFrame ||
window.msRequestAnimationFrame ||
function( callback ){
window.setTimeout(callback, 1000 / 60);
};
})();
function animate() {
if ( run )
requestAnimFrame( animate );
step();
}
function pause() {
run = !run;
if (run)
animate();
updateStats();
}
//console.log(A.a);
//console.log(Box2D.Dynamics);
//console.log(Box2D.Dynamics.b2BodyDef);
var b2CircleShape = Box2D.Collision.Shapes.b2CircleShape,
b2EdgeChainDef = Box2D.Collision.Shapes.b2EdgeChainDef,
b2EdgeShape = Box2D.Collision.Shapes.b2EdgeShape,
b2MassData = Box2D.Collision.Shapes.b2MassData,
b2PolygonShape = Box2D.Collision.Shapes.b2PolygonShape,
b2Shape = Box2D.Collision.Shapes.b2Shape,
b2CircleContact = Box2D.Dynamics.Contacts.b2CircleContact,
b2Contact = Box2D.Dynamics.Contacts.b2Contact,
b2ContactConstraint = Box2D.Dynamics.Contacts.b2ContactConstraint,
b2ContactConstraintPoint = Box2D.Dynamics.Contacts.b2ContactConstraintPoint,
b2ContactEdge = Box2D.Dynamics.Contacts.b2ContactEdge,
b2ContactFactory = Box2D.Dynamics.Contacts.b2ContactFactory,
b2ContactRegister = Box2D.Dynamics.Contacts.b2ContactRegister,
b2ContactResult = Box2D.Dynamics.Contacts.b2ContactResult,
b2ContactSolver = Box2D.Dynamics.Contacts.b2ContactSolver,
b2EdgeAndCircleContact = Box2D.Dynamics.Contacts.b2EdgeAndCircleContact,
b2NullContact = Box2D.Dynamics.Contacts.b2NullContact,
b2PolyAndCircleContact = Box2D.Dynamics.Contacts.b2PolyAndCircleContact,
b2PolyAndEdgeContact = Box2D.Dynamics.Contacts.b2PolyAndEdgeContact,
b2PolygonContact = Box2D.Dynamics.Contacts.b2PolygonContact,
b2PositionSolverManifold = Box2D.Dynamics.Contacts.b2PositionSolverManifold,
b2Body = Box2D.Dynamics.b2Body,
b2_staticBody = Box2D.Dynamics.b2Body.b2_staticBody,
b2_kinematicBody = Box2D.Dynamics.b2Body.b2_kinematicBody,
b2_dynamicBody = Box2D.Dynamics.b2Body.b2_dynamicBody,
b2BodyDef = Box2D.Dynamics.b2BodyDef,
b2ContactFilter = Box2D.Dynamics.b2ContactFilter,
b2ContactImpulse = Box2D.Dynamics.b2ContactImpulse,
b2ContactListener = Box2D.Dynamics.b2ContactListener,
b2ContactManager = Box2D.Dynamics.b2ContactManager,
b2DebugDraw = Box2D.Dynamics.b2DebugDraw,
b2DestructionListener = Box2D.Dynamics.b2DestructionListener,
b2FilterData = Box2D.Dynamics.b2FilterData,
b2Fixture = Box2D.Dynamics.b2Fixture,
b2FixtureDef = Box2D.Dynamics.b2FixtureDef,
b2Island = Box2D.Dynamics.b2Island,
b2TimeStep = Box2D.Dynamics.b2TimeStep,
b2World = Box2D.Dynamics.b2World,
b2Color = Box2D.Common.b2Color,
b2internal = Box2D.Common.b2internal,
b2Settings = Box2D.Common.b2Settings,
b2Mat22 = Box2D.Common.Math.b2Mat22,
b2Mat33 = Box2D.Common.Math.b2Mat33,
b2Math = Box2D.Common.Math.b2Math,
b2Sweep = Box2D.Common.Math.b2Sweep,
b2Transform = Box2D.Common.Math.b2Transform,
b2Vec2 = Box2D.Common.Math.b2Vec2,
b2Vec3 = Box2D.Common.Math.b2Vec3,
b2AABB = Box2D.Collision.b2AABB,
b2Bound = Box2D.Collision.b2Bound,
b2BoundValues = Box2D.Collision.b2BoundValues,
b2Collision = Box2D.Collision.b2Collision,
b2ContactID = Box2D.Collision.b2ContactID,
b2ContactPoint = Box2D.Collision.b2ContactPoint,
b2Distance = Box2D.Collision.b2Distance,
b2DistanceInput = Box2D.Collision.b2DistanceInput,
b2DistanceOutput = Box2D.Collision.b2DistanceOutput,
b2DistanceProxy = Box2D.Collision.b2DistanceProxy,
b2DynamicTree = Box2D.Collision.b2DynamicTree,
b2DynamicTreeBroadPhase = Box2D.Collision.b2DynamicTreeBroadPhase,
b2DynamicTreeNode = Box2D.Collision.b2DynamicTreeNode,
b2DynamicTreePair = Box2D.Collision.b2DynamicTreePair,
b2Manifold = Box2D.Collision.b2Manifold,
b2ManifoldPoint = Box2D.Collision.b2ManifoldPoint,
b2Point = Box2D.Collision.b2Point,
b2RayCastInput = Box2D.Collision.b2RayCastInput,
b2RayCastOutput = Box2D.Collision.b2RayCastOutput,
b2Segment = Box2D.Collision.b2Segment,
b2SeparationFunction = Box2D.Collision.b2SeparationFunction,
b2Simplex = Box2D.Collision.b2Simplex,
b2SimplexCache = Box2D.Collision.b2SimplexCache,
b2SimplexVertex = Box2D.Collision.b2SimplexVertex,
b2TimeOfImpact = Box2D.Collision.b2TimeOfImpact,
b2TOIInput = Box2D.Collision.b2TOIInput,
b2WorldManifold = Box2D.Collision.b2WorldManifold,
ClipVertex = Box2D.Collision.ClipVertex,
Features = Box2D.Collision.Features,
IBroadPhase = Box2D.Collision.IBroadPhase,
b2Joint = Box2D.Dynamics.Joints.b2Joint,
b2JointDef = Box2D.Dynamics.Joints.b2JointDef,
b2JointEdge = Box2D.Dynamics.Joints.b2JointEdge,
b2LineJoint = Box2D.Dynamics.Joints.b2LineJoint,
b2LineJointDef = Box2D.Dynamics.Joints.b2LineJointDef,
b2MouseJoint = Box2D.Dynamics.Joints.b2MouseJoint,
b2MouseJointDef = Box2D.Dynamics.Joints.b2MouseJointDef,
b2PrismaticJoint = Box2D.Dynamics.Joints.b2PrismaticJoint,
b2PrismaticJointDef = Box2D.Dynamics.Joints.b2PrismaticJointDef,
b2PulleyJoint = Box2D.Dynamics.Joints.b2PulleyJoint,
b2PulleyJointDef = Box2D.Dynamics.Joints.b2PulleyJointDef,
b2RevoluteJoint = Box2D.Dynamics.Joints.b2RevoluteJoint,
b2RevoluteJointDef = Box2D.Dynamics.Joints.b2RevoluteJointDef,
b2WeldJoint = Box2D.Dynamics.Joints.b2WeldJoint,
b2WeldJointDef = Box2D.Dynamics.Joints.b2WeldJointDef,
b2DistanceJoint = Box2D.Dynamics.Joints.b2DistanceJoint,
b2DistanceJointDef = Box2D.Dynamics.Joints.b2DistanceJointDef,
b2FrictionJoint = Box2D.Dynamics.Joints.b2FrictionJoint,
b2FrictionJointDef = Box2D.Dynamics.Joints.b2FrictionJointDef;
window['onload'] = function doOnload() {
/*
using(Box2D.Common, "b2.+");
using(Box2D.Common.Math, "b2.+");
using(Box2D.Collision, "b2.+");
using(Box2D.Collision.Shapes, "b2.+");
using(Box2D.Dynamics, "b2.+");
using(Box2D.Dynamics.Joints, "b2.+");
using(Box2D.Dynamics.b2Body, "b2.+");//b2_dynamicBody etc
*/
init();
changeTest();
animate();
}
//these need to be kept global for closure advanced optimization
window['currentTest'] = null;
//window['Box2D'] = Box2D;
/*
String.prototype.endsWith = function(suffix) {
return this.indexOf(suffix, this.length - suffix.length) !== -1;
};
function ttt(ns, recurse) {
if ( typeof recurse === 'undefined' ) recurse = true;
var parts = ns.split(".");
var base = "window";
for (i=0;i<parts.length;i++)
base += "['"+parts[i]+"']";
//if ( ns.endsWith('prototype') )
// recurse = false;
for (var name in eval(ns)) {
console.log(base+"['"+name+"'] = "+ns+"."+name+";");
//if ( typeof eval(ns+"."+name) == 'function' ) {
if ( recurse )
ttt(ns+"."+name+".prototype", true);
//}
}
}
//ttt('Box2D.Collision');
//ttt('Box2D.Collision.Shapes');
//ttt('Box2D.Common');
//ttt('Box2D.Common.Math');
//ttt('Box2D.Dynamics');
//ttt('Box2D.Dynamics.Contacts');
//ttt('Box2D.Dynamics.Joints');
*/

Binary file not shown.

Before

Width:  |  Height:  |  Size: 306 B

After

Width:  |  Height:  |  Size: 2.9 KiB

Before After
Before After

BIN
static/img/Characters/Chuck/upperLeftLeg.png Executable file → Normal file

Binary file not shown.

Before

Width:  |  Height:  |  Size: 144 B

After

Width:  |  Height:  |  Size: 2.8 KiB

Before After
Before After

BIN
static/img/Characters/Chuck/upperRightLeg.png Executable file → Normal file

Binary file not shown.

Before

Width:  |  Height:  |  Size: 144 B

After

Width:  |  Height:  |  Size: 2.8 KiB

Before After
Before After

View file

@ -239,28 +239,6 @@
"width":0,
"x":543.000000000001,
"y":384.333333333333
},
{
"height":0,
"name":"",
"properties":
{
"category":"graveyard",
"grabAngle":"-0.3",
"height":"12",
"image":"chest.png",
"name":"RagDoll",
"rotation":"0",
"type":"ragdoll",
"weight":"3",
"width":"5"
},
"rotation":0,
"type":"",
"visible":true,
"width":0,
"x":244,
"y":388
}],
"opacity":1,
"type":"objectgroup",

View file

@ -0,0 +1,672 @@
//Source code dump of Box2D scene: ragdoll.rube
//
// Created by R.U.B.E 1.5.4
// Using Box2D version 2.3.0
// Sun February 16 2014 21:04:35
//
// This code is originally intended for use in the Box2D testbed,
// but you can easily use it in other applications by providing
// a b2World for use as the 'm_world' variable in the code below.
b2Vec2 g(0.000000000000000e+00f, -1.000000000000000e+01f);
m_world->SetGravity(g);
b2Body** bodies = (b2Body**)b2Alloc(11 * sizeof(b2Body*));
b2Joint** joints = (b2Joint**)b2Alloc(9 * sizeof(b2Joint*));
{
b2BodyDef bd;
bd.type = b2BodyType(2);
bd.position.Set(-1.917114257812500e-01f, 1.433728694915771e+00f);
bd.angle = 0.000000000000000e+00f;
bd.linearVelocity.Set(0.000000000000000e+00f, 0.000000000000000e+00f);
bd.angularVelocity = 0.000000000000000e+00f;
bd.linearDamping = 0.000000000000000e+00f;
bd.angularDamping = 0.000000000000000e+00f;
bd.allowSleep = bool(4);
bd.awake = bool(2);
bd.fixedRotation = bool(0);
bd.bullet = bool(0);
bd.active = bool(32);
bd.gravityScale = 1.000000000000000e+00f;
bodies[0] = m_world->CreateBody(&bd);
{
b2FixtureDef fd;
fd.friction = 2.000000029802322e-01f;
fd.restitution = 0.000000000000000e+00f;
fd.density = 1.000000000000000e+00f;
fd.isSensor = bool(0);
fd.filter.categoryBits = uint16(1);
fd.filter.maskBits = uint16(65535);
fd.filter.groupIndex = int16(-1);
b2PolygonShape shape;
b2Vec2 vs[8];
vs[0].Set(6.299880146980286e-02f, -2.545155882835388e-01f);
vs[1].Set(6.299880146980286e-02f, 2.545149326324463e-01f);
vs[2].Set(-6.299890577793121e-02f, 2.545149326324463e-01f);
vs[3].Set(-6.299890577793121e-02f, -2.545155882835388e-01f);
shape.Set(vs, 4);
fd.shape = &shape;
bodies[0]->CreateFixture(&fd);
}
}
{
b2BodyDef bd;
bd.type = b2BodyType(2);
bd.position.Set(-6.397294998168945e-02f, 1.267420768737793e+00f);
bd.angle = 0.000000000000000e+00f;
bd.linearVelocity.Set(0.000000000000000e+00f, 0.000000000000000e+00f);
bd.angularVelocity = 0.000000000000000e+00f;
bd.linearDamping = 0.000000000000000e+00f;
bd.angularDamping = 0.000000000000000e+00f;
bd.allowSleep = bool(4);
bd.awake = bool(2);
bd.fixedRotation = bool(0);
bd.bullet = bool(0);
bd.active = bool(32);
bd.gravityScale = 1.000000000000000e+00f;
bodies[1] = m_world->CreateBody(&bd);
{
b2FixtureDef fd;
fd.friction = 2.000000029802322e-01f;
fd.restitution = 0.000000000000000e+00f;
fd.density = 1.000000000000000e+00f;
fd.isSensor = bool(0);
fd.filter.categoryBits = uint16(1);
fd.filter.maskBits = uint16(65535);
fd.filter.groupIndex = int16(-1);
b2PolygonShape shape;
b2Vec2 vs[8];
vs[0].Set(1.883362084627151e-01f, -4.305148720741272e-01f);
vs[1].Set(1.846363544464111e-01f, 5.393795371055603e-01f);
vs[2].Set(1.850083470344543e-03f, 5.393795371055603e-01f);
vs[3].Set(-1.883361339569092e-01f, 4.209862351417542e-01f);
vs[4].Set(-1.883361339569092e-01f, -4.607573151588440e-01f);
vs[5].Set(1.600667834281921e-03f, -4.952520132064819e-01f);
shape.Set(vs, 6);
fd.shape = &shape;
bodies[1]->CreateFixture(&fd);
}
{
b2FixtureDef fd;
fd.friction = 2.000000029802322e-01f;
fd.restitution = 0.000000000000000e+00f;
fd.density = 1.000000000000000e+00f;
fd.isSensor = bool(0);
fd.filter.categoryBits = uint16(1);
fd.filter.maskBits = uint16(65535);
fd.filter.groupIndex = int16(-1);
b2PolygonShape shape;
b2Vec2 vs[8];
vs[0].Set(1.840525716543198e-01f, 4.875739216804504e-01f);
vs[1].Set(1.840525716543198e-01f, 6.762337088584900e-01f);
vs[2].Set(-4.607129842042923e-03f, 6.762337088584900e-01f);
vs[3].Set(-4.607129842042923e-03f, 4.875739216804504e-01f);
shape.Set(vs, 4);
fd.shape = &shape;
bodies[1]->CreateFixture(&fd);
}
}
{
b2BodyDef bd;
bd.type = b2BodyType(2);
bd.position.Set(4.118728637695312e-02f, 2.199305295944214e+00f);
bd.angle = 0.000000000000000e+00f;
bd.linearVelocity.Set(0.000000000000000e+00f, 0.000000000000000e+00f);
bd.angularVelocity = 0.000000000000000e+00f;
bd.linearDamping = 0.000000000000000e+00f;
bd.angularDamping = 0.000000000000000e+00f;
bd.allowSleep = bool(4);
bd.awake = bool(2);
bd.fixedRotation = bool(0);
bd.bullet = bool(0);
bd.active = bool(32);
bd.gravityScale = 1.000000000000000e+00f;
bodies[2] = m_world->CreateBody(&bd);
{
b2FixtureDef fd;
fd.friction = 2.000000029802322e-01f;
fd.restitution = 0.000000000000000e+00f;
fd.density = 2.204959988594055e-01f;
fd.isSensor = bool(0);
fd.filter.categoryBits = uint16(1);
fd.filter.maskBits = uint16(65535);
fd.filter.groupIndex = int16(-1);
b2CircleShape shape;
shape.m_radius = 3.009769916534424e-01f;
shape.m_p.Set(-8.219080045819283e-03f, 4.109379835426807e-03f);
fd.shape = &shape;
bodies[2]->CreateFixture(&fd);
}
{
b2FixtureDef fd;
fd.friction = 2.000000029802322e-01f;
fd.restitution = 0.000000000000000e+00f;
fd.density = 2.204959988594055e-01f;
fd.isSensor = bool(0);
fd.filter.categoryBits = uint16(1);
fd.filter.maskBits = uint16(65535);
fd.filter.groupIndex = int16(-1);
b2CircleShape shape;
shape.m_radius = 2.723909914493561e-01f;
shape.m_p.Set(-3.647049888968468e-02f, -1.517499983310699e-01f);
fd.shape = &shape;
bodies[2]->CreateFixture(&fd);
}
}
{
b2BodyDef bd;
bd.type = b2BodyType(2);
bd.position.Set(1.235442161560059e-01f, 1.142371892929077e+00f);
bd.angle = 0.000000000000000e+00f;
bd.linearVelocity.Set(0.000000000000000e+00f, 0.000000000000000e+00f);
bd.angularVelocity = 0.000000000000000e+00f;
bd.linearDamping = 0.000000000000000e+00f;
bd.angularDamping = 0.000000000000000e+00f;
bd.allowSleep = bool(4);
bd.awake = bool(2);
bd.fixedRotation = bool(0);
bd.bullet = bool(0);
bd.active = bool(32);
bd.gravityScale = 1.000000000000000e+00f;
bodies[3] = m_world->CreateBody(&bd);
{
b2FixtureDef fd;
fd.friction = 2.000000029802322e-01f;
fd.restitution = 0.000000000000000e+00f;
fd.density = 1.000000000000000e+00f;
fd.isSensor = bool(0);
fd.filter.categoryBits = uint16(1);
fd.filter.maskBits = uint16(65535);
fd.filter.groupIndex = int16(-1);
b2PolygonShape shape;
b2Vec2 vs[8];
vs[0].Set(6.299892067909241e-02f, -1.556134223937988e-01f);
vs[1].Set(6.299892067909241e-02f, 1.556134223937988e-01f);
vs[2].Set(-6.299898028373718e-02f, 1.556134223937988e-01f);
vs[3].Set(-6.299898028373718e-02f, -1.556134223937988e-01f);
shape.Set(vs, 4);
fd.shape = &shape;
bodies[3]->CreateFixture(&fd);
}
}
{
b2BodyDef bd;
bd.type = b2BodyType(2);
bd.position.Set(-9.663248062133789e-02f, 3.554300665855408e-01f);
bd.angle = 0.000000000000000e+00f;
bd.linearVelocity.Set(0.000000000000000e+00f, 0.000000000000000e+00f);
bd.angularVelocity = 0.000000000000000e+00f;
bd.linearDamping = 0.000000000000000e+00f;
bd.angularDamping = 0.000000000000000e+00f;
bd.allowSleep = bool(4);
bd.awake = bool(2);
bd.fixedRotation = bool(0);
bd.bullet = bool(0);
bd.active = bool(32);
bd.gravityScale = 1.000000000000000e+00f;
bodies[4] = m_world->CreateBody(&bd);
{
b2FixtureDef fd;
fd.friction = 2.000000029802322e-01f;
fd.restitution = 0.000000000000000e+00f;
fd.density = 1.000000000000000e+00f;
fd.isSensor = bool(0);
fd.filter.categoryBits = uint16(1);
fd.filter.maskBits = uint16(65535);
fd.filter.groupIndex = int16(-1);
b2PolygonShape shape;
b2Vec2 vs[8];
vs[0].Set(1.550966501235962e-01f, -1.253567039966583e-01f);
vs[1].Set(1.550966501235962e-01f, -6.225190684199333e-02f);
vs[2].Set(-9.268096834421158e-02f, -6.225190684199333e-02f);
vs[3].Set(-9.268096834421158e-02f, -1.253567039966583e-01f);
shape.Set(vs, 4);
fd.shape = &shape;
bodies[4]->CreateFixture(&fd);
}
{
b2FixtureDef fd;
fd.friction = 2.000000029802322e-01f;
fd.restitution = 0.000000000000000e+00f;
fd.density = 1.000000000000000e+00f;
fd.isSensor = bool(0);
fd.filter.categoryBits = uint16(1);
fd.filter.maskBits = uint16(65535);
fd.filter.groupIndex = int16(-1);
b2PolygonShape shape;
b2Vec2 vs[8];
vs[0].Set(9.449840337038040e-02f, -1.247676759958267e-01f);
vs[1].Set(9.449840337038040e-02f, 1.715210527181625e-01f);
vs[2].Set(-9.449829906225204e-02f, 1.715210527181625e-01f);
vs[3].Set(-9.449829906225204e-02f, -1.247676759958267e-01f);
shape.Set(vs, 4);
fd.shape = &shape;
bodies[4]->CreateFixture(&fd);
}
}
{
b2BodyDef bd;
bd.type = b2BodyType(2);
bd.position.Set(-1.917138099670410e-01f, 1.142371892929077e+00f);
bd.angle = 0.000000000000000e+00f;
bd.linearVelocity.Set(0.000000000000000e+00f, 0.000000000000000e+00f);
bd.angularVelocity = 0.000000000000000e+00f;
bd.linearDamping = 0.000000000000000e+00f;
bd.angularDamping = 0.000000000000000e+00f;
bd.allowSleep = bool(4);
bd.awake = bool(2);
bd.fixedRotation = bool(0);
bd.bullet = bool(0);
bd.active = bool(32);
bd.gravityScale = 1.000000000000000e+00f;
bodies[5] = m_world->CreateBody(&bd);
{
b2FixtureDef fd;
fd.friction = 2.000000029802322e-01f;
fd.restitution = 0.000000000000000e+00f;
fd.density = 1.000000000000000e+00f;
fd.isSensor = bool(0);
fd.filter.categoryBits = uint16(1);
fd.filter.maskBits = uint16(65535);
fd.filter.groupIndex = int16(-1);
b2PolygonShape shape;
b2Vec2 vs[8];
vs[0].Set(6.299891322851181e-02f, -1.556134223937988e-01f);
vs[1].Set(6.299891322851181e-02f, 1.556134223937988e-01f);
vs[2].Set(-6.299878656864166e-02f, 1.556134223937988e-01f);
vs[3].Set(-6.299878656864166e-02f, -1.556134223937988e-01f);
shape.Set(vs, 4);
fd.shape = &shape;
bodies[5]->CreateFixture(&fd);
}
}
{
b2BodyDef bd;
bd.type = b2BodyType(2);
bd.position.Set(1.235442161560059e-01f, 1.433728694915771e+00f);
bd.angle = 0.000000000000000e+00f;
bd.linearVelocity.Set(0.000000000000000e+00f, 0.000000000000000e+00f);
bd.angularVelocity = 0.000000000000000e+00f;
bd.linearDamping = 0.000000000000000e+00f;
bd.angularDamping = 0.000000000000000e+00f;
bd.allowSleep = bool(4);
bd.awake = bool(2);
bd.fixedRotation = bool(0);
bd.bullet = bool(0);
bd.active = bool(32);
bd.gravityScale = 1.000000000000000e+00f;
bodies[6] = m_world->CreateBody(&bd);
{
b2FixtureDef fd;
fd.friction = 2.000000029802322e-01f;
fd.restitution = 0.000000000000000e+00f;
fd.density = 1.000000000000000e+00f;
fd.isSensor = bool(0);
fd.filter.categoryBits = uint16(1);
fd.filter.maskBits = uint16(65535);
fd.filter.groupIndex = int16(-1);
b2PolygonShape shape;
b2Vec2 vs[8];
vs[0].Set(6.299892067909241e-02f, -2.545155882835388e-01f);
vs[1].Set(6.299892067909241e-02f, 2.545149326324463e-01f);
vs[2].Set(-6.299898028373718e-02f, 2.545149326324463e-01f);
vs[3].Set(-6.299898028373718e-02f, -2.545155882835388e-01f);
shape.Set(vs, 4);
fd.shape = &shape;
bodies[6]->CreateFixture(&fd);
}
}
{
b2BodyDef bd;
bd.type = b2BodyType(2);
bd.position.Set(2.897095680236816e-02f, 6.702435612678528e-01f);
bd.angle = 0.000000000000000e+00f;
bd.linearVelocity.Set(0.000000000000000e+00f, 0.000000000000000e+00f);
bd.angularVelocity = 0.000000000000000e+00f;
bd.linearDamping = 0.000000000000000e+00f;
bd.angularDamping = 0.000000000000000e+00f;
bd.allowSleep = bool(4);
bd.awake = bool(2);
bd.fixedRotation = bool(0);
bd.bullet = bool(0);
bd.active = bool(32);
bd.gravityScale = 1.000000000000000e+00f;
bodies[7] = m_world->CreateBody(&bd);
{
b2FixtureDef fd;
fd.friction = 2.000000029802322e-01f;
fd.restitution = 0.000000000000000e+00f;
fd.density = 1.000000000000000e+00f;
fd.isSensor = bool(0);
fd.filter.categoryBits = uint16(1);
fd.filter.maskBits = uint16(65535);
fd.filter.groupIndex = int16(-1);
b2PolygonShape shape;
b2Vec2 vs[8];
vs[0].Set(9.449830651283264e-02f, -2.537839412689209e-01f);
vs[1].Set(9.449830651283264e-02f, 2.537844777107239e-01f);
vs[2].Set(-9.449817240238190e-02f, 2.537844777107239e-01f);
vs[3].Set(-9.449817240238190e-02f, -2.537839412689209e-01f);
shape.Set(vs, 4);
fd.shape = &shape;
bodies[7]->CreateFixture(&fd);
}
}
{
b2BodyDef bd;
bd.type = b2BodyType(2);
bd.position.Set(-9.663248062133789e-02f, 6.702435612678528e-01f);
bd.angle = 0.000000000000000e+00f;
bd.linearVelocity.Set(0.000000000000000e+00f, 0.000000000000000e+00f);
bd.angularVelocity = 0.000000000000000e+00f;
bd.linearDamping = 0.000000000000000e+00f;
bd.angularDamping = 0.000000000000000e+00f;
bd.allowSleep = bool(4);
bd.awake = bool(2);
bd.fixedRotation = bool(0);
bd.bullet = bool(0);
bd.active = bool(32);
bd.gravityScale = 1.000000000000000e+00f;
bodies[8] = m_world->CreateBody(&bd);
{
b2FixtureDef fd;
fd.friction = 2.000000029802322e-01f;
fd.restitution = 0.000000000000000e+00f;
fd.density = 1.000000000000000e+00f;
fd.isSensor = bool(0);
fd.filter.categoryBits = uint16(1);
fd.filter.maskBits = uint16(65535);
fd.filter.groupIndex = int16(-1);
b2PolygonShape shape;
b2Vec2 vs[8];
vs[0].Set(9.449842572212219e-02f, -2.537839412689209e-01f);
vs[1].Set(9.449842572212219e-02f, 2.537844777107239e-01f);
vs[2].Set(-9.449826925992966e-02f, 2.537844777107239e-01f);
vs[3].Set(-9.449826925992966e-02f, -2.537839412689209e-01f);
shape.Set(vs, 4);
fd.shape = &shape;
bodies[8]->CreateFixture(&fd);
}
}
{
b2BodyDef bd;
bd.type = b2BodyType(2);
bd.position.Set(2.897095680236816e-02f, 3.554300665855408e-01f);
bd.angle = 0.000000000000000e+00f;
bd.linearVelocity.Set(0.000000000000000e+00f, 0.000000000000000e+00f);
bd.angularVelocity = 0.000000000000000e+00f;
bd.linearDamping = 0.000000000000000e+00f;
bd.angularDamping = 0.000000000000000e+00f;
bd.allowSleep = bool(4);
bd.awake = bool(2);
bd.fixedRotation = bool(0);
bd.bullet = bool(0);
bd.active = bool(32);
bd.gravityScale = 1.000000000000000e+00f;
bodies[9] = m_world->CreateBody(&bd);
{
b2FixtureDef fd;
fd.friction = 2.000000029802322e-01f;
fd.restitution = 0.000000000000000e+00f;
fd.density = 1.000000000000000e+00f;
fd.isSensor = bool(0);
fd.filter.categoryBits = uint16(1);
fd.filter.maskBits = uint16(65535);
fd.filter.groupIndex = int16(-1);
b2PolygonShape shape;
b2Vec2 vs[8];
vs[0].Set(1.550965905189514e-01f, -1.253567039966583e-01f);
vs[1].Set(1.550965905189514e-01f, -6.225190684199333e-02f);
vs[2].Set(-9.268099069595337e-02f, -6.225190684199333e-02f);
vs[3].Set(-9.268099069595337e-02f, -1.253567039966583e-01f);
shape.Set(vs, 4);
fd.shape = &shape;
bodies[9]->CreateFixture(&fd);
}
{
b2FixtureDef fd;
fd.friction = 2.000000029802322e-01f;
fd.restitution = 0.000000000000000e+00f;
fd.density = 1.000000000000000e+00f;
fd.isSensor = bool(0);
fd.filter.categoryBits = uint16(1);
fd.filter.maskBits = uint16(65535);
fd.filter.groupIndex = int16(-1);
b2PolygonShape shape;
b2Vec2 vs[8];
vs[0].Set(9.449830651283264e-02f, -1.247680261731148e-01f);
vs[1].Set(9.449830651283264e-02f, 1.713046580553055e-01f);
vs[2].Set(-9.449817240238190e-02f, 1.713046580553055e-01f);
vs[3].Set(-9.449817240238190e-02f, -1.247680261731148e-01f);
shape.Set(vs, 4);
fd.shape = &shape;
bodies[9]->CreateFixture(&fd);
}
}
{
b2BodyDef bd;
bd.type = b2BodyType(0);
bd.position.Set(3.118395805358887e-03f, -6.553649902343750e-03f);
bd.angle = 0.000000000000000e+00f;
bd.linearVelocity.Set(0.000000000000000e+00f, 0.000000000000000e+00f);
bd.angularVelocity = 0.000000000000000e+00f;
bd.linearDamping = 0.000000000000000e+00f;
bd.angularDamping = 0.000000000000000e+00f;
bd.allowSleep = bool(4);
bd.awake = bool(2);
bd.fixedRotation = bool(0);
bd.bullet = bool(0);
bd.active = bool(32);
bd.gravityScale = 1.000000000000000e+00f;
bodies[10] = m_world->CreateBody(&bd);
{
b2FixtureDef fd;
fd.friction = 2.000000029802322e-01f;
fd.restitution = 0.000000000000000e+00f;
fd.density = 1.000000000000000e+00f;
fd.isSensor = bool(0);
fd.filter.categoryBits = uint16(1);
fd.filter.maskBits = uint16(65535);
fd.filter.groupIndex = int16(0);
b2ChainShape shape;
b2Vec2 vs[2];
vs[0].Set(-4.179394245147705e+00f, 0.000000000000000e+00f);
vs[1].Set(4.179394245147705e+00f, 0.000000000000000e+00f);
shape.CreateChain(vs, 2);
shape.m_prevVertex.Set(-1.998532295227051e+00f, -2.391039296991059e-23f);
shape.m_nextVertex.Set(4.949933242915726e-38f, 3.363116314379561e-44f);
shape.m_hasPrevVertex = bool(0);
shape.m_hasNextVertex = bool(0);
fd.shape = &shape;
bodies[10]->CreateFixture(&fd);
}
}
{
b2RevoluteJointDef jd;
jd.bodyA = bodies[1];
jd.bodyB = bodies[8];
jd.collideConnected = bool(0);
jd.localAnchorA.Set(-9.128235280513763e-02f, -3.880688548088074e-01f);
jd.localAnchorB.Set(-6.031601130962372e-02f, 2.092975974082947e-01f);
jd.referenceAngle = 0.000000000000000e+00f;
jd.enableLimit = bool(1);
jd.lowerAngle = -6.981316804885864e-01f;
jd.upperAngle = 1.919862151145935e+00f;
jd.enableMotor = bool(0);
jd.motorSpeed = 0.000000000000000e+00f;
jd.maxMotorTorque = 1.000000000000000e+00f;
joints[0] = m_world->CreateJoint(&jd);
}
{
b2RevoluteJointDef jd;
jd.bodyA = bodies[1];
jd.bodyB = bodies[7];
jd.collideConnected = bool(0);
jd.localAnchorA.Set(1.498610228300095e-01f, -3.952181935310364e-01f);
jd.localAnchorB.Set(5.541206151247025e-02f, 2.019590735435486e-01f);
jd.referenceAngle = 0.000000000000000e+00f;
jd.enableLimit = bool(1);
jd.lowerAngle = -6.981316804885864e-01f;
jd.upperAngle = 1.919862151145935e+00f;
jd.enableMotor = bool(0);
jd.motorSpeed = 0.000000000000000e+00f;
jd.maxMotorTorque = 1.000000000000000e+00f;
joints[1] = m_world->CreateJoint(&jd);
}
{
b2RevoluteJointDef jd;
jd.bodyA = bodies[1];
jd.bodyB = bodies[6];
jd.collideConnected = bool(0);
jd.localAnchorA.Set(1.874177008867264e-01f, 3.626269102096558e-01f);
jd.localAnchorB.Set(-1.000612974166870e-04f, 1.963189840316772e-01f);
jd.referenceAngle = 0.000000000000000e+00f;
jd.enableLimit = bool(0);
jd.lowerAngle = -2.268928050994873e+00f;
jd.upperAngle = 3.141592741012573e+00f;
jd.enableMotor = bool(0);
jd.motorSpeed = 0.000000000000000e+00f;
jd.maxMotorTorque = 1.000000000000000e+00f;
joints[2] = m_world->CreateJoint(&jd);
}
{
b2RevoluteJointDef jd;
jd.bodyA = bodies[1];
jd.bodyB = bodies[0];
jd.collideConnected = bool(0);
jd.localAnchorA.Set(-1.277616322040558e-01f, 3.649693727493286e-01f);
jd.localAnchorB.Set(-2.339482307434082e-05f, 1.986622810363770e-01f);
jd.referenceAngle = 0.000000000000000e+00f;
jd.enableLimit = bool(0);
jd.lowerAngle = -2.268928050994873e+00f;
jd.upperAngle = 3.141592741012573e+00f;
jd.enableMotor = bool(0);
jd.motorSpeed = 0.000000000000000e+00f;
jd.maxMotorTorque = 1.000000000000000e+00f;
joints[3] = m_world->CreateJoint(&jd);
}
{
b2RevoluteJointDef jd;
jd.bodyA = bodies[8];
jd.bodyB = bodies[4];
jd.collideConnected = bool(0);
jd.localAnchorA.Set(-1.047469675540924e-03f, -1.993342936038971e-01f);
jd.localAnchorB.Set(-1.047216355800629e-03f, 1.156357824802399e-01f);
jd.referenceAngle = 0.000000000000000e+00f;
jd.enableLimit = bool(1);
jd.lowerAngle = -2.268928050994873e+00f;
jd.upperAngle = 0.000000000000000e+00f;
jd.enableMotor = bool(0);
jd.motorSpeed = 0.000000000000000e+00f;
jd.maxMotorTorque = 1.000000000000000e+00f;
joints[4] = m_world->CreateJoint(&jd);
}
{
b2RevoluteJointDef jd;
jd.bodyA = bodies[0];
jd.bodyB = bodies[5];
jd.collideConnected = bool(0);
jd.localAnchorA.Set(1.148343086242676e-03f, -1.961904764175415e-01f);
jd.localAnchorB.Set(1.148715615272522e-03f, 9.516614675521851e-02f);
jd.referenceAngle = 0.000000000000000e+00f;
jd.enableLimit = bool(1);
jd.lowerAngle = 0.000000000000000e+00f;
jd.upperAngle = 1.919862151145935e+00f;
jd.enableMotor = bool(0);
jd.motorSpeed = 0.000000000000000e+00f;
jd.maxMotorTorque = 1.000000000000000e+00f;
joints[5] = m_world->CreateJoint(&jd);
}
{
b2RevoluteJointDef jd;
jd.bodyA = bodies[3];
jd.bodyB = bodies[6];
jd.collideConnected = bool(0);
jd.localAnchorA.Set(4.750192165374756e-04f, 9.541386365890503e-02f);
jd.localAnchorB.Set(4.747509956359863e-04f, -1.959429979324341e-01f);
jd.referenceAngle = 0.000000000000000e+00f;
jd.enableLimit = bool(1);
jd.lowerAngle = 0.000000000000000e+00f;
jd.upperAngle = 1.919862151145935e+00f;
jd.enableMotor = bool(0);
jd.motorSpeed = 0.000000000000000e+00f;
jd.maxMotorTorque = 1.000000000000000e+00f;
joints[6] = m_world->CreateJoint(&jd);
}
{
b2RevoluteJointDef jd;
jd.bodyA = bodies[7];
jd.bodyB = bodies[9];
jd.collideConnected = bool(0);
jd.localAnchorA.Set(2.657793462276459e-03f, -2.022806107997894e-01f);
jd.localAnchorB.Set(2.657927572727203e-03f, 1.125320196151733e-01f);
jd.referenceAngle = 0.000000000000000e+00f;
jd.enableLimit = bool(1);
jd.lowerAngle = -2.268928050994873e+00f;
jd.upperAngle = 0.000000000000000e+00f;
jd.enableMotor = bool(0);
jd.motorSpeed = 0.000000000000000e+00f;
jd.maxMotorTorque = 1.000000000000000e+00f;
joints[7] = m_world->CreateJoint(&jd);
}
{
b2RevoluteJointDef jd;
jd.bodyA = bodies[1];
jd.bodyB = bodies[2];
jd.collideConnected = bool(0);
jd.localAnchorA.Set(8.169807493686676e-02f, 5.554057359695435e-01f);
jd.localAnchorB.Set(-2.346399985253811e-02f, -3.764809966087341e-01f);
jd.referenceAngle = 0.000000000000000e+00f;
jd.enableLimit = bool(1);
jd.lowerAngle = -1.221730470657349e+00f;
jd.upperAngle = 6.981316804885864e-01f;
jd.enableMotor = bool(0);
jd.motorSpeed = 0.000000000000000e+00f;
jd.maxMotorTorque = 1.000000000000000e+00f;
joints[8] = m_world->CreateJoint(&jd);
}
b2Free(joints);
b2Free(bodies);
joints = NULL;
bodies = NULL;

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,2 @@
//Restarted script log at Sat Feb 15 20:29:28 2014
getJoint(2).deselect();

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,2 @@
//Restarted script log at Sun Feb 16 21:04:27 2014
getBody(16).deselect();

View file

@ -0,0 +1,48 @@
//Started script log at Mon Feb 17 11:10:57 2014
getBody(18).select();
getBody(19).select();
getBody(17).select();
getBody(20).select();
getBody(21).select();
getBody(22).select();
getBody(12).select();
getBody(15).select();
getBody(16).select();
getBody(14).select();
getBody(13).select();
getBody(18).deselect();
getBody(19).deselect();
getBody(17).deselect();
getBody(20).deselect();
getBody(21).deselect();
getBody(22).deselect();
getBody(12).deselect();
getBody(15).deselect();
getBody(16).deselect();
getBody(14).deselect();
getBody(13).deselect();
getBody(20).select();
getBody(20).deselect();
getBody(20).select();
getBody(20).deselect();
getBody(12).select();
getBody(12).deselect();
getBody(12).select();
getBody(12).deselect();
getBody(20).select();
getBody(20).deselect();
getBody(22).select();
getBody(12).select();
getBody(22).deselect();
getBody(12).deselect();
getBody(12).select();
getBody(12).deselect();
getBody(12).select();
getBody(12).deselect();
getBody(12).select();
getBody(12).deselect();
getBody(12).select();
getBody(12).deselect();
getBody(12).select();
getBody(12).deselect();