Login | Register

Big multiplayer games

July 31, 2006, 13:45 by Calle
[loading]
-->
After you have learnt to create multiplayer games comes the challenge to create multiplayer games with more than two players.

In the two-player multiplayer game you probably had a variable, called global.master or something, maybe global.host which was set to either true or false depending on whether you joined or hosted a session. This time you will have a similar variable, which we might call global.player.

Let's say that your game is a game with eight players. They all wait in a kind of waiting room until all of the players are in.
<div style="clear: both;">In the creation event in that waiting room you set global.player like this:

for (i=0, i<8, i+=1) {
if (mplay_data_read(i)==0) && (global.player==-1) {
mplay_data_write(i,1);
global.player = i;
}
}
</div>

The idea is that all write themselves into the shared data communication, and if they for some reasons leave, you will also be able to write his number to zero and by doing so make it possible for other players to take his place. If this works properly each player should now have different numbers when they get to the game room.

In the game room you may do as usual. Have one object for each player and in all user-interaction related code put if (global.player=5), or whatever, depending on which object your in. If you are in object five, then five is good.

I hope you got the principle. Ask if there is anything you wonder (by commenting preferably).

Comments

Loading comments... [loading]
.
Users logged in:

game maker articles, game maker examples, game maker tutorials, gmtutorials, game maker questions and answers, game maker crash course, how to create games