work in progress... worked on channel attributes and game goal. fixes #45 and references #48

This commit is contained in:
logsol 2014-03-30 00:12:04 +01:00
parent 039213cf50
commit 55256ada95
23 changed files with 409 additions and 110 deletions

View file

@ -7,7 +7,9 @@ define([
function (PhysicsEngine, TiledLevel, Player, Nc) {
function GameController () {
function GameController (options) {
this.options = options;
this.players = {};
this.level = null;
this.gameObjects = null;
@ -16,10 +18,12 @@ function (PhysicsEngine, TiledLevel, Player, Nc) {
this.physicsEngine = new PhysicsEngine();
this.physicsEngine.setCollisionDetector();
Nc.on(Nc.ns.core.game.events.level.loaded, this.onLevelLoaded, this);
this.ncTokens = [
Nc.on(Nc.ns.core.game.gameObject.add, this.onGameObjectAdd, this),
Nc.on(Nc.ns.core.game.gameObject.remove, this.onGameObjectRemove, this)
];
Nc.on(Nc.ns.core.game.gameObject.add, this.onGameObjectAdd, this);
Nc.on(Nc.ns.core.game.gameObject.remove, this.onGameObjectRemove, this);
this.loadLevel(options.levelUid);
this.update();
}
@ -62,15 +66,28 @@ function (PhysicsEngine, TiledLevel, Player, Nc) {
this.loadLevel(this.level.uid);
};
GameController.prototype.onLevelLoaded = function() {
};
GameController.prototype.destroy = function () {
for(var player in this.players) {
this.players[player].destroy();
// 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++) {
Nc.off(this.ncTokens[i]);
};
for (var key in this.gameObjects) {
for (var i = 0; i < this.gameObjects[key].length; i++) {
var gameObject = this.gameObjects[key][i];
this.onGameObjectRemove(key, gameObject);
gameObject.destroy();
};
};
this.physicsEngine.destroy();
}
/*

View file

@ -3,10 +3,11 @@ define([
"Lib/Vendor/Box2D",
"Game/Config/Settings",
"Game/" + GLOBALS.context + "/Collision/Detector",
"Game/" + GLOBALS.context + "/GameObjects/Item"
"Game/" + GLOBALS.context + "/GameObjects/Item",
"Lib/Utilities/NotificationCenter"
],
function (Parent, Box2D, Settings, CollisionDetector, Item) {
function (Parent, Box2D, Settings, CollisionDetector, Item, Nc) {
function Doll (physicsEngine, uid, player) {
@ -36,6 +37,8 @@ function (Parent, Box2D, Settings, CollisionDetector, Item) {
this.createFixtures();
this.body.SetActive(false);
Nc.trigger(Nc.ns.core.game.gameObject.add, 'animated', this);
}
Doll.prototype = Object.create(Parent.prototype);
@ -368,5 +371,9 @@ function (Parent, Box2D, Settings, CollisionDetector, Item) {
}
};
Doll.prototype.destroy = function() {
Nc.trigger(Nc.ns.core.game.gameObject.remove, 'animated', this);
};
return Doll;
});

View file

@ -3,10 +3,11 @@ define([
"Lib/Vendor/Box2D",
"Lib/Utilities/Options",
"Game/Config/Settings",
"Lib/Utilities/Exception"
"Lib/Utilities/Exception",
"Lib/Utilities/NotificationCenter"
],
function (Parent, Box2D, Options, Settings, Exception) {
function (Parent, Box2D, Options, Settings, Exception, Nc) {
function Item(physicsEngine, uid, options) {
@ -33,6 +34,8 @@ function (Parent, Box2D, Options, Settings, Exception) {
this.createFixture();
this.body.ResetMassData();
this.flipDirection = 1;
Nc.trigger(Nc.ns.core.game.gameObject.add, 'animated', this);
}
Item.prototype = Object.create(Parent.prototype);
@ -136,6 +139,11 @@ function (Parent, Box2D, Options, Settings, Exception) {
body.SetAngularVelocity(Settings.MAX_THROW_ANGULAR_VELOCITY * x);
};
Item.prototype.destroy = function() {
Nc.trigger(Nc.ns.core.game.gameObject.remove, 'animated', this);
Parent.prototype.destroy.call(this);
};
return Item;

View file

@ -2,15 +2,18 @@ define([
"Game/" + GLOBALS.context + "/GameObjects/GameObject",
"Lib/Vendor/Box2D",
"Game/Config/Settings",
"Lib/Utilities/Exception"
"Lib/Utilities/Exception",
"Lib/Utilities/NotificationCenter"
],
function (Parent, Box2D, Settings, Exception) {
function (Parent, Box2D, Settings, Exception, Nc) {
function Tile(physicsEngine, uid, options) {
this.options = options;
Parent.call(this, physicsEngine, uid);
this.createPhysicTile(this.options);
Nc.trigger(Nc.ns.core.game.gameObject.add, 'fixed', this);
}
Tile.prototype = Object.create(Parent.prototype);
@ -112,6 +115,10 @@ function (Parent, Box2D, Settings, Exception) {
Tile.prototype.addVec = function (vs, m1, m2) {
return vs.push(new Box2D.Common.Math.b2Vec2(this.mkArg(m1), this.mkArg(m2)));
}
Tile.prototype.destroy = function() {
Nc.trigger(Nc.ns.core.game.gameObject.remove, 'fixed', this);
};
return Tile;

View file

@ -10,11 +10,10 @@ define([
], function (Settings, Box2D, Nc, CollisionDetector, Tile, Item, Skateboard, RagDoll) {
function Level (uid, engine, gameObjects) {
function Level (uid, engine) {
this.uid = uid;
this.engine = engine;
this.levelObject = null;
this.gameObjects = gameObjects;
this.isLoaded = false;
this.load(this.uid);
}
@ -32,11 +31,13 @@ define([
}
Level.prototype.destroy = function () {
/*
for (var key in this.gameObjects) {
for (var i = 0; i < this.gameObjects[key].length; i++) {
this.gameObjects[key][i].destroy();
}
}
*/
this.isLoaded = false;
}
@ -52,7 +53,9 @@ define([
var options = tiles[i];
//options.m = this.tileAtPositionExists(options.x, options.y - 1) ? "Soil" : "GrassSoil";
options.m = "Soil";
this.gameObjects.fixed.push(new Tile(this.engine, "tile-" + i, options));
//this.gameObjects.fixed.push(
new Tile(this.engine, "tile-" + i, options);
//);
}
}
@ -66,7 +69,7 @@ define([
var options = items[i];
var uid = "item-" + i;
var item = this.createItem(uid, options);
this.gameObjects.animated.push(item); // FIXME: use Nc
//this.gameObjects.animated.push(item);
};
};

View file

@ -13,10 +13,10 @@ define([
], function (Parent, Settings, ItemSettings, Box2D, Options, Exception, CollisionDetector, Tile, Item, Skateboard) {
// Public
function TiledLevel (path, engine, gameObjects) {
function TiledLevel (path, engine) {
this.levelData = null;
Parent.call(this, path, engine, gameObjects);
Parent.call(this, path, engine);
}
TiledLevel.prototype = Object.create(Parent.prototype);
@ -51,7 +51,9 @@ define([
y: parseInt(i / collisionLayer.height , 10)
}
this.gameObjects.fixed.push(new Tile(this.engine, "tile-" + i, options));
//this.gameObjects.fixed.push(
new Tile(this.engine, "tile-" + i, options);
//);
}
} else {
@ -69,7 +71,7 @@ define([
var uid = "item-" + i;
var item = this.createItem(uid, options);
this.gameObjects.animated.push(item);
//this.gameObjects.animated.push(item);
};
};

View file

@ -60,6 +60,10 @@ function (Settings, Box2D, CollisionDetector, Nc) {
this.processWorldQueue();
}
Engine.prototype.destroy = function() {
delete this.world;
};
return Engine;
});

View file

@ -40,7 +40,6 @@ function (Doll, Settings, Nc, Exception, SpectatorDoll, RagDoll) {
this.doll = new Doll(this.physicsEngine, "doll-" + this.id, this);
this.doll.spawn(x, y);
this.isSpawned = true;
Nc.trigger(Nc.ns.core.game.gameObject.add, 'animated', this.doll);
}
Player.prototype.getPosition = function () {
@ -120,14 +119,13 @@ function (Doll, Settings, Nc, Exception, SpectatorDoll, RagDoll) {
this.isSpawned = false;
Nc.trigger(Nc.ns.core.game.gameObject.remove, 'animated', this.doll);
this.doll.destroy();
this.doll = null;
this.ragDoll = ragDoll;
Nc.trigger(Nc.ns.core.game.player.killed, this);
Nc.trigger(Nc.ns.core.game.player.killed, this, killedByPlayer);
};
Player.prototype.update = function () {
@ -148,7 +146,6 @@ function (Doll, Settings, Nc, Exception, SpectatorDoll, RagDoll) {
this.spectatorDoll.destroy();
if(this.doll) this.doll.destroy();
if(this.ragDoll) this.ragDoll.destroy();
}
Player.prototype.setPlayerController = function(playerController) {