Online game using "Dplay"
Author: | Diab
|
Submitted: | 10th July, 2003
|
Views: | 5610
| Rated: |
|
|
Reason for this article: Last 5 minutes i have seen 2 posts about making an online game, both saying you need a server. This is untrue.
The cnc/tgf/mmf extension "Dplay" is a verry good tool for getting a game online, it needs no server and only requires you to directly connect with the person you will be playing.
To send infomation over Dplay is verry simple andonly requires a few events for most 2 player games, using 3 or more players requires you to tell the game who is sending what infomation so its a little tricky around that part, for now we will stick to 2 players.
First things first is to explain the extension for those who do not know. Dplay connects to other Dplay extensions over lan/ip style connections, For example to play your friend you will need him to be on a local area network with yourself or have his IP to connect to (IP is your internet adress to direct infomation) be careful who you give you'r IP to.
Dplay has its own GUID, this tells another Dplay on connection if it can connect to this game, for example if you made a shooting game from above and your friend made a side on racing game, both using Dplay extensions, if the GUID was the same for both Dplay's then you could connect and causing strange player posisions and events. mmmm nice.
When you first place down the Dplay extension it will create a random GUID, to use the same ID for other frames in your game copy and paste the guid in the extensions setup or grab the extension from the frame using the left side item bar going back a level or two to find it in your game.
The fun part, making a 2 player platform game!
NOTE! Dplay needs the event "Is Message(s) Waiting ?" = "Process A Msg" on every new level you use Dplay on, otherwise nothing netwise will work.
First place down a Dplay object in a game, lets make a new game here so nothing is in the way. with the Dplay extension down and he GUID set (use what it gives, don't type your name or something) create something that will be used for connecting andhosting. lets say 2 actives that are clickable by the mouse with the text HOST and CONN on them. In the event editor set it up so when you click on HOST:
*Set username to ""
*Set max users to 2
*Set session name to "Dplay Test"
*Try to HOST!
NOTE that there is alot more you can set before you host, take a look around but most are unneeded for us at the moment.
The name part can be anything, you can make it grab a name from any text edit box you use, players are set to 2 but you could leave it at anything as it won't effect any events BUT if a 3rd person tried to join it may mess up.
Session name is what someone see's as they connect to the HOST, so thry add your ip, connect (explained below) and they then see a box with a game name in it with the amount of playable slots. double click to join.
Now we need the CONN button working (connect), so lets set it up so when clicked on:
*Set username to ""
*Try to CONNECT
Nice and simple, now this will bring up a window for adding an IP adress or selecting you'r LAN stuff.
You need an event to tell you when someone is connected and to load up the next frame together, one method i use is "Connected" (this will be join side players) = Set counter to "1", Send Single Value (under Dplay).
Under the same event tell the HOST to "Set Counter To "Message Data, Recirve Single String"
NOTE make sure you send the alue from the CONN player under the same style of recieve, example SINGLE STRING will be SINGLE STRING, to send a double value will not be recieveable by a DOUBLE STRING recieving event.
And to finish off the connection, when counter is 1 = next frame!
If for any reason this does not work i am sure you can work out a way to get both screens to load the next frame, once you are connected work out a method of sending and recieving values to each player to tell them it is ready to continue the game.
Now to the game part!
Next frame, you will need to have a Dplay extension in this frame too, copy this from the frame before or the frame that just used the Dplay so the GUID is correct to keep its connection connected. now you need the "Is Message(s) Waiting" event here in this level again for the Dplay to work. now create a basic floor, and 2 active squares both being a different colour and give them a player 1, player 2 name (this is for your use, not the Dplay events). ONLY give player one platform movement and give player 2, well nothing really as the Dplay will set its x-y posisions.
Under events set a timer to say every 0.15 of a second.
NOTE that if you set the game to every 0.1 second you will cause too much infomation to be set too fast down the internet and cause increasing lag and alot of game slowdown where it keeps waiting for infomation to load.
Set the Dplay to send the x-y-a-b-c values and to recieve the same in that 0.15 of a second. then set the player 2 square to set its posision from the recieved values, this will show you where the other player is on you'r screen. The player animation value can also be sent over with the x-y-a-c-b values but make sure you make the game recieve the same set of values also!
From here a game can be made online, you could add bullets, ability to jump on each other, enemys, blah blah and so on. The great thing about this method of Dplay is that any one player game of yours can be converted to some kind of online game with these events. Say you have an action game form the side and you want it online, you create a 2nd player that will show you the connected player and do all the infomation sending over Dplay, now you will need to add a few extra events to say when he gets hit on your screen, or to send his health packet to a value so both players can see each others health. There is alot you can do.
I hope this helps a few of you wanting to know how to get a game online without much effort. It's my first article so i hope i not rushed this and forgot something ;
Do note that there is alot more settings you can tamper with and try out, but this method works well and also note that a 56k modem will run on this but try not to use extremely high amounts of sending infomation to stop lag slowly building up. a good value is 0.15 of a second across the net.
|
|
Diab
Registered 09/07/2003
Points 103
|