mirror of
https://github.com/logsol/chuck.js.git
synced 2026-05-11 18:47:35 +00:00
Merge branch 'restructuring' of github.com:logsol/chuck.js into restructuring
This commit is contained in:
commit
6f28a10149
4 changed files with 27 additions and 54 deletions
|
|
@ -1,40 +1,24 @@
|
||||||
define([
|
define([
|
||||||
|
"Game/Core/GameController",
|
||||||
|
"Game/Server/Physics/Engine",
|
||||||
"Game/Client/View/ViewController",
|
"Game/Client/View/ViewController",
|
||||||
"Game/Core/Physics/Engine",
|
|
||||||
"Game/Core/Player",
|
|
||||||
"Game/Client/Control/KeyboardController",
|
"Game/Client/Control/KeyboardController",
|
||||||
"Game/Config/Settings",
|
|
||||||
"Game/Core/Loader/Level",
|
|
||||||
"Lib/Vendor/Box2D",
|
|
||||||
"Lib/Utilities/RequestAnimFrame"
|
"Lib/Utilities/RequestAnimFrame"
|
||||||
],
|
],
|
||||||
|
|
||||||
function(ViewController, PhysicsEngine, Player, KeyboardController, Settings, Level, Box2D, requestAnimFrame) {
|
function(Parent, PhysicsEngine, ViewController, KeyboardController, requestAnimFrame) {
|
||||||
|
|
||||||
function GameController (clientGame) {
|
function GameController () {
|
||||||
this.clientGame = clientGame;
|
this.me;
|
||||||
this.init();
|
this.keyboardController;
|
||||||
};
|
|
||||||
|
|
||||||
GameController.prototype.init = function() {
|
Parent.apply(this, new PhysicsEngine());
|
||||||
this.viewController = new ViewController();
|
this.viewController = new ViewController();
|
||||||
this.physicsEngine = new PhysicsEngine();
|
this.update();
|
||||||
|
|
||||||
this.update();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
GameController.prototype.loadLevel = function(path) {
|
GameController.prototype = Object.create(Parent);
|
||||||
if (this.level) {
|
|
||||||
this.level.unload();
|
|
||||||
}
|
|
||||||
|
|
||||||
this.level = new Level(path, this.physicsEngine);
|
|
||||||
this.level.loadLevelInToEngine();
|
|
||||||
}
|
|
||||||
|
|
||||||
GameController.prototype.getPhysicsEngine = function() {
|
|
||||||
return this.physicsEngine;
|
|
||||||
}
|
|
||||||
|
|
||||||
GameController.prototype.getMe = function() {
|
GameController.prototype.getMe = function() {
|
||||||
return this.me;
|
return this.me;
|
||||||
|
|
@ -48,29 +32,18 @@ function(ViewController, PhysicsEngine, Player, KeyboardController, Settings, Le
|
||||||
this.viewController.update();
|
this.viewController.update();
|
||||||
|
|
||||||
if(this.me) {
|
if(this.me) {
|
||||||
this.KeyboardController.update();
|
this.keyboardController.update();
|
||||||
this.me.update();
|
this.me.update();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
GameController.prototype.destruct = function() {
|
GameController.prototype.destroy = function() {
|
||||||
|
Parent.prototype.destroy.call(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
GameController.prototype.spawnNewPlayerWithId = function(id) {
|
GameController.prototype.meJoined = function(user) {
|
||||||
var player = new Player(this.physicsEngine, id, null);
|
this.me = this.userJoined(user);
|
||||||
player.spawn(100, 0);
|
this.keyboardController = new KeyboardController(this.me, this);
|
||||||
this.physicsEngine.setCollisionDetector(player);
|
|
||||||
return player;
|
|
||||||
}
|
|
||||||
|
|
||||||
GameController.prototype.spawnMeWithId = function(id) {
|
|
||||||
this.me = this.spawnNewPlayerWithId(id);
|
|
||||||
this.KeyboardController = new KeyboardController(this.me, this);
|
|
||||||
}
|
|
||||||
|
|
||||||
GameController.prototype.sendGameCommand = function(command, options) {
|
|
||||||
this.clientGame.sendGameCommand(command, options);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
GameController.prototype.processGameCommand = function(command, options) {
|
GameController.prototype.processGameCommand = function(command, options) {
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,7 @@ define(["Game/Core/Protocol/Helper", "Game/Client/GameController"], function(Pro
|
||||||
|
|
||||||
function Networker(socketLink) {
|
function Networker(socketLink) {
|
||||||
this.socketLink = socketLink;
|
this.socketLink = socketLink;
|
||||||
this.GameController = null;
|
this.gameController = null;
|
||||||
|
|
||||||
this.init();
|
this.init();
|
||||||
}
|
}
|
||||||
|
|
@ -36,8 +36,8 @@ define(["Game/Core/Protocol/Helper", "Game/Client/GameController"], function(Pro
|
||||||
}
|
}
|
||||||
|
|
||||||
Networker.prototype.onDisconnect = function() {
|
Networker.prototype.onDisconnect = function() {
|
||||||
this.GameController.destruct();
|
this.gameController.destruct();
|
||||||
this.GameController = null;
|
this.gameController = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
Networker.prototype.join = function(channelName){
|
Networker.prototype.join = function(channelName){
|
||||||
|
|
@ -50,19 +50,19 @@ define(["Game/Core/Protocol/Helper", "Game/Client/GameController"], function(Pro
|
||||||
}
|
}
|
||||||
|
|
||||||
Networker.prototype.onJoinSuccess = function(options) {
|
Networker.prototype.onJoinSuccess = function(options) {
|
||||||
this.GameController = new GameController(this, options.id);
|
this.gameController = new GameController(this, options.id);
|
||||||
this.GameController.loadLevel("default.json")
|
this.gameController.loadLevel("default.json")
|
||||||
console.log("Joined " + options.channelName);
|
console.log("Joined " + options.channelName);
|
||||||
|
|
||||||
if (options.userIds && options.userIds.length > 0) {
|
if (options.userIds && options.userIds.length > 0) {
|
||||||
for(var i = 0; i < options.userIds.length; i++) {
|
for(var i = 0; i < options.userIds.length; i++) {
|
||||||
this.GameController.userJoined(options.userIds[i])
|
this.gameController.userJoined(options.userIds[i])
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Networker.prototype.onUserJoined = function(userId) {
|
Networker.prototype.onUserJoined = function(userId) {
|
||||||
this.GameController.userJoined(userId);
|
this.gameController.userJoined(userId);
|
||||||
console.log("User " + userId + " joined");
|
console.log("User " + userId + " joined");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -71,7 +71,7 @@ define(["Game/Core/Protocol/Helper", "Game/Client/GameController"], function(Pro
|
||||||
}
|
}
|
||||||
|
|
||||||
Networker.prototype.onUserLeft = function(userId) {
|
Networker.prototype.onUserLeft = function(userId) {
|
||||||
this.GameController.userLeft(userId);
|
this.gameController.userLeft(userId);
|
||||||
}
|
}
|
||||||
|
|
||||||
Networker.prototype.processControlCommand = function(command, options) {
|
Networker.prototype.processControlCommand = function(command, options) {
|
||||||
|
|
@ -82,7 +82,7 @@ define(["Game/Core/Protocol/Helper", "Game/Client/GameController"], function(Pro
|
||||||
|
|
||||||
case 'gameCommand':
|
case 'gameCommand':
|
||||||
for(var gameCommand in options) {
|
for(var gameCommand in options) {
|
||||||
this.GameController.processGameCommand(gameCommand, options[gameCommand]);
|
this.gameController.processGameCommand(gameCommand, options[gameCommand]);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -32,12 +32,12 @@ function(Engine, Level, ) {
|
||||||
for(var player in this.players) {
|
for(var player in this.players) {
|
||||||
this.players[player].destroy();
|
this.players[player].destroy();
|
||||||
}
|
}
|
||||||
delete this.players;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
GameController.prototype.userJoined = function(user) {
|
GameController.prototype.userJoined = function(user) {
|
||||||
var player = new Player(this.physicsEngine, id);
|
var player = new Player(id, this.physicsEngine);
|
||||||
this.players[user.id] = player;
|
this.players[user.id] = player;
|
||||||
|
return player;
|
||||||
}
|
}
|
||||||
|
|
||||||
GameController.prototype.userLeft = function(user) {
|
GameController.prototype.userLeft = function(user) {
|
||||||
|
|
|
||||||
|
|
@ -5,7 +5,7 @@ define([
|
||||||
|
|
||||||
function(Doll, Settings) {
|
function(Doll, Settings) {
|
||||||
|
|
||||||
function Player (physicsEngine, id, repository) {
|
function Player (id, physicsEngine, repository) {
|
||||||
this.physicsEngine = physicsEngine;
|
this.physicsEngine = physicsEngine;
|
||||||
this.id = id;
|
this.id = id;
|
||||||
this.repository = repository;
|
this.repository = repository;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue