PDA

View Full Version : Tile based game and FOW


Playaction
05-05-2009, 12:12 AM
I'm working on a small tile based game. My first game project, which actually seems to become playable some day.
On my tile based map there are a number of good guys and a number of bad guys and a number of walls and obstackles. The opponent AI is coming together nicely, but i have major trouble with creating some kind of FOW effect.

I've tried using a line of sight function, which checks 30 points between two points to see if i run into any obstackles along the way. But if i use that to check every tile from every character, i end up with a loop that takes about 4 seconds to complete (20 x 20 map x 5 heroes x 30 points). That just wont work, since it has to recalculate every time one of the good guys move.

Then i tried drawing shapes over every obstackle in a seperate layer, to try some hittest with a straight line vs the obstackle map to make it simpler. But since i found out that can only use bounding boxes on two shapes, that makes it just as complicated as my first approach.

Does this make any sense, and can anyone point me in the right direction? :eek:

bluemagica
05-05-2009, 12:59 AM
umm...why are you checking 30 points? its a tile based game, so why don't you just check the tiles type, 4-5 tiles away?

scarce
05-05-2009, 07:14 AM
yeah agreed blue, your having it process 30 times more then needed. checking points are for object based games, your creating a tile based game, use tiles for everything, seriously man

Playaction
05-05-2009, 07:42 AM
Maybe i'm missing something obvious, but i check 30 times along a line like this, to see if charX can see charY. If the line crosses the corner of an obstackle LOS is blocked

http://www.stregen.dk/xytile.jpg

bluemagica
05-05-2009, 08:50 AM
Nobody cares for pixel perfect LOS. it will only lag your game! try dividing the check by half of the tile size, and you will still get quite convincing results for the gameplay! Also use distance check before doing LOS, if a object is out of range, there's no point in doing the LOS check!

Playaction
05-05-2009, 01:57 PM
Hehe - I'll try to be less accurate, and see if it still seems like a natural result. Thanks for helping!

Playaction
05-06-2009, 09:06 AM
If others with similar problems see this, i'll post the solution i came up with.

Instead of checking visibility from the character to every square, i checked lines out from the character in 4 degrees intervals. If a point on the line met an empty tileobstackle, it lights it up. If it meets an obstackle, the function breaks, since no more checking is nessesary.

It now works something like this :
http://www.stregen.dk/xytile2.jpg
Combined with less checkpoints along the lines, this turned out to be usable.