1
votes

I've been planning an indie game project for a while now. I'll summarise it for you so I can get right to the question.

It's done entirely using the latest version of XNA through Visual Studio. Hoping to put it on 360 and PC, but am only really looking for a PC-oriented solution at this stage.

It's a 2D side-scrolling shooter (think Metroidvania-style, or even Terraria). It will eventually include an in-game map editor with maps being tile-based (16x16). There will be upwards and downwards scrolling. I'm hoping to implement tile layers in the dev map editor (reason for a dev map editor is it's going to be heavily leaning towards a content-focus, so there will be a lot of maps).

Physical tiles will be very simple with only two major types. Block tiles, which are just a solid tile, and angled tiles, which are tiles with an incline that characters can walk on. I'm strongly considering abandoning angled tiles entirely, but not sure yet.

The character/NPC movement will be simple. Moving side-to-side, jumping, falling, flying (with appropriate items/situations), teleporting. All very static, no dynamic physics necessary. Only basic gravity. When a character steps off the edge of a tile, it falls. When it jumps and a tile is above it, it stops short and falls back down. When it reaches a protruding tile/wall, it can't move further unless it jumps over or flies. All the basic stuff.

Projectiles can be affected by gravity as well, and some situations may arise where a projectile may be manipulated mid-flight, but nothing requiring heavy physics. Some projectiles will move characters as well (think a simple "pushing" mechanic).

So here's the question: I'm at the stage where I'm starting to work on movement and collision-detection but I just can't set myself on a way to go about them. I need ways to determine when character, tiles, and projectiles collide. Given what I've said about the style I'm going for and the tile-based system I'm using, can I get some recommendations+links to some tried and true collision detection methods others have used in similar situations? What I need more than anything else is inspiration.

And just a quick note, I have several years of experience as a programmer, so I'm not a total newbie :)

2
You might get better answer at gamedev.stackexchange.com/?as=1 - Mesop
Thanks for that link, asked there as well now. - Djentleman

2 Answers

2
votes

I was working on a GIS project at some point, I had a similar problem that I resolved with QuadTrees, have a look at this link for a great explanation and example.

0
votes

If it's a tile based map as you say, then tiles are stored in a 2d array. As such you can quickly access a tile by it's x,y coordinate in the map array.

What i recommend over a quad-tree is to simply only check the tiles immediately near the entity.

For example, you have a player entity that is moving right (+x direction) and not moving up or down. The number of tiles you can collide with will only be one of a few tiles. Specifically the tiles immediately to your right. Perhaps more to your right if you're moving fast enough.

The above solution of only checking neighboring tiles is a very common approach to this problem and can be adapted for many use-cases. This is also faster and simpler than quad-tree lookup mentioned above.