Bay 12 Games Forum

Please login or register.

Login with username, password and session length
Advanced search  

Author Topic: Quadrant -Life in the void- My 2d spaceship game.  (Read 5256 times)

Talvara

  • Bay Watcher
    • View Profile
Quadrant -Life in the void- My 2d spaceship game.
« on: January 27, 2014, 11:24:36 am »

So, I've gotten some 'off time' from big school projects and finally managed to get started on a game I've been wanting to work on for a while now.

Quadrant is that game, and I've been working on it for two weeks now. I'm not completely sure where I want to take the game, but in the long run I'd like to make some sort of 2d Economic spaceship playground, X3 Terran conflict is a big source of inspiration for this. but such grandness is still far faaaar off in the distance.

For now I'm working on getting spaceships to fly around... shoot stuff, and eventually die in fictional agonising space explosions! something I'm also keen on having in my game is to allow players to design their own ships, using 'modular' components. Preparing this and designing an editor for spacecraft is something I'm currently working on.

I'm using Unity 4.3 to work on this, the Box2d Physics implementation is missing a few... vital functions (like an easy way to get/set the centre of mass on a physics body). but I'm really digging the performance its giving me, I've tried using Farseer for unity, which has some more fancy features but sadly just doesn't compete with unity's native 2d physics implementation when it comes to performance =(...

So enough talk, Lets see some stuff.
As I mentioned I want spaceship to be build out of modular components, These components are essentially sprites being stored in a texture atlas:
Spoiler (click to show/hide)

I also made a ship saver and loader. which takes a ship assembled in the unity editor and saves/loads it to an XML. the parts are saved by name... so when the texture atlas is changed in the future and the positioning of the various components changes the system can still find the correct part based on its name. not only does this keep my hands out of my hair when I want to add some new graphics it should also open up the door to some modability!
Spoiler (click to show/hide)

while most of the components are only aesthetic and used to define the shape of the spacecraft, other components like the guns and engines do their respective job when input is provided, (IE... guns shoot and engines enact force onto the physics body they're attached to)
Spoiler (click to show/hide)
so yeah... Engine placement matters when it comes to ship handling.

Feel free to have a bit of a test ride. Link to Webplayer (edit: link no longer works.)
WSAD for steering, Space for shooting. There's not a whole lot to do, damage and user friendly handling is kinda still on the wishlist ;)
(ps, if you're interested in a game developer students portfolio feel free to go to the root of that link ;) (mind you, its a bit of a work in progress))

Heres what I've got:
- Loading of art assets through texture atlas.
- Engines that give force depending on their positioning.
- shooters that spawn bullets.
- a projectile manager to handles bullet collision (its a raycast between old and new positions) and renders bullets as particles.
- a way to save designs to XML.
- a way to load designs from XML.
- automatic assignment of correct engines to correct inputs (that's what the breaking up of engine force vectors was for)
- every art asset has its own collision object that is saved to an xml.

Here's what I'm currently working on:
- I've imported the excellent Clipper library made by Angus Johnson.
- I'm trying to preform a boolean union operation of all the little collision objects to merge them into a single object.
- I ran into problems with the clipper not working as intended when the new polygon has holes.
- reworking the way I store collision shapes to take holes into account...
- all of this is being done to make an ingame editor, so I don't have to design ships in the unity editor any more!

Let me know what you guys think. I don't know how often I'll be able to update this or how often I'll be able to work in my game in the future (dark clouds of educational responsibilities are on the horizon)
« Last Edit: May 27, 2016, 05:40:40 pm by Talvara »
Logged

Talvara

  • Bay Watcher
    • View Profile
Re: Quadrant -Life in the void- My 2d spaceship game.
« Reply #1 on: January 27, 2014, 11:25:19 am »

- reserved for future nefarious needs -
Logged

Anvilfolk

  • Bay Watcher
  • Love! <3
    • View Profile
    • Portuguese blacksmithing forum!
Re: Quadrant -Life in the void- My 2d spaceship game.
« Reply #2 on: January 27, 2014, 02:59:12 pm »

This is pretty cool. My dream game is also about spaceships :D

Are you planning on open-sourcing this at some point and have multiple contributors? I've been toying with the idea of procedurally generated spaceships, and have been looking into Unity :)

Nasikabatrachus

  • Bay Watcher
  • Who watchdwarfs the watchdwarves?
    • View Profile
Re: Quadrant -Life in the void- My 2d spaceship game.
« Reply #3 on: January 27, 2014, 09:13:36 pm »

This looks pretty neat. I'm impressed that this much has been put together in just two weeks (I'm a non-coder, so take that for whatever it's worth).

As someone whose childhood was shaped by the Escape Velocity games, I would recommend that you look towards those games for their expansive environments and free-form play, but whatever you do with this I look forward to seeing how it turns out.
Logged
"I want to have goblins about me, for I am courageous. The courage which scareth away ghosts, createth for itself goblins--it wanteth to laugh." Thus Spake Zarathustra, chapter 7, Friedrich Nietzsche

sackhead

  • Bay Watcher
    • View Profile
Re: Quadrant -Life in the void- My 2d spaceship game.
« Reply #4 on: January 27, 2014, 11:50:22 pm »

I love the Physics and the turning i only wish there was no friction

Logged

Talvara

  • Bay Watcher
    • View Profile
Re: Quadrant -Life in the void- My 2d spaceship game.
« Reply #5 on: January 28, 2014, 06:07:07 am »

This is pretty cool. My dream game is also about spaceships :D

Are you planning on open-sourcing this at some point and have multiple contributors? I've been toying with the idea of procedurally generated spaceships, and have been looking into Unity :)

I can't say the idea of making this open-source is something I'm comfortable with right now. I am however going to try and open up as much as I can to modding.
 
Unity is pretty cool and I had a good time picking it up... I'd suggest diving straight into C# coding and avoiding unity(java)script. I felt like C# forced me to be more mindful about what I was doing. not being as flexible as unityscript when it comes to how you write stuff. If you see stuff I made that you'd like to know more about I'm not opposed to sharing knowledge and possibly code snippets :).

...

As someone whose childhood was shaped by the Escape Velocity games, I would recommend that you look towards those games for their expansive environments and free-form play, but whatever you do with this I look forward to seeing how it turns out.

I googled escape velocity and found that I had already been to the wiki page for it, the screen shots I've glanced look interesting too. Guess I'll try to find a lets play for it to listen/watch while I do some work. thank you for the suggestion.

I love the Physics and the turning i only wish there was no friction

Having no friction is certainly a (more realistic) option, I'm having trouble wrapping my head around the implications for a 'topspeed' with no friction though... I recall hearing that realistic space battles would be boring as hell since they would boil down to flying towards each other at ungodly speeds... tossing junk out the window and hoping said junk collides with whatever you're trying to mess up.

anyway I've not completely thrown the thought of no friction out of the airlock, but I'm worried that no friction will have negative effects on the gameplay, (and make people expect more realism to be present in other areas of the game ;) )

-------------------------------------

So yesterday evening stuff went smoother than I had anticipated and I ended up with a working 2d polygon boolean operation. (its a mouthful) and what that means... is that I can take separate polygonal shapes and combine them into one.
Spoiler (click to show/hide)

Up until now I've been making the various ship collider shapes by hand, which would have been an option for the editor as well... but I didn't like placing the responsibility for a good collider shape in the hands of the player. since its some what 'cheat' sensitive and kind of tedious to do.

if you notice those red dots they're holes in the collidermesh! In the end I'm really thankful that they were there. my first try at making the Union operation worked well enough. but it wouldn't handle holes in the resulting mesh. it would just error out. if I hadn't accidentally added those holes to my little test ship I wouldn't have thought to account for their possible existence and the entire thing would have broken down at a later date (a date where I would probably have forgotten what the hell I was doing)

While having holes in the collision mesh isn't interesting for hit detection and physics use (I cant even add them to the collision mesh anyway). they do become important when I want to calculate the "area" of the ship for mass calculation or if I'd at some point want to 'slice' the ships into pieces to simulate damage or destruction. The holes will also prove to be important for when I want to add interiors to the spacecraft. (I.E. where stuff can be placed and where stuff can't be placed)


The natural next step would be to write some code that cleans up the combined collision mesh... that means detecting points that are very close together or points that don't really influence the shape at all. (less points = faster calculation).
Spoiler (click to show/hide)
I'll postpone doing the clean up until later I think. even though the new collision shape is heavier on the calculation side of things, they still technically work just fine.

I think I'll work on the in game ship editor next. I really need to get this in enough shape fast so I can toss it onto my portfolio soon. I need to go internship hunting in the near future.
Logged

Biag

  • Bay Watcher
  • Huzzah!
    • View Profile
Re: Quadrant -Life in the void- My 2d spaceship game.
« Reply #6 on: January 28, 2014, 05:50:10 pm »

I would be very interested in a description of how you went about that union function!
Logged

Talvara

  • Bay Watcher
    • View Profile
Re: Quadrant -Life in the void- My 2d spaceship game.
« Reply #7 on: January 28, 2014, 07:06:12 pm »

I would be very interested in a description of how you went about that union function!

okay, the first thing you need to know is that all the heavy lifting is done with that Clipper Library that I mentioned in the first post. I downloaded that and placed the C# file in my unity project.

With that in your unity project you should now have access to the "ClipperLib" namespace and should be able to make a "Clipper myClipper = new Clipper()" in your scripts (be sure to add "using ClipperLib" at the top of your script, otherwise you'll have to write Clipperlib.Clipper" every time you want to use something from your new shiny Clipper powerhouse).

now the way clipper works is that you feed it "polygons" which is what clipper calls a list of IntPoints (I don't know why it wants IntPoints specifically... but I'm not one to judge) since you'll be doing alot of converting between Unities nice and elegant Vector2's and ClipperLibs IntPoints its probably a good idea to make some helper functions that convert between the two.

mine look like:
Spoiler (click to show/hide)

so you feed your little Clipper friend a number of Subject polygons and a number of Clip polygons. this is where my knowledge is beginning to fall short since I can't really explain how subjects are different from clips... but I'll just direct you to the documentation ;)

since I'm not to sure on the exact workings, I chose to just do 1 subject and 1 clip at a time, Running a loop through the polygon shapes I collected from the various GetComponent<PolygonCollider2d>().Points.

something that is important to note is that the... 'winding direction' of your polygons is important. the winding direction can be clockwise(polygons) or counterclockwise(holes). since its probably a good idea to have a way of telling a polygons winding direction, I googled and was rewarded (protip, if you want to reverse the winding direction of a polygon, simply reverse your list of Vector2's)

so thats about the gist of it... Calling Clipper.Execute with the Union cliptype will give you a list of polygons which you can convert back into a nice safe array of Vector2 points... and feed to your polygoncolliders.

I hope this satisfies your curiosity :).
Logged

Anvilfolk

  • Bay Watcher
  • Love! <3
    • View Profile
    • Portuguese blacksmithing forum!
Re: Quadrant -Life in the void- My 2d spaceship game.
« Reply #8 on: January 29, 2014, 10:57:01 am »

This is pretty cool. My dream game is also about spaceships :D

Are you planning on open-sourcing this at some point and have multiple contributors? I've been toying with the idea of procedurally generated spaceships, and have been looking into Unity :)

I can't say the idea of making this open-source is something I'm comfortable with right now. I am however going to try and open up as much as I can to modding.

Too bad :(

Talvara

  • Bay Watcher
    • View Profile
Re: Quadrant -Life in the void- My 2d spaceship game.
« Reply #9 on: January 30, 2014, 10:05:06 am »

So far the past days I've been laying down the groundwork for the ship interiors, The first thing I did was try and find a way to convert those lovely collision meshes into a triangle mesh that can be used for rendering. After quite a bit of browsing the web I stumbled onto a c# port of LibTess which seems to do exactly what I needed it to do, from what I can tell its faster that a solution that can be found on the Unity wiki, and handles Holes in meshes as well! as an added bonus it accepts the same sort of data (although in its own format...)  that the Clipper library spits out.

I wasn't able to find any documentation on how the damned LibTess thing worked though, so I had to dig around in the source files to decipher its arcane mysteries.
Spoiler (click to show/hide)
So I managed to get mesh creation to work. after banging my head against the desk for a while I should add.
Now being able to create meshes from my polygonal data I wanted to set out and make some actual rooms, so I set up a little test interior to see if I can render rooms, and if I can use the Clipper library to cut out some walls.
Spoiler (click to show/hide)
and this is where I'm sort of stuck for now... I'm able to cut out a few rooms from the hull mesh... but not all of the rooms seem to want to play nice. It might have something to do with the centre line? I just don't know.

The reason why I want to have a hull with the rooms cut out is that later on I want to split that hole riddled hull into chunks and use those chunks to track damage data and potentially vent oxygen.

I really want damage to be more than a numerical value between alive and dead. Similar to Wayward Terran Frontier (go check it out if you haven't yet, its awesome) a ships functioning should come down to its internal components being in working order or not.

I'm also hoping to avoid the square grid nature of interior design by designing rooms with polygonal shapes.

So, that's where I'm at. its currently not working as intended and I haven't even begun to think about saving interior space to xml files.
there's just so much to do before this starts coming together... but I really need those interiors to be there before I can start thinking about damage and (unrealistic) space fireball explosions

Update:
So I found what was wrong... I wasn't transforming the polygon data to the parent transform... which meant that the mirrored rooms (those that had -1 in their X scale) were claiming that they weren't mirrored at all. Likely closing the hole that their non mirror cousin was making.

Spoiler (click to show/hide)
« Last Edit: January 30, 2014, 11:06:25 am by Talvara »
Logged

Talvara

  • Bay Watcher
    • View Profile
Re: Quadrant -Life in the void- My 2d spaceship game.
« Reply #10 on: May 27, 2016, 11:02:48 am »

So wow... its been over two years!

I've stopped working on it for a while as my studies urged me to focus on other things, Then I've worked on it again to make a 2dspaceship editor for my graduation project. put the project down again as I did some part-time work and now recently am trying to pick it up again.

I'll share a link to an executable so if you're interested you can have a poke around. But first a few screenshots so you know what you'll be downloading.

A simple Menu.
Spoiler (click to show/hide)

The editor for the ship designer.
Spoiler (click to show/hide)

The sandbox test environment.
(you can fly around your creations here)
Spoiler (click to show/hide)

Usability of the editor is a continued concern. I need to find a elegant way to explain some of the more hidden workings. For instance in the data folder you'll find a resources folder where you'll find a hull art folder... in which you'll find sub folders filled with artwork for spaceship components. Users can add their own subfolders and own artwork and use the "Hull Shape editor" to make collision shapes and incorporate their artwork into the editor.

Link to .Rar archive containing editor.


---
Currently I'm working on improving the way damage is done to the ship, I've decided to go for a gridbased approach and at the moment I can transform projectiles hitting the polygonal collisionshape onto a 2dtexture.

(warning large Gif)
Spoiler (click to show/hide)
Logged

MoonyTheHuman

  • Bay Watcher
  • I think the DEC VAX hates me.
    • View Profile
    • hellomouse
Re: Quadrant -Life in the void- My 2d spaceship game.
« Reply #11 on: May 27, 2016, 05:13:46 pm »

Your inching close to The toady one, Spaceship edition  ;)

ShadowHammer

  • Bay Watcher
  • God is love.
    • View Profile
Re: Quadrant -Life in the void- My 2d spaceship game.
« Reply #12 on: May 28, 2016, 12:51:33 am »

This looks awesome, yo! Posting to watch!
Logged

xaritscin

  • Bay Watcher
    • View Profile
Re: Quadrant -Life in the void- My 2d spaceship game.
« Reply #13 on: July 19, 2016, 06:51:48 pm »

that last post. omg!.....

Logged