mirror of
https://github.com/logsol/chuck.js.git
synced 2026-05-11 10:37:34 +00:00
implemented rube doll to appear when dying
This commit is contained in:
parent
cd956b8a28
commit
2dea240a4b
5 changed files with 99 additions and 14 deletions
|
|
@ -1,11 +1,45 @@
|
||||||
define([
|
define([
|
||||||
"Game/Core/GameObjects/Items/RubeDoll"
|
"Game/Core/GameObjects/Items/RubeDoll",
|
||||||
|
"Game/Config/Settings",
|
||||||
|
"Lib/Utilities/NotificationCenter"
|
||||||
],
|
],
|
||||||
|
|
||||||
function (Parent) {
|
function (Parent, Settings, Nc) {
|
||||||
|
|
||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
return Parent;
|
function RubeDoll(physicsEngine, uid, options) {
|
||||||
|
Parent.call(this, physicsEngine, uid, options);
|
||||||
|
}
|
||||||
|
|
||||||
|
RubeDoll.prototype = Object.create(Parent.prototype);
|
||||||
|
|
||||||
|
RubeDoll.prototype.beingReleased = function(player) {
|
||||||
|
Parent.prototype.beingReleased.call(this, player);
|
||||||
|
if(this.scheduledForDestruction) {
|
||||||
|
this.delayedDestroy();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
RubeDoll.prototype.delayedDestroy = function() {
|
||||||
|
var self = this;
|
||||||
|
this.scheduledForDestruction = true;
|
||||||
|
this.destructionTimeout = setTimeout(function() {
|
||||||
|
Nc.trigger(Nc.ns.channel.to.client.gameCommand.broadcast, 'removeGameObject', {
|
||||||
|
type: 'animated',
|
||||||
|
uid: self.uid
|
||||||
|
});
|
||||||
|
self.destroy();
|
||||||
|
}, Settings.RAGDOLL_DESTRUCTION_TIME * 1000);
|
||||||
|
};
|
||||||
|
|
||||||
|
RubeDoll.prototype.destroy = function() {
|
||||||
|
if(this.scheduledForDestruction) {
|
||||||
|
clearTimeout(this.destructionTimeout);
|
||||||
|
}
|
||||||
|
Parent.prototype.destroy.call(this);
|
||||||
|
};
|
||||||
|
|
||||||
|
return RubeDoll;
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
@ -11,7 +11,7 @@ function (Parent, Layer, Settings, Nc) {
|
||||||
|
|
||||||
function RubeDoll(physicsEngine, uid, options) {
|
function RubeDoll(physicsEngine, uid, options) {
|
||||||
|
|
||||||
this.primaryColor = 0x008800;
|
this.primaryColor = options.primaryColor;
|
||||||
|
|
||||||
var limbOptions = {};
|
var limbOptions = {};
|
||||||
|
|
||||||
|
|
@ -160,6 +160,12 @@ function (Parent, Layer, Settings, Nc) {
|
||||||
};
|
};
|
||||||
|
|
||||||
RubeDoll.prototype.destroy = function() {
|
RubeDoll.prototype.destroy = function() {
|
||||||
|
|
||||||
|
for (var name in this.limbMeshes) {
|
||||||
|
Nc.trigger(Nc.ns.client.view.mesh.remove, this.layerId, this.limbMeshes[name]);
|
||||||
|
};
|
||||||
|
|
||||||
|
Parent.prototype.destroy.call(this);
|
||||||
};
|
};
|
||||||
|
|
||||||
RubeDoll.prototype.render = function() {
|
RubeDoll.prototype.render = function() {
|
||||||
|
|
|
||||||
|
|
@ -83,10 +83,6 @@ function (Parent, Nc, Settings) {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
Player.prototype.getNickname = function() {
|
|
||||||
return this.user.options.nickname;
|
|
||||||
};
|
|
||||||
|
|
||||||
Player.prototype.render = function() {
|
Player.prototype.render = function() {
|
||||||
|
|
||||||
if(this.doll) {
|
if(this.doll) {
|
||||||
|
|
|
||||||
|
|
@ -4,10 +4,11 @@ define([
|
||||||
"Lib/Vendor/Box2D",
|
"Lib/Vendor/Box2D",
|
||||||
"Game/Config/Settings",
|
"Game/Config/Settings",
|
||||||
"Lib/Utilities/Assert",
|
"Lib/Utilities/Assert",
|
||||||
|
"Lib/Utilities/NotificationCenter",
|
||||||
"json!Game/Asset/RubeDoll.json" // using requirejs json loader plugin
|
"json!Game/Asset/RubeDoll.json" // using requirejs json loader plugin
|
||||||
],
|
],
|
||||||
|
|
||||||
function (Parent, RubeLoader, Box2D, Settings, Assert, RubeDollJson) {
|
function (Parent, RubeLoader, Box2D, Settings, Assert, Nc, RubeDollJson) {
|
||||||
|
|
||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
|
|
@ -45,6 +46,13 @@ function (Parent, RubeLoader, Box2D, Settings, Assert, RubeDollJson) {
|
||||||
|
|
||||||
RubeDoll.prototype = Object.create(Parent.prototype);
|
RubeDoll.prototype = Object.create(Parent.prototype);
|
||||||
|
|
||||||
|
RubeDoll.prototype.getFixtureDef = function() {
|
||||||
|
|
||||||
|
var fixtureDef = new Box2D.Dynamics.b2FixtureDef();
|
||||||
|
fixtureDef.shape = new Box2D.Collision.Shapes.b2CircleShape();
|
||||||
|
return fixtureDef;
|
||||||
|
};
|
||||||
|
|
||||||
RubeDoll.prototype.flip = function(direction) {
|
RubeDoll.prototype.flip = function(direction) {
|
||||||
Parent.prototype.flip.call(this, direction);
|
Parent.prototype.flip.call(this, direction);
|
||||||
// Extend
|
// Extend
|
||||||
|
|
@ -62,5 +70,36 @@ function (Parent, RubeLoader, Box2D, Settings, Assert, RubeDollJson) {
|
||||||
this.body.SetPosition(position);
|
this.body.SetPosition(position);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
RubeDoll.prototype.setVelocities = function(options) {
|
||||||
|
Assert.number(options.linearVelocity.x, options.linearVelocity.y);
|
||||||
|
Assert.number(options.angularVelocity);
|
||||||
|
|
||||||
|
this.body.SetLinearVelocity(options.linearVelocity);
|
||||||
|
this.body.SetAngularVelocity(options.angularVelocity);
|
||||||
|
for(var name in this.limbs) {
|
||||||
|
this.limbs[name].SetLinearVelocity(options.linearVelocity);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
RubeDoll.prototype.getPosition = function() {
|
||||||
|
return this.body.GetPosition().Copy();
|
||||||
|
};
|
||||||
|
|
||||||
|
RubeDoll.prototype.getHeadPosition = function() {
|
||||||
|
return this.limbs.head.GetPosition().Copy();
|
||||||
|
};
|
||||||
|
|
||||||
|
RubeDoll.prototype.destroy = function() {
|
||||||
|
|
||||||
|
Nc.trigger(Nc.ns.core.game.gameObject.remove, "animated", this);
|
||||||
|
var world = this.body.GetWorld();
|
||||||
|
|
||||||
|
for (var name in this.limbs) {
|
||||||
|
world.DestroyBody(this.limbs[name]);
|
||||||
|
}
|
||||||
|
|
||||||
|
Parent.prototype.destroy.call(this);
|
||||||
|
};
|
||||||
|
|
||||||
return RubeDoll;
|
return RubeDoll;
|
||||||
});
|
});
|
||||||
|
|
@ -3,11 +3,12 @@ define([
|
||||||
"Game/Config/Settings",
|
"Game/Config/Settings",
|
||||||
"Lib/Utilities/NotificationCenter",
|
"Lib/Utilities/NotificationCenter",
|
||||||
"Lib/Utilities/Exception",
|
"Lib/Utilities/Exception",
|
||||||
|
"Lib/Utilities/ColorConverter",
|
||||||
"Game/" + GLOBALS.context + "/GameObjects/SpectatorDoll",
|
"Game/" + GLOBALS.context + "/GameObjects/SpectatorDoll",
|
||||||
"Game/" + GLOBALS.context + "/GameObjects/Items/RagDoll"
|
"Game/" + GLOBALS.context + "/GameObjects/Items/RubeDoll"
|
||||||
],
|
],
|
||||||
|
|
||||||
function (Doll, Settings, Nc, Exception, SpectatorDoll, RagDoll) {
|
function (Doll, Settings, Nc, Exception, ColorConverter, SpectatorDoll, RubeDoll) {
|
||||||
|
|
||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
|
|
@ -30,6 +31,10 @@ function (Doll, Settings, Nc, Exception, SpectatorDoll, RagDoll) {
|
||||||
Nc.trigger(Nc.ns.core.game.gameObject.add, 'animated', this);
|
Nc.trigger(Nc.ns.core.game.gameObject.add, 'animated', this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Player.prototype.getNickname = function() {
|
||||||
|
return this.user.options.nickname;
|
||||||
|
};
|
||||||
|
|
||||||
Player.prototype.getActiveDoll = function() {
|
Player.prototype.getActiveDoll = function() {
|
||||||
if(this.spawned) {
|
if(this.spawned) {
|
||||||
return this.doll;
|
return this.doll;
|
||||||
|
|
@ -112,6 +117,10 @@ function (Doll, Settings, Nc, Exception, SpectatorDoll, RagDoll) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// prepare for creating the ragdoll
|
// prepare for creating the ragdoll
|
||||||
|
|
||||||
|
var converter = new ColorConverter();
|
||||||
|
var primaryColor = converter.getColorByName(this.getNickname());
|
||||||
|
|
||||||
var options = {
|
var options = {
|
||||||
x: this.getPosition().x * Settings.RATIO,
|
x: this.getPosition().x * Settings.RATIO,
|
||||||
y: this.getPosition().y * Settings.RATIO,
|
y: this.getPosition().y * Settings.RATIO,
|
||||||
|
|
@ -123,10 +132,11 @@ function (Doll, Settings, Nc, Exception, SpectatorDoll, RagDoll) {
|
||||||
type: "ragdoll",
|
type: "ragdoll",
|
||||||
weight: 3,
|
weight: 3,
|
||||||
width: 5,
|
width: 5,
|
||||||
height: 12
|
height: 12,
|
||||||
|
primaryColor: primaryColor
|
||||||
};
|
};
|
||||||
|
|
||||||
var ragDoll = new RagDoll(this.physicsEngine, "ragDoll-" + this.id + "-" + ragDollId, options);
|
var ragDoll = new RubeDoll(this.physicsEngine, "ragDoll-" + this.id + "-" + ragDollId, options);
|
||||||
ragDoll.setVelocities(this.doll.getVelocities());
|
ragDoll.setVelocities(this.doll.getVelocities());
|
||||||
|
|
||||||
this.spawned = false;
|
this.spawned = false;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue