Created
March 27, 2012 14:53
-
-
Save ruby0x1/2216575 to your computer and use it in GitHub Desktop.
Multi-player games in HTML5 : Server Side Game Class
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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