Yet-another Multiplayer Demo (with capx)

Show us your completed creations made in Construct 2

Post » Tue Feb 28, 2012 1:36 am

Update 9/22/2012: Please try @JohnnySheffield new plugin at http://www.scirra.com/forum/plugin-zack0wack0s-socketio-mod_topic56503.html. He updated the plugin to work with minify and other goodness. Thank you.

Based on the work of Zack0Wack0, I was able to modify a little bit his excellent socket.io plugin and created a small top-down shooter game.

To download the demo and the modified version of the socket.io plugin, please go here and download the "socket-io-mod.zip" file.

Before you can use the plugin and the example, please install node.js and socket.io as Zack0Wack0 explained in his post. If you are using Windows, I strongly suggest that you open the CMD, cd to C:\node_modules (create that folder is not present) and run the "npm install socket.io" from there. It seems that Node.js has "C:\node_modules" hardcoded as one of the paths to find installed modules.

Instructions

Once you install node.js and socket.io, you can CD into the folder that contains example_server.js and type "node example_server.js" in the commnad prompt. The server will run listening for connections on port 8099.

Open the capx and run it, make sure the "ChooseServer" layout is the 1st to run.

For server address you can enter the IP of the computer that is running the server, if it is the same computer, you can enter 127.0.0.1.

Enter 8099 in the server port and click Connect.

If you run the capx in another computer, make sure you enter the appropriate IP address of the computer running the node.js server.

You can also try to run two separate instances of the game in the same computer by just opening two broser windows and going to the address where you game is (default for preview localhost:5000).

I have only tested it in Chrome and Windows. Also, if you want to export the project, avoid checking "minify" for some reason I can't get it working with that, I think Zack0Wack0had the same problem.

You can watch a video of the sample game in a LAN here

Update 4/19/12:

I wrote a new post in my blog on how the multiplayer demo works in Construct2:

http://jptarqu.blogspot.com/2012/04/how-to-create-online-multiplayer-html5.html

I also uploaded a new video showing an iPad connecting to the game:

http://www.youtube.com/watch?v=vIdpc5N0pZwjuantar2012-09-22 21:27:06
B
26
S
7
G
3
Posts: 118
Reputation: 4,264

Post » Tue Feb 28, 2012 9:09 am

Good job! :D
B
19
S
3
G
5
Posts: 98
Reputation: 4,647

Post » Tue Feb 28, 2012 9:49 am

Great!!! But you have to type a IP and a port number so practically is it usable in a game? If you want to search for a game ect the use would need to know there IP adress right? Or can we find that out within c2?

I just want to know a practical way of using this in a game.
B
29
S
12
G
7
Posts: 740
Reputation: 7,849

Post » Tue Feb 28, 2012 2:40 pm

If you want C2 to display a list of available servers, i.e. a lobby, you would have to code the display logic in C2 and then store the list of servers in a server where anybody can query the list.

One way of accomplishing that is to create a server side app (php, asp.net, gae, etc) that receives http POST messages from c2 clients who want to host a game. The server side app will store the name of the server and its public ip.
the servers side app would also accept Get messages from c2 clients who want to retrieve the list of available servers. The server side app would pull the list from its database. Because the list will have the ip of the servers, you can add logic to c2 to use that ip when the user chooses the server and clicks Connect.

There are many ways of implementing lobbys, but i think the above would be the easiest for c2 users.
B
26
S
7
G
3
Posts: 118
Reputation: 4,264

Post » Tue Feb 28, 2012 3:34 pm

Unfortunately I am not so good with server side scripting like that so I guess multiplayer is something I cannot do.
B
29
S
12
G
7
Posts: 740
Reputation: 7,849

Post » Tue Feb 28, 2012 7:11 pm

[QUOTE=juantar] If you want C2 to display a list of available servers, i.e. a lobby, you would have to code the display logic in C2 and then store the list of servers in a server where anybody can query the list.[/QUOTE]
Thanks, juantar, for a good overview of how multiplayer games can be made available over the internet (as opposed to over a LAN).

For those interested in the nuts and bolts of implementing a lobby server, here's a good practical article. To quote from the intro explanation of how a lobby functions:

"A lobby is in essence a collection of players and a collection of games. Each player may be in one or more games, and each game may contain one or more players. Players should be able to create, join, leave and start games, and they should be able to see which games are already available and which players are in the 'room', although this is simply a case of allowing the UI to see that data. A lobby should also fire events when players join or leave the server, or the state of a game changes (i.e. a new player joins, or it moves from setup to 'in play'), so that a UI can know when to update."Velojet2012-02-28 19:12:34
B
105
S
20
G
12
Posts: 549
Reputation: 20,320

Post » Tue Feb 28, 2012 7:25 pm

I get making the visual side of things, I meant how can I find a game, for example user loads up game, goes into multiplayer mode. Somehow we get his IP address then we need to find a random ip adress of another user and somehow connect the two right? But how can I do this..?

Can the game be hosted on a web server? Or does the multiplayer only work locally?

Thanks.
B
29
S
12
G
7
Posts: 740
Reputation: 7,849

Post » Tue Feb 28, 2012 7:50 pm

[QUOTE=smitchell]Somehow we get his IP address then we need to find a random ip adress of another user and somehow connect the two right? But how can I do this..?[/QUOTE]
Through a game lobby. See my and junatar's previous posts.

[QUOTE=smitchell]Can the game be hosted on a web server?[/QUOTE]
Yes, indeed. That's what the game lobby does - connects you with a server hosting a game (and connecting you with other players of that game).

<EDIT> To be more precise, the game is split into a component that runs locally and a component that runs on the server, managing the interactions between players.

For example, in a single player FPS game running locally where your enemies are created and controlled by the (Construct 2) code, in a multiplayer game, where your enemies are other players, their actions have to be communicated by the server component of the game.Velojet2012-02-28 20:40:55
B
105
S
20
G
12
Posts: 549
Reputation: 20,320

Post » Tue Feb 28, 2012 8:56 pm

@Velojet, Thanks for the help. I think im getting there in terms of understanding. But the multiplayer needs to run of node.js right? can a webserver run node.js?

I think I need a example, would that be possible?

Thanks.
B
29
S
12
G
7
Posts: 740
Reputation: 7,849

Post » Tue Feb 28, 2012 9:48 pm

Every time I type "npm install socket.io" it just puts

...

[FIXED]

Disregard me xDIndex2012-02-28 22:20:53
B
72
S
10
G
6
Posts: 104
Reputation: 7,550

Next

Return to Completed Creations

Who is online

Users browsing this forum: No registered users and 1 guest