# How do I handle this type of collision?

So I've been messing around with simple game development for a while and just found an interesting game idea here . I'm using SFML 2.1 with C++ and so far I have a tilemap in a VertexArray using a very similar way to this tutorial and have gotten it working with submarine movement but I feel that I have dug myself a hole with this. Here is what I have so far and you can see my simple tileset: . I am pretty lost in terms of how to handle collisions between the submarines (and anything else fired) and the walls. The only way I can really think of is pixel collision but I'm not really sure how I would implement that.

Sorry if this has been asked before but I have looked and can't find much that applies. Any help is greatly appreciated.

Thanks,

Karel

I just realised that the question is badly worded sorry. I was wondering how to do collision detection between the submarine and the walls of the level. Since I don't want to just do collision tests on the whole tile (as it would prevent the sub from getting close to the wall) but rather the section that has the actual wall part (just the line in the tile). I really don't know how to do this, should I switch out the tilemap for just a bunch of line objects and do the collision tests on those or is there a way to do it as it stands now?

• It really depends on how you model your collisions. How about instead of pixel collisions, you try modeling your walls as line segments and your submarine as a point? Collision detection and resolution is much more simple that way Jul 9, 2014 at 2:47

## 1 Answer

Collision doesn't need to care about tiles at all. If a tile is just a shape of lines, your "tile collision" is really just collision against those specific lines. You can also use collision against arbitrary shapes defined by mathematical functions - like curves - which are represented by tiles.

Tile collision in this case means determining which tiles the submarine is overlapping in and then doing tests against the lines in those specific tiles. For instance, if tile value 2 is the shape:

|\
| \
|  \
----


then when the submarine is colliding with any tile of value 2 use the appropriate triangle data to do the actual collision calculation with.

The general technique along with math and some interactive examples can be found at the classic article N Tutorial A - Collision Detection and Response.