DIV ARENA FORUMS

Network multiplayer

MikeDX - 23-3-2016 at 04:44 AM

As promised, DIV now has a working multiplayer.





Code:
program redwar; global struct j[2] x,y,graph; size,angle; shot; end yo,myfont; begin load_fpg("steroid/steroid.fpg"); myfont=load_fnt("red.fnt"); set_mode(m640x480); set_fps(35,4); net.device=0; // TCP/IP net.num_players=2; net.max_players=2; yo=net_join_game("MyGame",&j,sizeof(j)); if (yo<0) exit("Error...",yo); end player(yo); enemy(1-yo); end process player(i) begin x=640*i; angle=i*pi; y=240; graph=1; write(myfont,0,0,0,"Game ID:"); write_int(myfont,100,0,0,&net.com); write_int(myfont,0,20,0,&net.server); write_int(myfont,0,40,0,&yo); loop if (key(_right)) angle-=15000; end if (key(_left)) angle+=15000; end if (key(_up)) advance(8); end if (key(_space)) shot(x,y,angle); j[i].shot=1; else j[i].shot=0; end j[i].x=x; j[i].y=y; j[i].angle=angle; j[i].size=size; j[i].graph=graph; frame; end end process shot(x,y,angle) begin graph=2; advance(24); repeat advance(16); frame; until (out_region(id,0)); end process enemy(i) begin loop x=j[i].x; y=j[i].y; graph=j[i].graph; size=j[i].size; angle=j[i].angle; if (j[i].shot) shot(x,y,angle); j[i].shot=0; end frame; end end


As you can see the code is very simple. We keep a struct with the shared information, and update it with our player positions, then each frame it is automatically updated and the opposing player (enemy) is drawn on screen at the correct positions, and even shoots bullets when required.


I'll try to do a better example this week, but look out for network support in a future beta and nightly build.


dom cook - 23-3-2016 at 08:04 AM

Impressive.

Is it possible to run the program and get the same result as shown in the screenshot as is? (i.e 2 game windows)
Will it run over 2 computers?
Sorry, I have no idea about networking.

MikeDX - 23-3-2016 at 10:42 AM

Quote: Originally posted by dom cook  
Impressive.

Is it possible to run the program and get the same result as shown in the screenshot as is? (i.e 2 game windows)
Will it run over 2 computers?
Sorry, I have no idea about networking.


Yes, here is a link to a youtube video where you can see it in action.

https://www.youtube.com/watch?v=B4Tg89K3DzA

Also yes it will run on two computers. At sone point it will hopefully enable 100s of simultaneous players.

RKSoft - 23-3-2016 at 11:32 AM

looks nice :)

humildadever - 23-3-2016 at 12:29 PM

Good news. Now i m very impressive

dom cook - 23-3-2016 at 06:54 PM

Quote: Originally posted by MikeDX  


Yes, here is a link to a youtube video where you can see it in action.

https://www.youtube.com/watch?v=B4Tg89K3DzA

Also yes it will run on two computers. At sone point it will hopefully enable 100s of simultaneous players.


Hi Mike,
If you've got a minute or two, do you think you could give me a pointer or two regarding how to set this up? I've tried it on a single computer and I just get a single window. I really don't have a clue.
Thanks.

MikeDX - 23-3-2016 at 07:06 PM

The demo you see on youtube / screenshot is only in a development build with specific compile flags - and those changes havent made it into the most recently nightly build yet anyway so you're a bit out of luck!

However, once it *is* in the build, you just open two instances of DIV, and run the program twice. The first game runs the server, and the second runs the client. This is going to change though as div-arena will become the game server - and all games will be clients.


Hope that makes sense!

dom cook - 24-3-2016 at 06:26 AM

Quote: Originally posted by MikeDX  
The demo you see on youtube / screenshot is only in a development build with specific compile flags - and those changes havent made it into the most recently nightly build yet anyway so you're a bit out of luck!

However, once it *is* in the build, you just open two instances of DIV, and run the program twice. The first game runs the server, and the second runs the client. This is going to change though as div-arena will become the game server - and all games will be clients.


Hope that makes sense!


It's starting to thanks. Looking forward to it.