@@ -77,7 +77,12 @@ $('form').submit(function(){
7777 msg . timestamp = getTime ( ) ;
7878 msg . from = getQueryVariable ( "username" ) ;
7979 msg . text = $ ( '#m' ) . val ( ) ;
80- server . socket . emit ( 'message' , msg ) ;
80+ if ( msg . text [ 0 ] == '/' ) {
81+ command_handler ( msg . text ) ;
82+ }
83+ else {
84+ server . socket . emit ( 'message' , msg ) ;
85+ }
8186 $ ( '#m' ) . val ( '' ) ;
8287 return false ;
8388} ) ;
@@ -97,13 +102,68 @@ server.socket.on('message', function(msg){
97102 $ ( '#messages' ) . append ( $ ( '<li>' ) . text ( msg ) ) ;
98103} ) ;
99104server . socket . on ( 'user_move' , function ( move ) {
105+ console . log ( "{move} " + move . user + ": " + move . x + ", " + move . y + " (" + ROTATIONS [ move . rotation ] + ")" ) ;
106+
100107 if ( users [ move . user ] != undefined ) {
101108 users [ move . user ] . x = move . x ;
102109 users [ move . user ] . y = move . y ;
103110 users [ move . user ] . rotation = move . rotation ;
104111 }
112+ renderConnectedUsers ( ) ;
105113} ) ;
114+ server . socket . on ( 'place' , function ( cmd ) {
115+ console . log ( "new Tile(" + cmd . block_index + ", " + cmd . x + ", " + cmd . y + ");" ) ;
116+ tiles [ cmd . y ] [ cmd . x ] = new Tile ( cmd . block_index , cmd . x , cmd . y ) ;
117+ } ) ;
118+
119+ function command_handler ( msg ) {
120+ var com = msg . slice ( 1 ) . split ( ' ' ) ;
121+ //console.log(com);
122+ if ( com [ 0 ] == "place" ) {
123+ if ( com . length == 2 ) {
124+ place_block ( parseInt ( com [ 1 ] ) ) ;
125+ }
126+ else if ( com . length == 4 ) {
127+ place_block ( parseInt ( com [ 1 ] ) , parseInt ( com [ 2 ] ) , parseInt ( com [ 3 ] ) ) ;
128+ }
129+ else {
130+ $ ( '#messages' ) . append ( $ ( '<li>' ) . text ( "Invalid number of operands" ) ) ;
131+ }
132+ }
133+ else if ( com [ 0 ] == "list" ) {
134+ list_available_commands ( ) ;
135+ }
136+ else if ( com [ 0 ] == "help" ) {
137+ help ( ) ;
138+ }
139+ }
106140
141+ function place_block ( block_index , x , y ) {
142+ console . log ( "place_block(" + block_index + ", " + x + ", " + y + ");" ) ;
143+ if ( x == undefined && y == undefined ) {
144+ x = player_sprite . x ;
145+ y = player_sprite . y ;
146+ if ( ROTATIONS [ player_sprite . rotation ] == "up" ) {
147+ y -- ;
148+ }
149+ else if ( ROTATIONS [ player_sprite . rotation ] == "down" ) {
150+ y ++ ;
151+ }
152+ else if ( ROTATIONS [ player_sprite . rotation ] == "left" ) {
153+ x -- ;
154+ }
155+ else if ( ROTATIONS [ player_sprite . rotation ] == "right" ) {
156+ x ++ ;
157+ }
158+ }
159+ var cmd = {
160+ user : player ,
161+ block_index : block_index ,
162+ x : x ,
163+ y : y
164+ }
165+ server . socket . emit ( 'place' , cmd ) ;
166+ }
107167
108168/*
109169 -----------------
@@ -177,8 +237,9 @@ function Sprite(name, url, x, y) {
177237 }
178238 }
179239 this . updateLocation = function ( ) {
180- this . sprite . x = this . getX ( ) ; // ADD LERP
181- this . sprite . y = this . getY ( ) ; // ADD LERP
240+ //this.sprite.x = this.getX(); // ADD LERP
241+ //this.sprite.y = this.getY(); // ADD LERP
242+ game . add . tween ( this . sprite ) . to ( { x : this . getX ( ) , y : this . getY ( ) } , this . moveThreshold , null , true ) ;
182243 //console.log(this.sprite.scale.x);
183244 //this.sprite.scale.x = Math.abs(this.sprite.scale.x) - (this.rotation % 2) * 2 * Math.abs(this.sprite.scale.x);
184245 if ( ROTATIONS [ this . rotation ] == "up" ) {
@@ -391,6 +452,7 @@ function renderConnectedUsers(data) {
391452 ) ;
392453 user_sprites [ users [ i ] . username ] . setX ( users [ i ] . x ) ;
393454 user_sprites [ users [ i ] . username ] . setY ( users [ i ] . y ) ;
455+ user_sprites [ users [ i ] . username ] . setRotation ( users [ i ] . rotation ) ;
394456 user_sprites [ users [ i ] . username ] . updateLocation ( ) ;
395457 }
396458 }
@@ -456,15 +518,17 @@ function create() {
456518
457519function update ( ) {
458520 controls ( ) ;
459- playerSync ( ) ;
460521}
461522
462523function render ( ) {
463524 playerSync ( ) ;
464- renderConnectedUsers ( ) ;
465- game . debug . cameraInfo ( game . camera , 32 , 32 ) ;
525+ //playerSync();
526+ //renderConnectedUsers();
527+ //game.debug.cameraInfo(game.camera, 32, 32);
528+ /*
466529 if(player_sprite != undefined) {
467530 game.debug.spriteCoords(player_sprite.sprite, 32, 500);
468531 }
532+ */
469533 //game.debug.geom(chat.background);
470534}
0 commit comments