fixes #112 finished recorder

This commit is contained in:
Jeena 2015-03-15 21:06:44 +01:00
parent dfa71bc8e5
commit c88afc8b4c
11 changed files with 275 additions and 1765 deletions

View file

@ -4,9 +4,11 @@ define([
"Game/" + GLOBALS.context + "/Player",
"Lib/Utilities/NotificationCenter",
"Game/" + GLOBALS.context + "/GameObjects/Doll",
"Game/" + GLOBALS.context + "/GameObjects/GameObject",
"Lib/Utilities/Assert"
],
function (PhysicsEngine, TiledLevel, Player, Nc, Doll) {
function (PhysicsEngine, TiledLevel, Player, Nc, Doll, GameObject, Assert) {
"use strict";
@ -53,7 +55,7 @@ function (PhysicsEngine, TiledLevel, Player, Nc, Doll) {
GameController.prototype.getPhysicsEngine = function () {
return this.physicsEngine;
}
};
GameController.prototype.loadLevel = function (levelUid) {
@ -63,7 +65,50 @@ function (PhysicsEngine, TiledLevel, Player, Nc, Doll) {
}
this.level = new TiledLevel(levelUid, this.physicsEngine, this.gameObjects);
}
};
GameController.prototype.onWorldUpdate = function (updateData) {
var body = this.physicsEngine.world.GetBodyList();
do {
var userData = body.GetUserData();
if (userData instanceof GameObject) {
var gameObject = userData;
if(updateData[gameObject.uid]) {
var update = updateData[gameObject.uid];
this.onWorldUpdateGameObject(body, gameObject, update);
}
}
} while (body = body.GetNext());
};
GameController.prototype.onWorldUpdateGameObject = function(body, gameObject, update) {
if (gameObject instanceof Doll) {
/*
if(gameObject === this.me.doll) {
this.me.setLastServerPositionState(update);
if(!this.me.acceptPositionStateUpdateFromServer()) {
return; // this is to ignore own doll updates from world update
}
}
*/
gameObject.setActionState(update.as);
gameObject.lookAt(update.laxy.x, update.laxy.y);
}
Assert.number(update.p.x, update.p.y);
Assert.number(update.a);
Assert.number(update.lv.x, update.lv.y);
Assert.number(update.av);
body.SetAwake(true);
body.SetPosition(update.p);
body.SetAngle(update.a);
body.SetLinearVelocity(update.lv);
body.SetAngularVelocity(update.av);
};
GameController.prototype.onResetLevel = function() {
this.loadLevel(this.level.uid);
@ -84,7 +129,7 @@ function (PhysicsEngine, TiledLevel, Player, Nc, Doll) {
player.destroy();
delete this.players[userId];
}
};
GameController.prototype.createPlayer = function(user) {
var player = new Player(user.id, this.physicsEngine, user);
@ -93,17 +138,21 @@ function (PhysicsEngine, TiledLevel, Player, Nc, Doll) {
};
GameController.prototype.destroy = function () {
var i = 0;
/*
for(var player in this.players) {
// this.players[player].destroy();
// FIXME:
// commented out for now, because players are in gameObjects array.
// try using a real gameobject for the health bar
}
}*/
for (var i = 0; i < this.ncTokens.length; i++) {
for (i = 0; i < this.ncTokens.length; i++) {
Nc.off(this.ncTokens[i]);
};
}
/*
* Contents of gameObject: Players, Items, Tiles, RagDolls
@ -111,12 +160,12 @@ function (PhysicsEngine, TiledLevel, Player, Nc, Doll) {
*/
for (var key in this.gameObjects) {
for (var i = 0; i < this.gameObjects[key].length; i++) {
for (i = 0; i < this.gameObjects[key].length; i++) {
var gameObject = this.gameObjects[key][i];
gameObject.destroy();
};
};
}
}
this.gameObjects = {
fixed: [],
@ -124,7 +173,7 @@ function (PhysicsEngine, TiledLevel, Player, Nc, Doll) {
};
this.physicsEngine.destroy();
}
};
return GameController;
});

View file

@ -23,7 +23,7 @@ function (Doll, Settings, Nc, Exception, SpectatorDoll, RagDoll) {
this.playerController = null;
this.doll;
this.id = id;
this.isSpawned = false;
this.spawned = false;
this.holdingItem = null;
this.spectatorDoll = new SpectatorDoll(this.physicsEngine, "spectatorDoll-" + this.id, this);
@ -31,7 +31,7 @@ function (Doll, Settings, Nc, Exception, SpectatorDoll, RagDoll) {
}
Player.prototype.getActiveDoll = function() {
if(this.isSpawned) {
if(this.spawned) {
return this.doll;
} else if (this.ragDoll) {
return this.ragDoll;
@ -42,9 +42,13 @@ function (Doll, Settings, Nc, Exception, SpectatorDoll, RagDoll) {
Player.prototype.spawn = function (x, y) {
this.doll = new Doll(this.physicsEngine, "doll-" + this.id, this);
this.doll.spawn(x, y);
this.isSpawned = true;
this.spawned = true;
}
Player.prototype.isSpawned = function() {
return this.spawned;
};
Player.prototype.getPosition = function () {
return this.getActiveDoll().getPosition();
}
@ -55,47 +59,47 @@ function (Doll, Settings, Nc, Exception, SpectatorDoll, RagDoll) {
Player.prototype.move = function (direction) {
if(!this.isSpawned) return false;
if(!this.spawned) return false;
this.doll.move(direction);
}
Player.prototype.stop = function () {
if(!this.isSpawned) return false;
if(!this.spawned) return false;
this.doll.stop();
}
Player.prototype.jump = function () {
if(!this.isSpawned) return false;
if(!this.spawned) return false;
this.doll.jump();
}
Player.prototype.jumpStop = function () {
if(!this.isSpawned) return false;
if(!this.spawned) return false;
this.doll.jumpStop();
}
Player.prototype.lookAt = function (x, y) {
if(!this.isSpawned) return false;
if(!this.spawned) return false;
// FIXME implement spectator movement here
this.doll.lookAt(x, y);
}
Player.prototype.grab = function(item) {
if(!this.isSpawned) return false;
if(!this.spawned) return false;
this.doll.grab(item);
item.beingGrabbed(this);
this.holdingItem = item;
};
Player.prototype.throw = function(options, item) {
if(!this.isSpawned) return false;
if(!this.spawned) return false;
this.doll.throw(item, options);
item.beingReleased(this);
this.holdingItem = null;
};
Player.prototype.kill = function(killedByPlayer, ragDollId) {
if(!this.isSpawned) return false;
if(!this.spawned) return false;
// FIXME: do something better then just respawn in GameController
if(this.holdingItem) {
@ -125,7 +129,7 @@ function (Doll, Settings, Nc, Exception, SpectatorDoll, RagDoll) {
var ragDoll = new RagDoll(this.physicsEngine, "ragDoll-" + this.id + "-" + ragDollId, options);
ragDoll.setVelocities(this.doll.getVelocities());
this.isSpawned = false;
this.spawned = false;
this.doll.destroy();
this.doll = null;