replaced killed doll with ragdoll - fixes #50

This commit is contained in:
logsol 2014-02-18 01:15:24 +01:00
parent aa6fdaa2df
commit 413254bfa4
19 changed files with 330 additions and 88 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));
@ -45,10 +47,6 @@ function (Parent, Box2D, PhysicsEngine, ViewManager, PlayerController, Notificat
this.me.update();
}
for (var key in this.players) {
this.players[key].render();
}
for (var i = 0; i < this.gameObjects.animated.length; i++) {
this.gameObjects.animated[i].render();
}
@ -97,7 +95,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,18 +146,26 @@ function (Parent, Box2D, PhysicsEngine, ViewManager, PlayerController, Notificat
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

@ -96,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

@ -87,6 +87,9 @@ function (Parent, NotificationCenter, Settings) {
};
Player.prototype.render = function() {
// dolls are self responsible
if(this.playerInfoViewVisible) {
var position = this.getPosition();
var options = {

View file

@ -44,7 +44,7 @@ function (Parent, DomController, PIXI, Settings, NotificationCenter) {
}
PixiView.prototype.render = function () {
if(this.me && this.me.isSpawned) {
if(this.me) {
var pos = this.calculateCameraPosition();
this.setCameraPosition(pos.x, pos.y);
}