mirror of
https://github.com/logsol/chuck.js.git
synced 2026-05-11 10:37:34 +00:00
replaced killed doll with ragdoll - fixes #50
This commit is contained in:
parent
aa6fdaa2df
commit
413254bfa4
19 changed files with 330 additions and 88 deletions
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -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 = [];
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
21
app/Game/Client/GameObjects/SpectatorDoll.js
Normal file
21
app/Game/Client/GameObjects/SpectatorDoll.js
Normal 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;
|
||||
});
|
||||
|
|
@ -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 = {
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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,11 +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: 3,
|
||||
RESPAWN_TIME: 6,
|
||||
HEALTH_DISPLAY_TIME: 2,
|
||||
RAGDOLL_DESTRUCTION_TIME: 25,
|
||||
|
||||
// restitution: bouncyness, friction: rubbing, density: mass
|
||||
TILE_FRICTION: 0.99,
|
||||
|
|
@ -46,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',
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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];
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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()) {
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
||||
});
|
||||
37
app/Game/Core/GameObjects/SpectatorDoll.js
Normal file
37
app/Game/Core/GameObjects/SpectatorDoll.js
Normal 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;
|
||||
|
||||
});
|
||||
|
|
@ -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);
|
||||
}
|
||||
|
||||
|
|
@ -86,8 +103,35 @@ function (Doll, Settings, NotificationCenter) {
|
|||
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) {
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
||||
});
|
||||
|
|
@ -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) {
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
||||
});
|
||||
9
app/Game/Server/GameObjects/SpectatorDoll.js
Normal file
9
app/Game/Server/GameObjects/SpectatorDoll.js
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
define([
|
||||
"Game/Core/GameObjects/SpectatorDoll"
|
||||
],
|
||||
|
||||
function (Parent) {
|
||||
|
||||
return Parent;
|
||||
|
||||
});
|
||||
|
|
@ -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() {
|
||||
|
|
|
|||
|
|
@ -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",
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue