mirror of
https://github.com/logsol/chuck.js.git
synced 2026-05-11 10:37:34 +00:00
parent
8b8093b771
commit
8641a2dc0b
4 changed files with 36 additions and 21 deletions
|
|
@ -177,25 +177,36 @@ function (Parent, PhysicsEngine, Settings, requestAnimFrame, Nc, Box2D, Player,
|
||||||
return spawnedPlayers;
|
return spawnedPlayers;
|
||||||
};
|
};
|
||||||
|
|
||||||
GameController.prototype.getRuntimeItems = function() {
|
GameController.prototype._getRuntimeItems = function() {
|
||||||
var objects = [];
|
|
||||||
|
|
||||||
// This is using the level.createItem mechanism to
|
var runtimeItems = [];
|
||||||
// create the RubeDoll from its ItemSettings
|
|
||||||
for (var uid in this.worldUpdateObjects) {
|
for (var uid in this.worldUpdateObjects) {
|
||||||
if(this.worldUpdateObjects[uid] instanceof RubeDoll) {
|
if(this.worldUpdateObjects[uid] instanceof RubeDoll) {
|
||||||
var object = this.worldUpdateObjects[uid];
|
var object = this.worldUpdateObjects[uid];
|
||||||
|
runtimeItems.push(object);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return runtimeItems;
|
||||||
|
};
|
||||||
|
|
||||||
|
GameController.prototype.gatherRuntimeItemsForWorldUpdate = function() {
|
||||||
|
var infos = [];
|
||||||
|
var runtimeItems = this._getRuntimeItems();
|
||||||
|
|
||||||
|
// On the other side this is using the level.createItem mechanism to
|
||||||
|
// create the RubeDoll from its ItemSettings
|
||||||
|
for (var i = 0; i < runtimeItems.length; i++) {
|
||||||
|
var object = runtimeItems[i];
|
||||||
var options = object.options;
|
var options = object.options;
|
||||||
options.x = object.getPosition().x;
|
options.x = object.getPosition().x;
|
||||||
options.y = object.getPosition().y;
|
options.y = object.getPosition().y;
|
||||||
objects.push({
|
infos.push({
|
||||||
uid: object.uid,
|
uid: object.uid,
|
||||||
options: object.options
|
options: object.options
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
return objects;
|
return infos;
|
||||||
};
|
};
|
||||||
|
|
||||||
GameController.prototype.onClientReady = function(userId) {
|
GameController.prototype.onClientReady = function(userId) {
|
||||||
|
|
@ -204,7 +215,7 @@ function (Parent, PhysicsEngine, Settings, requestAnimFrame, Nc, Box2D, Player,
|
||||||
var options = {
|
var options = {
|
||||||
spawnedPlayers: this.getSpawnedPlayersAndTheirPositions(),
|
spawnedPlayers: this.getSpawnedPlayersAndTheirPositions(),
|
||||||
worldUpdate: this.getWorldUpdateObject(true),
|
worldUpdate: this.getWorldUpdateObject(true),
|
||||||
runtimeItems: this.getRuntimeItems(),
|
runtimeItems: this.gatherRuntimeItemsForWorldUpdate(),
|
||||||
userId: userId
|
userId: userId
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -241,6 +252,11 @@ function (Parent, PhysicsEngine, Settings, requestAnimFrame, Nc, Box2D, Player,
|
||||||
clearTimeout(this.spawnTimeouts[i]);
|
clearTimeout(this.spawnTimeouts[i]);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
var runtimeItems = this._getRuntimeItems();
|
||||||
|
for (var i = 0; i < runtimeItems.length; i++) {
|
||||||
|
runtimeItems[i].destroy();
|
||||||
|
}
|
||||||
|
|
||||||
Parent.prototype.destroy.call(this);
|
Parent.prototype.destroy.call(this);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -13,7 +13,9 @@ function (Parent, Settings, Nc, Layer) {
|
||||||
this.layerId = Layer.ID.ITEM;
|
this.layerId = Layer.ID.ITEM;
|
||||||
Parent.call(this, physicsEngine, uid, options);
|
Parent.call(this, physicsEngine, uid, options);
|
||||||
|
|
||||||
Nc.on(Nc.ns.client.game.events.render, this.render, this);
|
this.ncTokens = this.ncTokens.concat([
|
||||||
|
Nc.on(Nc.ns.client.game.events.render, this.render, this)
|
||||||
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
Item.prototype = Object.create(Parent.prototype);
|
Item.prototype = Object.create(Parent.prototype);
|
||||||
|
|
|
||||||
|
|
@ -16,7 +16,9 @@ function (Parent, Nc, Settings) {
|
||||||
this.healthBarViewVisible = false;
|
this.healthBarViewVisible = false;
|
||||||
this.initHealthBar();
|
this.initHealthBar();
|
||||||
|
|
||||||
Nc.on(Nc.ns.client.game.events.render, this.render, this);
|
this.ncTokens = [
|
||||||
|
Nc.on(Nc.ns.client.game.events.render, this.render, this)
|
||||||
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
Player.prototype = Object.create(Parent.prototype);
|
Player.prototype = Object.create(Parent.prototype);
|
||||||
|
|
@ -109,6 +111,7 @@ function (Parent, Nc, Settings) {
|
||||||
Player.prototype.destroy = function() {
|
Player.prototype.destroy = function() {
|
||||||
clearTimeout(this.healthBarViewVisibleTimeout);
|
clearTimeout(this.healthBarViewVisibleTimeout);
|
||||||
Nc.trigger(Nc.ns.client.view.healthBar.remove, this.healthBarView);
|
Nc.trigger(Nc.ns.client.view.healthBar.remove, this.healthBarView);
|
||||||
|
Nc.off(this.ncTokens);
|
||||||
Parent.prototype.destroy.call(this);
|
Parent.prototype.destroy.call(this);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -26,12 +26,6 @@
|
||||||
<fieldset>
|
<fieldset>
|
||||||
<legend>Maps</legend>
|
<legend>Maps</legend>
|
||||||
<ul id="maps">
|
<ul id="maps">
|
||||||
<li>
|
|
||||||
<label><input name="maps" value="debug" type="checkbox" checked> Debug</label>
|
|
||||||
</li>
|
|
||||||
<li>
|
|
||||||
<label><input name="maps" value="stones" type="checkbox" checked> Stones</label>
|
|
||||||
</li>
|
|
||||||
</ul>
|
</ul>
|
||||||
</fieldset>
|
</fieldset>
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue