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) {
function RagDoll(physicsEngine, uid, options) {
this.scheduledForDestruction = false;
this.destructionTimeout = null;
return Parent;
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() {