Jump to content

multiplayer logic


smooth_penguin
 Share

Recommended Posts

Hey!

 

 I'm using phaserjs and Im building a game which will involve players joining at random points in time,

I'd like to confirm if my coding approach is right,

 

As you can see below, each player is created using add_hero() instead of create()

 

 

 

 13         var add_hero =  function(name, channel, ts){
 14                 heroes[name] = {};
 15                 heroes[name]['name'] = name;
 16                 heroes[name]['id'] = hero_count;
 17                 heroes[name]['connected'] = 1;
 18                 heroes[name]['last_input_ts'] = ts;
 19
 20                 heroes[name] = games.add.sprite(0, 0, 'hero_' + hero_count );
 21
 22                 heroes[name].body.collideWorldBounds = true;
 23                 heroes[name].body.bounce.y = 0.3;
 24                 heroes[name].body.bounce.x = 0.3;
 25
 26                 heroes[name].body.velocity.x = 0;
 27                 heroes[name].body.velocity.y = 0;
 28                 heroes[name].body.angularVelocity = 0;
 29
 30         }
 31
 

 

 

if I need to check for collision detection or any other task that will involves looping through all players/items, would this be right?

 

 

 

function update() {

                     for var hero in heroes{
                         game.physics.overlap(hero, gifts, collect_gift, null, this);
                     }

....

...

 

 

Thanks for any pointers/advice/help :)

 

 

 

 

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...