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

@ -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,13 +56,17 @@ 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();
if(enemy != this) enemy.score();
this.kill(enemy);
} else {
this.broadcastStats();
@ -83,6 +87,10 @@ function (Parent, NotificationCenter) {
playerId: this.id,
killedByPlayerId: killedByPlayer.id
});
if(this.ragDoll) {
this.ragDoll.delayedDestroy();
}
};
Player.prototype.score = function() {