mirror of
https://github.com/logsol/chuck.js.git
synced 2026-05-11 10:37:34 +00:00
new system for synchronizing game objects. fixes #74
This commit is contained in:
parent
3ef3a6abf9
commit
07dad646cf
19 changed files with 194 additions and 162 deletions
|
|
@ -55,9 +55,11 @@ function (Parent, Box2D, PhysicsEngine, ViewManager, PlayerController, Nc, reque
|
|||
this.mePositionStateUpdate();
|
||||
}
|
||||
|
||||
for (var i = 0; i < this.gameObjects.animated.length; i++) {
|
||||
this.gameObjects.animated[i].render();
|
||||
}
|
||||
//for (var uid in this.gameObjects.animated) {
|
||||
// this.gameObjects.animated[uid].render();
|
||||
//}
|
||||
|
||||
Nc.trigger(Nc.ns.client.game.events.render);
|
||||
|
||||
this.view.render();
|
||||
DomController.fpsStep();
|
||||
|
|
@ -78,17 +80,10 @@ function (Parent, Box2D, PhysicsEngine, ViewManager, PlayerController, Nc, reque
|
|||
|
||||
if (options.runtimeItems) {
|
||||
for (i = 0; i < options.runtimeItems.length; i++) {
|
||||
|
||||
var itemDef = options.runtimeItems[i];
|
||||
|
||||
var alreadyExists = false;
|
||||
for (var j = 0; j < this.gameObjects.animated.length; j++) {
|
||||
if(this.gameObjects.animated[j].uid == itemDef.uid) {
|
||||
alreadyExists = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if(!alreadyExists) {
|
||||
if(!this.getItemByUid(itemDef.uid)) {
|
||||
// When creating from synchronization we need to bring it into level format (px)
|
||||
itemDef.options.x *= Settings.RATIO;
|
||||
itemDef.options.y *= Settings.RATIO;
|
||||
|
|
@ -112,6 +107,13 @@ function (Parent, Box2D, PhysicsEngine, ViewManager, PlayerController, Nc, reque
|
|||
//this.audioPlayer.play();
|
||||
};
|
||||
|
||||
|
||||
/*
|
||||
|
||||
TODO :
|
||||
- remove this
|
||||
- overwrite setUpdateData inside client / Me with an empty function
|
||||
|
||||
GameController.prototype.onWorldUpdateGameObject = function(body, gameObject, update) {
|
||||
if(gameObject === this.me.doll) {
|
||||
this.me.setLastServerPositionState(update);
|
||||
|
|
@ -122,6 +124,7 @@ function (Parent, Box2D, PhysicsEngine, ViewManager, PlayerController, Nc, reque
|
|||
|
||||
Parent.prototype.onWorldUpdateGameObject.call(this, body, gameObject, update);
|
||||
};
|
||||
*/
|
||||
|
||||
GameController.prototype.createMe = function(user) {
|
||||
this.me = new Me(user.id, this.physicsEngine, user);
|
||||
|
|
@ -161,15 +164,7 @@ function (Parent, Box2D, PhysicsEngine, ViewManager, PlayerController, Nc, reque
|
|||
|
||||
GameController.prototype.onHandActionResponse = function(options) {
|
||||
var player = this.players[options.playerId];
|
||||
|
||||
var item = null;
|
||||
for (var i = 0; i < this.gameObjects.animated.length; i++) {
|
||||
var currentItem = this.gameObjects.animated[i];
|
||||
if(currentItem.uid == options.itemUid) {
|
||||
item = currentItem;
|
||||
break;
|
||||
}
|
||||
}
|
||||
var item = this.getItemByUid(options.itemUid);
|
||||
|
||||
if(item) {
|
||||
if(options.action == "throw") {
|
||||
|
|
@ -230,22 +225,6 @@ function (Parent, Box2D, PhysicsEngine, ViewManager, PlayerController, Nc, reque
|
|||
this.me.resetPositionState(options);
|
||||
};
|
||||
|
||||
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);
|
||||
};
|
||||
|
|
|
|||
|
|
@ -27,7 +27,7 @@ function (Parent, Exception, Nc) {
|
|||
GameObject.prototype.createMesh = function() {
|
||||
throw new Exception('Abstract method GameObject.createMesh not overwritten');
|
||||
};
|
||||
|
||||
|
||||
return GameObject;
|
||||
|
||||
});
|
||||
|
|
@ -12,6 +12,8 @@ function (Parent, Settings, Nc, Layer) {
|
|||
function Item(physicsEngine, uid, options) {
|
||||
this.layerId = Layer.ID.ITEM;
|
||||
Parent.call(this, physicsEngine, uid, options);
|
||||
|
||||
Nc.on(Nc.ns.client.game.events.render, this.render, this);
|
||||
}
|
||||
|
||||
Item.prototype = Object.create(Parent.prototype);
|
||||
|
|
|
|||
|
|
@ -189,8 +189,6 @@ function (Parent, Layer, Settings, Nc) {
|
|||
RubeDoll.prototype.flip = function(direction) {
|
||||
Parent.prototype.flip.call(this, direction);
|
||||
|
||||
console.log("last", this.lastFlipDirection, "now", direction);
|
||||
|
||||
// flipping depth of right body side arm/leg images with left
|
||||
if (this.lastFlipDirection != direction) { // FIXME : this is a bit broken.
|
||||
|
||||
|
|
|
|||
|
|
@ -8,9 +8,9 @@ function (Parent, Settings, Nc) {
|
|||
|
||||
"use strict";
|
||||
|
||||
function TiledLevel(uid, engine, gameObjects) {
|
||||
function TiledLevel(uid, engine) {
|
||||
this.layerId = "background";
|
||||
Parent.call(this, uid, engine, gameObjects);
|
||||
Parent.call(this, uid, engine);
|
||||
}
|
||||
|
||||
TiledLevel.prototype = Object.create(Parent.prototype);
|
||||
|
|
|
|||
|
|
@ -15,6 +15,8 @@ function (Parent, Nc, Settings) {
|
|||
this.healthBarViewVisibleTimeout = null;
|
||||
this.healthBarViewVisible = false;
|
||||
this.initHealthBar();
|
||||
|
||||
Nc.on(Nc.ns.client.game.events.render, this.render, this);
|
||||
}
|
||||
|
||||
Player.prototype = Object.create(Parent.prototype);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue