Friday, February 01, 2008

Testing an early implementation of fog-of-war

This is an early implementation and might not be very efficent.

The idea is, that we have an array of integers that represents the maptiles and an array of integers that represents the tiles we are able to see. Then when we draw the tiles, we just check if it is visible or not.

Here's a picture with a vision radius of 5 tiles.


And here's another with vision radius set to 10 tiles.


Calculationg wether or not a point is within the visibility range is simple. The idea is from Java forums, but I trust most people can figure this out without any help.

Here's the formula:
if (Math.Pow((x1 - x), 2) + Math.Pow((y1 -y), 2) < Math.Pow(10, 2)) {
fogOfWar[x, y] = 1; //As in visible
}

the x1 and y1 are the coordinates of the center of the structure. The 10 in the end is the range of visibily, aka. the radius of the circle. And x and y are the coordinates of the point whichs visibility we are currently trying to determine.

2 comments:

Anonymous said...

Good Afternoon

Definitely gonna recommend this post to a few friends

Anonymous said...

Good evening

Thanks for sharing, I have digged this post