Skip to content

Instantly share code, notes, and snippets.

@ruby0x1
Created March 27, 2012 14:53
Show Gist options
  • Save ruby0x1/2216575 to your computer and use it in GitHub Desktop.
Save ruby0x1/2216575 to your computer and use it in GitHub Desktop.
Multi-player games in HTML5 : Server Side Game Class
var Game = Class.extend({
init : function( player, opponent ) {
this.id = UUID();
this.player = player;
this.opponent = opponent;
},
create : function(){
//set flags on host
this.player.ingame = true;
this.player.currentgame = this;
this.player.serverplayer = new serverPlayer( this.player );
//set flags on opponent
this.opponent.ingame = true;
this.opponent.currentgame = this;
//Set up the game mirror state. Only x ever changes.
this.opponent.block = {
position : { x:0 },
}
//add to the list of games that are active
server.games.push( game );
},
emit : function( ev, obj ) {
//send message to all players
this.player.socket.emit( ev,obj );
this.opponent.socket.emit( ev,obj );
},
update : function( deltatime ) {
//update clients position
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment