websocket - 2D multiplayer game real-time comunication JavaScript -


i programming multi-player game javascript , html. objective need communication between players. how can manage this?

my code:

    enchant();     window.onload = function() {     var game = new game(320, 320); 

here first question: should counted how many player now, entered room last. number should assigned player. i´d solve function.

    var my_bear = get_player_number();      game.preload('chara1.gif');     game.fps=15;     var bears = [];     game.onload = function() {         var ix;         var bear;         (ix = 0; ix < 5; ix++) {             bear=new sprite(32, 32);             bear.image = game.assets['chara1.gif'];             bear.frame = 4;             bear.x=math.random()*300;             bear.y=math.random()*300;             game.rootscene.addchild(bear);             bears.push(bear);         }     };     game.start();     var addit=6;     document.addeventlistener('keyup',function (evt) {         if(evt.keycode == 38){bears[my_bear-1].y-=addit;}         if(evt.keycode == 39){bears[my_bear-1].x+=addit;}         if(evt.keycode == 40){bears[my_bear-1].y+=addit;}         if(evt.keycode == 37){bears[my_bear-1].x-=addit;}     }); } 

due simplification of programme have 5 bears. 1 of them can control arrow-keys (the bear value of variable “my_bear”).

but it´s still single-player game yet...

init_other_players(my_bear); 

a function perfect, detects , indicates movement of player on other computer. webspace 2 domains available programme.



i´m looking forward helpful answer, thank !!!

first, if want multiplayer, need manage rooms , such, need server. games, i'd suggest nodejs. node server app built in js, language familiar with. don't need know node now, running enough while progress on code, after i'd should bit more it.

after, i'd socket.io lets manage websockets , therefore communication between users , server. there tutorials chat in started section of website let know basics of communication between users.

from there can create logic rooms , rest of game! may lot learn but, honstly, it's explained , quite easy grasp of.


Comments

Popular posts from this blog

java - Static nested class instance -

c# - Bluetooth LE CanUpdate Characteristic property -

JavaScript - Replace variable from string in all occurrences -