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.

DarkBASIC Professional Discussion / Multiplayer problems!

Author
Message
WAKS
12
Years of Service
User Offline
Joined: 5th Oct 2013
Location: Oslo, Norway
Posted: 24th Nov 2013 17:06 Edited at: 24th Nov 2013 17:17
Hallo
My friend and I are making a 2D fighting game called Beat em up. We have an idea about implementing multiplayer in this game. That we tried to do is to make the player able to play with someone else through the Internet. I am a beginner and have no experience in multiplayer coding. Therefore I use a code from the codebase on tgc, and experimenting to modify so I could use this code on my project. so far have I been able to make a simple server, were the player could choosing between hosting a game or log in and join as a client using a IP address. But my problem is that I have no idea how I could move my sprite (and the other player could see that on his screen on the other end) and how the other player could move the other sprite (and I could see the player are moving on my screen). Sorry for bad explanation

Here is my code



Thanks for answers
Derek Darkly
14
Years of Service
User Offline
Joined: 22nd Sep 2011
Location: Whats Our Vector, Victor?
Posted: 25th Nov 2013 01:23 Edited at: 5th Dec 2013 17:16
Something like this has worked for me:



D.D.
WAKS
12
Years of Service
User Offline
Joined: 5th Oct 2013
Location: Oslo, Norway
Posted: 28th Nov 2013 20:33
Thanks for your answer
Sorry for the late reply, I have a very busy week. Your code sounds interesting, but I have one question; could you explain your code so I could learn how you do it?
Derek Darkly
14
Years of Service
User Offline
Joined: 22nd Sep 2011
Location: Whats Our Vector, Victor?
Posted: 4th Dec 2013 13:53 Edited at: 5th Dec 2013 17:16
Quote: "Sorry for the late reply, I have a very busy week. Your code sounds interesting, but I have one question; could you explain your code so I could learn how you do it?"


Sure, no problem.

DIM PlayerData(2)
This creates 2 data "containers"...
1 for your player's X position
1 for your Player's Y position

PlayerData(1)=SpritePositionX
PlayerData(2)=SpritePositionY

Inside our loop, we update the information according to our player's current position.

if MEMBLOCK EXIST(1) then DELETE MEMBLOCK 1
This clears out the old memblock so we can update.
(Our memblock will contain the aforementioned X and Y coordinates.)

MAKE MEMBLOCK FROM ARRAY 1,PlayerData(0)
This creates a Memblock (block of information) from our coordinates.

SEND NET MESSAGE MEMBLOCK 0,1
This sends the information to all the other players.
("0" specifies send to all players rather than a specific one.)




As for the receiving end:
GET NET MESSAGE
This checks for incoming messages.

if MEMBLOCK EXIST(2) then DELETE MEMBLOCK 2
Deletes old Memblock for Enemy data

if NET MESSAGE EXIST() and NET MESSAGE TYPE()=4 THEN NET MESSAGE MEMBLOCK 2
Net message type 4 is specifically for Memblocks
"NET MESSAGE MEMBLOCK 2" creates the memblock from the net message

MAKE ARRAY FROM MEMBLOCK EnemyData(0),2
Create our Enemy coordinate array from memblock data

EnemyPositionX=EnemyData(1)
EnemyPositionY=EnemyData(2)


Assign our enemy positions

D.D.
WAKS
12
Years of Service
User Offline
Joined: 5th Oct 2013
Location: Oslo, Norway
Posted: 4th Dec 2013 13:59
Thanks!
It helped a lot
Derek Darkly
14
Years of Service
User Offline
Joined: 22nd Sep 2011
Location: Whats Our Vector, Victor?
Posted: 4th Dec 2013 18:09 Edited at: 4th Dec 2013 18:11
You're welcome...

Also, I have found that sometimes sending the data every loop is too much, or not necessary.

You may want to keep track of your old X and Y positions in another variable and only send the coordinate data if the player's position has changed.

D.D.
Mobiius
Valued Member
23
Years of Service
User Offline
Joined: 27th Feb 2003
Location: The Cold North
Posted: 5th Dec 2013 19:52
Quote: "You may want to keep track of your old X and Y positions in another variable and only send the coordinate data if the player's position has changed."

Or send the data every xth of a second, and use interpolation at the client end.

Derek Darkly
14
Years of Service
User Offline
Joined: 22nd Sep 2011
Location: Whats Our Vector, Victor?
Posted: 6th Dec 2013 03:04 Edited at: 6th Dec 2013 03:06
Quote: "Or send the data every xth of a second, and use interpolation at the client end."


True, I think that's what I'm doing with my tank game...

I began with trying to look up how multiplayers send the player coordinates so quickly and came across the phrase "predictive programming"... then I realized I could just update the coordinates with a timer and have my tank roll towards the latest point even if it doesn't exactly match what's on the other players' screens. (Right now I'm just pointing the tank directly, so it looks horrible, but later I'll smooth the turning.)

I'm still figuring out how to most quickly register player hits.
So far I'm registering on the shooter side and sending "HITx" to be parsed by the other players if that makes sense.

D.D.
Mobiius
Valued Member
23
Years of Service
User Offline
Joined: 27th Feb 2003
Location: The Cold North
Posted: 6th Dec 2013 16:29
Quote: "I'm still figuring out how to most quickly register player hits."

The best way would be to send the shot data to the server, and let the server decide if it was a hit, then pass that information back to the clients. It's the best way to prevent cheating.

Login to post a reply

Server time is: 2026-07-06 10:39:44
Your offset time is: 2026-07-06 10:39:44