gbadev.org forum archive

This is a read-only mirror of the content originally found on forum.gbadev.org (now offline), salvaged from Wayback machine copies. A new forum can be found here.

Beginners > Line of sight

#19957 - FiveEight - Wed Apr 28, 2004 11:12 pm

I'm making a tile based game with some shooting. The player shoots by holding the right button to select a target and then pressing A to fire. The target will be selected based on hostility, line of sight and distance.

What I need to know is the best way to determine if the player character (fixed to the centre of the screen) has a clear line of sight to an enemy. LOS is blocked by tiles with a collision bit and not blocked by other tiles without the bit set. Non-hostile characters also need to block LOS.

Also, which is the best sort to use for small sets (maybe ten targets)?

If this has been answered before then could someone link me to it?

Thanks.

#19958 - Miked0801 - Wed Apr 28, 2004 11:16 pm

If your collision tiles are a constant size, then just trace a vector line throuhg them all and check each point till you hit the end.

For a set of 10, I'd not use anything fancy - perhaps just an insertion or perhaps a shell sort. Not bubble sort - nothing ever needs bubble sort :)