Huge World / 2d Tile Engine

Hi, I am really enjoying working with Box2d! So, I've always wanted to do this epic action game that takes place on a planet in 2d universe. I want you to be able to fly into the planet from outer space and all the way around and through the center of the planet. Then you discover the planet is actually the remains of a huge ancient space station with lots of rooms and stuff ala metroid or zelda.

The level editor is progressing very nicely and that's what I want to share with you guys today. I have combined the concept of a tile engine with edge loops if that makes sense. I only made a few mods to box2d code (mostly to remove the concept of edge loop chains). In this engine the edge data for each tile is compressed into a single byte (instead of 2 vectors). So an entire 1000x1000 world fits in a meg of memory. During gameplay it seamlessly only keeps physics loaded for the 3x3 grid of patches surrounding the player. Next I will be adding texturing and another Byte of data per tile to index which texture to use.

So, try it out! It takes a little bit of time to get used to because the winding order you draw in is crucial. Left click to draw. Right click to box fill. Double right click to erase. Middle click to move. Mouse wheel to zoom out. There are also some hidden controls in the edit mode: m = move player to cursor, z = flood delete, x = flood fill

Gameplay isn't really implemented yet except for basic ship controls. The particle system is fast and functional but not really used yet. The engine also supports subframe interpolation for physics and particles to make everything feel super smooth.

Here's a link to where you can download the executable.
http://www.3d2k.com/2dGame.exe

If you receive a missing DLL error, try updating DirectX at: http://msdn.microsoft.com/en-us/directx/aa937788.aspx

Plus a screenshot of the editor and a quick mockup of what I have planned for the planet so far.

Image
Image
Nice. I was just stopping in to search for optimizations for games with large tile-based maps, so your post is extremely timely. So essentially you are constantly pushing bodies in and out of the Box2D world that are near the dynamic bodies in your game. My thought was to add a callback function into Box2D that would take a body, and generate a list of other bodies that could possibly collide with it.
Are you dynamically allocating the bodies and shapes and actually adding and removing them to the Box2D world, or do you have a static array of 9 bodies that you modify?
2dGame.exe - Unable To Locate Component wrote:This application has failed to start because d3dx9_39.dll was not found. Re-installing the application may fix this problem.

I know this is probably my fault, but still, could you provide a link to where I get the latest directx from (I'm lazy).

But the idea looks awesome.
Dan: I am creating and destroying bodys on the fly. Each patch (20x20 grid of tiles) is one body with shapes equal to the amount of edges used in that patch. Dynamic bodys are not really handled right now but they will be streamed in the same way. If a dynamic body or static body's AABB gets out of simulation window it will just be destroyed. It works the same as how you would stream hightfield zones in a 3d world. I am working on cleaning up the code so I can share it soon because this seems like it could be used in a wide variety of applications and I know people have been asking for this sort of thing.

Boris: http://msdn.microsoft.com/en-us/directx/aa937788.aspx Did you ever read the comic book Boris the Bear? That comic kicks ass.
I get the same error as BorisTheBrave. 🙁 EDIT: Oh, thanks for the link.

I'm secretly also working on a level editor for edge loops, but with a focus on sidescrollers/platformers, and no tile support aside from a snap-vertices-to-grid option. So, its sufficiently different, but I'm very curious to see how you did things.
I think this tile engine method could work really well for a traditional platformer. The only real difference in my case is the camera rotates depending on where you are on the planet and you are in a ship instead of on foot. I can see how you have more flexibility with an edge loop engine but I think with a 1000x1000 grid of these tiles there is probably sufficient granularity for most applications.

I'm not sure how I'm going to integrate it with the current edge loop code since this just uses edges and not really edge loops. I suppose I could just make it use edge loops but that seems like sort of a waste to keep have the extra pointers and stuff when they are just single edges.
Is there a way to force it to draw straight lines?

EDIT: The flood fill tool seems very useful, but the flood delete tool, for whatever reason, seems to always destroy my lines. If I carve a little circle out of a big solid/black area and try to fill it in blue, the entire square becomes blue. 🙁
No straight line tool yet, I will add that, good suggestion. Flood erase is a bit crappy right now, I know exactly what you are saying. I will fix that up too.

Edit: I just put up a new version that has a line tool (hold shift and left click to make lines) . Keep in mind the lines are going to snap to the nearest quarter tile, this is because of the compression. So the lines may not come out straight depending on how you draw them. I also improved the flood erase function. Also I changed the control to delete tiles, instead of double right clicking just hold control while right clicking.
Ok, played it now, that is cool. Is there any reason you went with quantized line segments for each tile, or just to get the aesthetics right?

I haven't read Boris The Bear, but I'll be sure to look out for it now.
Can you give a direct link to directx please?

Original thread: https://box2d.org/forum/viewtopic.php?t=2451