mirror of
https://github.com/logsol/chuck.js.git
synced 2026-05-11 18:47:35 +00:00
added Server and Client Game
This commit is contained in:
parent
e959c8e7a2
commit
bffb16e77c
5 changed files with 57 additions and 10 deletions
21
lib/Chuck/ClientGame.js
Normal file
21
lib/Chuck/ClientGame.js
Normal file
|
|
@ -0,0 +1,21 @@
|
||||||
|
define(["Chuck/Processors/ClientProcessor"], function(ClientProcessor) {
|
||||||
|
|
||||||
|
function ClientGame(networker){
|
||||||
|
this.networker = networker;
|
||||||
|
this.processor = new ClientProcessor();
|
||||||
|
}
|
||||||
|
|
||||||
|
ClientGame.prototype.loadLevel = function(path) {
|
||||||
|
this.processor.loadLevel(path);
|
||||||
|
}
|
||||||
|
|
||||||
|
ClientGame.prototype.processGameCommand = function(command, options){
|
||||||
|
console.log('(not implemented) processGameCommand:', command, options);
|
||||||
|
}
|
||||||
|
|
||||||
|
ClientGame.prototype.destruct = function(){
|
||||||
|
this.processor.destruct();
|
||||||
|
}
|
||||||
|
|
||||||
|
return ClientGame;
|
||||||
|
});
|
||||||
|
|
@ -9,7 +9,8 @@ var requires = [
|
||||||
"RequestAnimationFrame"
|
"RequestAnimationFrame"
|
||||||
];
|
];
|
||||||
|
|
||||||
define(requires, function(ViewController, PhysicsEngine, Player, InputControlUnit, Settings, Box2D, Level, requestAnimFrame){
|
define(requires,
|
||||||
|
function(ViewController, PhysicsEngine, Player, InputControlUnit, Settings, Box2D, Level, requestAnimFrame) {
|
||||||
|
|
||||||
function ClientGame () {
|
function ClientGame () {
|
||||||
this.init();
|
this.init();
|
||||||
|
|
|
||||||
21
lib/Chuck/ServerGame.js
Normal file
21
lib/Chuck/ServerGame.js
Normal file
|
|
@ -0,0 +1,21 @@
|
||||||
|
define(["Chuck/Processors/ServerProcessor"], function(ServerProcessor) {
|
||||||
|
|
||||||
|
function ServerGame(chanel) {
|
||||||
|
this.chanel = chanel;
|
||||||
|
this.processor = new ServerProcessor();
|
||||||
|
}
|
||||||
|
|
||||||
|
ServerGame.prototype.loadLevel = function(path) {
|
||||||
|
this.processor.loadLevel(path);
|
||||||
|
}
|
||||||
|
|
||||||
|
ServerGame.prototype.processGameCommand = function(command, options) {
|
||||||
|
console.log('(not implemented) processGameCommand:', command, options);
|
||||||
|
}
|
||||||
|
|
||||||
|
ServerGame.prototype.destruct = function() {
|
||||||
|
this.processor.destruct();
|
||||||
|
}
|
||||||
|
|
||||||
|
return ServerGame;
|
||||||
|
});
|
||||||
|
|
@ -1,8 +1,8 @@
|
||||||
define(["Protocol/Helper", "Chuck/Game"], function(ProtocolHelper, Game) {
|
define(["Protocol/Helper", "Chuck/ClientGame"], function(ProtocolHelper, ClientGame) {
|
||||||
|
|
||||||
function Networker(socketLink) {
|
function Networker(socketLink) {
|
||||||
this.socketLink = socketLink;
|
this.socketLink = socketLink;
|
||||||
this.game = null;
|
this.clientGame = null;
|
||||||
|
|
||||||
this.init();
|
this.init();
|
||||||
}
|
}
|
||||||
|
|
@ -36,8 +36,8 @@ define(["Protocol/Helper", "Chuck/Game"], function(ProtocolHelper, Game) {
|
||||||
}
|
}
|
||||||
|
|
||||||
Networker.prototype.onDisconnect = function() {
|
Networker.prototype.onDisconnect = function() {
|
||||||
this.game.destruct();
|
this.clientGame.destruct();
|
||||||
this.game = null;
|
this.clientGame = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
Networker.prototype.join = function(channelName){
|
Networker.prototype.join = function(channelName){
|
||||||
|
|
@ -50,7 +50,8 @@ define(["Protocol/Helper", "Chuck/Game"], function(ProtocolHelper, Game) {
|
||||||
}
|
}
|
||||||
|
|
||||||
Networker.prototype.onJoinSuccess = function(channelName) {
|
Networker.prototype.onJoinSuccess = function(channelName) {
|
||||||
this.game = new Game(this);
|
this.clientGame = new ClientGame(this);
|
||||||
|
this.clientGame.loadLevel("default.json")
|
||||||
}
|
}
|
||||||
|
|
||||||
Networker.prototype.processControlCommand = function(command, options){
|
Networker.prototype.processControlCommand = function(command, options){
|
||||||
|
|
@ -60,7 +61,7 @@ define(["Protocol/Helper", "Chuck/Game"], function(ProtocolHelper, Game) {
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'gameCommand':
|
case 'gameCommand':
|
||||||
this.game.processGameCommand(options);
|
this.clientGame.processGameCommand(options);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
|
|
|
||||||
|
|
@ -1,10 +1,9 @@
|
||||||
define(["Chuck/Game"], function(Game) {
|
define(["Chuck/ServerGame"], function(ServerGame) {
|
||||||
|
|
||||||
function Channel(name) {
|
function Channel(name) {
|
||||||
this.name = name;
|
this.name = name;
|
||||||
this.users = {};
|
this.users = {};
|
||||||
this.game = new Game();
|
this.serverGame = new ServerGame(this);
|
||||||
// create game here
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Channel.validateName = function(name){
|
Channel.validateName = function(name){
|
||||||
|
|
@ -19,6 +18,10 @@ define(["Chuck/Game"], function(Game) {
|
||||||
delete this.users[user.id];
|
delete this.users[user.id];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Channel.prototype.sendToAllUsers = function(package) {
|
||||||
|
console.log("not implemented sendToAllUsers: " + JSON.stringify(package))
|
||||||
|
}
|
||||||
|
|
||||||
return Channel;
|
return Channel;
|
||||||
|
|
||||||
});
|
});
|
||||||
Loading…
Add table
Add a link
Reference in a new issue