Multiplayer Component Based Space Combat

Show off your games, demos and other (playable) creations.
User avatar
Lap
Party member
Posts: 256
Joined: Fri Apr 30, 2010 3:46 pm

Multiplayer Component Based Space Combat

Post by Lap »

I've always loved Battleships Forever.

http://www.wyrdysm.com/games.php

However, the game lacked muliplayer. I spent about eight hours today and developed a working multiplayer prototype of the game. So far I can make full physiced ships from small parts and have them fly around. The host does all the simulation.

Considering how much demand there was for a multiplayer version and how easy it was to get this far I'm really surprised no one has created a BSF multiplayer version using something after all these years.

Here's a screenshot I took today.

Image
Last edited by Lap on Fri May 21, 2010 8:12 pm, edited 1 time in total.
User avatar
bartbes
Sex machine
Posts: 4946
Joined: Fri Aug 29, 2008 10:35 am
Location: The Netherlands
Contact:

Re: Multiplayer Battleships Forever

Post by bartbes »

So, is there like.. something we can play?
User avatar
Lap
Party member
Posts: 256
Joined: Fri Apr 30, 2010 3:46 pm

Re: Multiplayer Component Based Space Combat

Post by Lap »

At the moment all you can do is fly around with your friends as I haven't actually made any working weapons. I'm focusing on the ship editor right now.

I was initially planning on just making a multiplayer port of the freeware game Battleships Forever, but he doesn't seem very keen on that idea so I'll probably just be making my own separate game. For the immediate future I won't actually release anything until I get my own sprites to use. On the positive note though, not making a straight port means I have the design freedom to do whatever I want and add different game mechanics.
User avatar
Skasi
Prole
Posts: 27
Joined: Thu Feb 12, 2009 2:25 pm

Re: Multiplayer Component Based Space Combat

Post by Skasi »

Well.. actually.. I thought of doing something like this too, but have been too afraid of all the work that has to be done for properly synchronizing physical stuff. (same for Lords of Space :p)

Wishing you a lot of fun with your project, am already eager to finally play BSF with friends. ;)
User avatar
StoneCrow
Party member
Posts: 199
Joined: Sat Apr 17, 2010 9:31 am
Location: Wales the land of leeks and leaks
Contact:

Re: Multiplayer Component Based Space Combat

Post by StoneCrow »

This is awesome,
nuff said
Dull but sincere filler.
User avatar
Elvashi
Prole
Posts: 45
Joined: Sat Jul 04, 2009 9:17 am
Location: Australia

Re: Multiplayer Component Based Space Combat

Post by Elvashi »

I'm definitely looking forward to seeing where this ends up :awesome:
Even if theres not much of a game yet, I'm sure we'd all still like to take a peek, and if nothing else we can see out the networking code holds holds up. :P
"We could make a program for doing this for you, but that is for the LÖVE IDE, planned to be released in March 2142." ~mike
Networking with UDP uLove Proposal CCG: Gangrene
User avatar
Lap
Party member
Posts: 256
Joined: Fri Apr 30, 2010 3:46 pm

Re: Multiplayer Component Based Space Combat

Post by Lap »

Networking code is all LUBE so there's not too much left untested there.

I've worked with Lua before on a very similar game to this one and it kind of makes me scared. Lua isn't the fastest code and a game like this needs to do a lot of line of sight checks for automated weapons. That combined with all the effects and physics this will likely need kind of has me hesitant to go much further. I don't want to put in tons of work just to find out that the game ends up lagging when everything gets put together.

Has anyone done any physics related benchmarks?

My hands are also kind of full and I don't know if I really want to juggle another full project solo so if anyone is interested in helping out with the code let me know. Most of the hard stuff is already done.
User avatar
Robin
The Omniscient
Posts: 6506
Joined: Fri Feb 20, 2009 4:29 pm
Location: The Netherlands
Contact:

Re: Multiplayer Component Based Space Combat

Post by Robin »

Lap wrote:Lua isn't the fastest code
Actually, Lua is blazing fast. It helps, of course if your algorithms are, say, O(n log(n)) or even O(log(n)) rather than O(n²) or O(2^n).
Help us help you: attach a .love.
User avatar
Lap
Party member
Posts: 256
Joined: Fri Apr 30, 2010 3:46 pm

Re: Multiplayer Component Based Space Combat

Post by Lap »

Well I remember doing this same process in Garry's mod and it got pretty laggy. I can blame most of it on the physics, but the line of sight checks seemed to actually cause quite a bit of lag when I benchmarked them.

I'm just going to throw out the blueprints of the code and hopefully someone can point out any problems and help me conquer some hurdles.

Pieces-
-Ships are made of pieces. Each piece is individually defined.
-Each piece will become it's own shape.

Code: Select all

-- {image, { polygon coords} }
Pieces = {}
Pieces['wond_sec'] = {love.graphics.newImage('gfx/pieces/wond_sec01.png'), {0,30,17,0 ,55,0,72,30}}
Pieces['kae_sec47'] = { love.graphics.newImage('gfx/pieces/kae_sec47.png'), {0,0,15,0,32,17,32,25}}
Pieces['old_ce60'] = { love.graphics.newImage('gfx/pieces/Old_CE60.png'), {15,0,72,21,15,42,0,33,3,21,0,9}}
Ships-
-contain one core piece on which all other pieces most somehow indirectly or directly connect to.
-are a table of pieces.
-will correspond to one body, with one shape per piece.

Code: Select all

Ship1 = {}
Ship1['Core'] = 'old_ce60'
Ship1['Pieces'] = {}
Ship1['Weapons'] = {}
-- {Parent #, X Offset, Y Offset, Flip x, Flip y, Rotation, type}
Ship1['Pieces'][1] = {0, 0, 20, true, true, 0, 'wond_sec'}
Ship1['Pieces'][2] = {0, 0, -20, false, false, 0, 'wond_sec'}
Ship1['Pieces'][3] = {1, 0, 40, false, true, 0, 'kae_sec47'}
Ship1['Pieces'][4] = {2, 0, -40, false, false, 0, 'kae_sec47'}
Serverside -

1. A physics world is created.
2. Ships are created
---a. Add a body to represent each ship
---b. Go through each piece in the ship file and add the corresponding shape to this body.
3. Send created ships to new joining players as well as a table of which pieces are destroyed.
4. Simulate physics
5. Send updated ship positions.
5. Accept client input

Clientside-

1.Create a dummy physics world.
2.Draw the ships the server sends us from simple data (i.e. {ShipType, xpos, ypos, angle}). No physics will be simulated.
3.Send client commands.

Weapon Checks- Here's the tricky part

0. If it's time to find a new target....
1. Loop through all shapes throwing out shapes that are too far away.
---a. How do we determine the distance between two shapes? There is no shape:getPos() or equivalent that I know of.
---b. If we get the center of a piece it's kind of inaccurate because the center might not be in range, but an edge might.
2. Check to see if the targeted shape is in the firing arc of the weapon
3. Loop through all remaining shapes and use shape:testLineSegment() to make sure there is nothing between the weapons and the target. If there is, try the next shape.
4. Fire

This last part could derail the whole project or at least drastically change all the guns to manual instead of auto-targetting, which makes this an entirely different game.

The only way I can think of doing this is to store the position of every single shape in the game (as in hundreds of them) in a big table that gets updated every time physics update. Each time I have to
1. Lookup the shape's body
2. Get the bodies position
3. Lookup the piece's relative offsets
4. Add that to the body postion
5. do rotation...
local finalx = (xoffset * math.cos(rotation) - yoffset * math.sin(rotation)) + centerx
local finaly = (xoffset * math.sin(rotation) + yoffset * math.cos(rotation)) + centery
to find the final position

Now if I have to do that for every single physics.update that seems awful, especially considering box2d has to have the x,y of each shape stored somewhere.
User avatar
Robin
The Omniscient
Posts: 6506
Joined: Fri Feb 20, 2009 4:29 pm
Location: The Netherlands
Contact:

Re: Multiplayer Component Based Space Combat

Post by Robin »

This seems overly complicated. I'm sure there is a much simpler way to deal with this, I just can't think of one right now.
Help us help you: attach a .love.
Post Reply

Who is online

Users browsing this forum: No registered users and 54 guests