Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Newcomers DBPro Corner / 2d multiplaying

Author
Message
MdaP
18
Years of Service
User Offline
Joined: 5th Nov 2006
Location:
Posted: 21st Feb 2007 00:01
Hi everyone

I am have this 2d game, and i want to implement a multiplayer function in it. I have been looking on various plugins, and the one i have worked alot with is the Tempest plugin by Benjamin (very clever guy in my opinion).

But the problem with all these plugins, is that they are designed specifically for a 3d environment. Now how the h*** can I change the very crucial functions in the plugin to suit my 2d environment?

The functions that are causing a problem is HandleControls(), HandleMovement() and HandleNetwork().

Thanks in advance.

By the way, i am making the game for 2 players at the moment (might go up to 4), and there is two seperate programs; a host and a client.
MdaP
18
Years of Service
User Offline
Joined: 5th Nov 2006
Location:
Posted: 21st Feb 2007 16:27
Here is the code that is in the tempest plugin (i have only included the functions)



But as you can see, it creates objects, moves the object etc. but i want it to communicate with an image instead.
Hammaman
20
Years of Service
User Offline
Joined: 11th Feb 2004
Location:
Posted: 22nd Feb 2007 13:42 Edited at: 23rd Feb 2007 10:52
Firstly, I'm just starting to use the Tempest plugin, but have read quite a bit on how multiplayer communication works and so I think I can help you by explaining how the code you have posted works.

Taking the HandleMovement function, I'm guessing that the game creates one 3D objects for each player. These are numbered 1, 2, etc. The object number for the local player (on the PC that you are running the code on) is called OURID.

So to convert to 2D sprites, you will need to replace the object numbers with sprite numbers (which may be simple or not, depending on how you have written your game). So if the sprites for the players are numbered 1,2,etc, then the HandleMovement function will need to look like:



I'm not at home to refer to the DBPro help files, but I'm fairly sure that there are sprite exist and move sprite functions in DBPro (which I assume you are using). I'll check and edit this post later if I'm wrong.

[EDIT]I've now checked and whilst there are move sprite commands, they don't work in the way I have assumed above. Please see my subsequent post below[\EDIT]

I also think that you will need to address the fundamental differences between controlling 2D and 3D objects. Many 2D objects are controlled by specifying the new (x,y) co-ordinates (and so you have the concept of moving left, right, up and down) -whereas 3D objects are mainly controlled by pointing them in a specific direction and then moving back and forward (i.e. left and right change the direction and up and down move back and forward).

So to make the rest of the code work, you need to decide what information needs to be passed back and forth around the network. On a simple level, this could be the (x,y) position of each player. For the 3D code above, the information is the (x,z) position and angle of rotation.

The x position is added to the network message using the TPutFloat command (if you are not aware of what a Float is, please refer to TDK's tutorial on data types) and so you need to replace the reference to "object position x(OURID)".

Similarly, the TGetFloat receives the information sent and stores in it variables called x#,z#, etc and then positions the object to that location using the "position object from, x#, 5, z#" and "yrotate object from, yA#" commands - these need to be replaced by code to position your sprites in 2D.

Finally, in 2D, you don't need to worry about the 3D camera, and so the Handle_camera function is not required.

I hope this points you in the right direction - if not, please come back and I'll try to help further.
MdaP
18
Years of Service
User Offline
Joined: 5th Nov 2006
Location:
Posted: 22nd Feb 2007 14:06
thank you very much! I have to be at a meeting now, but I will try this as soon as possible.

But I am also not quite sure that I am able to replace OBJECT with SPRITE, but I'll give it a try.

Thanks alot Hammaman!
Hammaman
20
Years of Service
User Offline
Joined: 11th Feb 2004
Location:
Posted: 23rd Feb 2007 10:56
Further to my post above, I've noticed that the move sprite command does not work how I had assumed. I've therefore taken the Tempest Example 1 code and amended it completely to work with 2D sprites.

I've tested this on one PC at home, but have not been able to confirm that it works over a network yet. So please let me know if you experience problems so that I can have a look.



You will see that I've added a new function to create some sprites without requiring additional media (i.e. images) - obviously, feel free to replace this with the usual "load image" commands to use your own sprite images.

Good luck!
MdaP
18
Years of Service
User Offline
Joined: 5th Nov 2006
Location:
Posted: 24th Feb 2007 14:19
thanks alot, hamma!

but I have one last question that you might be able to guide me with too. I have the following keys already implemented in the code:



How am I able to implement the HandleControls() function into my update_positions(this_player) function?

Thanks for everything man. You have been the only one that could guide me through this.
Hammaman
20
Years of Service
User Offline
Joined: 11th Feb 2004
Location:
Posted: 26th Feb 2007 14:02
MdaP,

Happy to help.

Regarding your question, the HandleControls() function and your update_positions() functions work in a very similar way (to update the (local) player's position based on user input) - presumably you are calling the function as update_positions(OURID). Therefore, you can replace the HandleControls function with yours.

I'm not sure whether you've also amended the HandleNetwork function to cope with the way you are storing the positions. If not, you appear to be storing the players position as x=bomberman_positions(player,1) and y=bomberman_positions(player,2) - so all you need to pass these two values in the HandleNetwork function. So I think you will need to replace:

playerdata(OURID).xpos with bomberman_positions(OURID,1), and
playerdata(OURID).ypos with bomberman_positions(OURID,2)

or something similar in the TPutFloat and TGetFloat sections of the code.

Hope this enables you to get your code to work - good luck!
MdaP
18
Years of Service
User Offline
Joined: 5th Nov 2006
Location:
Posted: 27th Feb 2007 16:49
I have looked at your last post, and the function update_positions(this_player) doesn't work if I call it update_positions(OURID)

but when replacing playerdata(OURID).xpos with bomberman_positions(OURID,1), and playerdata(OURID).ypos with bomberman_positions(OURID,2) inside the HandleNetwork() function, I come to the conclusion that it almost works.

The only problem now, is that when I first host a game, and then run a seperate .exe file as the client, the client-player interferes with the host-player.

Do you have an instant messenger program, maybe you could have a look at my code - otherwise, thank you alot for at least pointing me in the right direction.
MdaP
18
Years of Service
User Offline
Joined: 5th Nov 2006
Location:
Posted: 27th Feb 2007 19:10
one last question though, i got the players to move and so on when connected to the host!!! I have changed the program, so I have both the host and the client in one single executable program.

This is very good, but the only problem I've got now, is actually sending the information of the map to the client. Because I have chosen to make it a randomized map whenever the program is open.

Here is the code for my grid:





So my question is how the h*** do we pass the information through the HandleNetwork() function??
MdaP
18
Years of Service
User Offline
Joined: 5th Nov 2006
Location:
Posted: 28th Feb 2007 13:27
one last question though, i got the players to move and so on when connected to the host!!! I have changed the program, so I have both the host and the client in one single executable program.

This is very good, but the only problem I've got now, is actually sending the information of the grid to the client. Because I have chosen to make it a randomized map whenever the program is open, and when hosting a game, it creates a grid, and when joining the game, it creates a different grid.

Here is the code for my grid:





So my question is how the h*** do we pass the information through the HandleNetwork() function, so when joining a hosted game we join the grid that the host has created??

Thanks in advance, lad.
MdaP
18
Years of Service
User Offline
Joined: 5th Nov 2006
Location:
Posted: 28th Feb 2007 16:29 Edited at: 28th Feb 2007 16:31
sorry for posting twice!! I pushed on edit post.. honestly

look on the post right above this one.
MdaP
18
Years of Service
User Offline
Joined: 5th Nov 2006
Location:
Posted: 1st Mar 2007 20:25
okay, i have now made the grid into a non-random one.



but still when i bomb a block, the other player cant see it on his screen.

I am still pondering over this, and I hope you can sort me out.

Thanks.
Hammaman
20
Years of Service
User Offline
Joined: 11th Feb 2004
Location:
Posted: 2nd Mar 2007 19:39
Sorry for not replying sooner - I've been completely snowed under at work.

The short answer is that you need to send the grid information from the host to the client before you start the game. This will involve using the TPutFloat and TGetFloat commands in a loop to pass the information.

The main issue is going to be how to ensure that the grid data has been received before the game starts (i.e. getting the timing correct). I'll have a go at adapting my example to send some info across and will post the results later.
MdaP
18
Years of Service
User Offline
Joined: 5th Nov 2006
Location:
Posted: 3rd Mar 2007 13:08
thanks mate, and dont worry about it I give it a go anyways...
Hammaman
20
Years of Service
User Offline
Joined: 11th Feb 2004
Location:
Posted: 5th Mar 2007 10:48
Hi, had a quick look at this over the weekend, but wasn't able to get anything to work.

Thinking about other multiplayer games, there's generally a "holding area" where you wait while others join the game, then the game starting data is send to all players, then the game play begins and game updates are passed around so that all the games are in sync.

I tried to implement the "holding area" at the weekend, but each time the client was unable to join the hosted game. I suspect that the multiplayer plugin may require a constant stream of messages (i.e. info sent to TPutFloat, and TSendAll) to keep the connection open and working - I seem to vaguely recall something about this in the documentation.

As a result, I suggest that you code your game so that all users start with the same grid at the beginning of the game - and add in this functionality once the other issues have been resolved.

Turning to the game updates, in my mind, I see an additional variable being passed between players: a flag to show whether it is a player update, or a grid update. This would be attached to the front of each message (i.e. block of code with TPutFloat or TGetFloat) to enable the passed variables to be interpreted correctly.

You then "simply" pass the grid updates in a similar way to the player co-ordinates. However, the current code ignores any missed messages in player co-ordinates - and this is not a problem as the player co-ordinates are updated multiple times a second. But in the case of a grid update, we need this to definitely be received and so need to add in a reliability flag into the TSendAll command (see the documenation on how to do this). I know this does slow things down a bit, and I'm not sure whether this just affects the data transfer, or the speed the game runs.

I hope this gives you enough information to make some progress with your game. Good luck!
Hammaman
20
Years of Service
User Offline
Joined: 11th Feb 2004
Location:
Posted: 8th Mar 2007 13:38
A quick update to my earlier post.

I've been playing around trying to make my "holding area" work. I think I was missing a TSync call, which will keep Tempest up and running and checking for messages. I will try to test this further (time permitting) before posting the code here.

Also, I thought it useful to put the link to the main Tempest thread here:

http://forum.thegamecreators.com/?m=forum_view&t=73665&b=5

@MdaP - have you got your game working yet?
MdaP
18
Years of Service
User Offline
Joined: 5th Nov 2006
Location:
Posted: 12th Mar 2007 21:17
thanks alot, no I did not get it fully working, but it was an assignment, so I am just waiting to get it back so my tutor can tell me how it's done properly, or how is the best way of making a multiplayer game.

Thanks again many times

Login to post a reply

Server time is: 2024-11-25 21:48:11
Your offset time is: 2024-11-25 21:48:11