Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

strategy game help: fog of war

Tags:

java

algorithm

im trying to make a real time strategy game such as starcraft or age of empires. my maps woud have to support up to about 1500 entities. My problem arrises with how to implement a fog of war without lagging the game. The method that i initialy tried was to simply caclulate the distance to all surrounding area of a unit everytime it moved but as i expected this lagged since many units would be constantly moving. If anyone knows a faster algorythim for a fog of war please help. the maps would be tile based and stored in an array.

like image 910
Stas Jaro Avatar asked Jan 19 '23 09:01

Stas Jaro


1 Answers

A quite basic implementation can be as follows:

  • Visibility is given by a value v[i,j] for each tile (i,j). Any value below a certain threshold lies within the fog.

  • The values are updated with regular time steps (note: for such a thing no high accuracy or high frequency is needed besides for very special cases) using the following two steps:

    1. blur the current map v[i,j]
    2. for each unit increase the value v[unit_i, unit_j] by a constant amount. You can also add a constant amount if a unit is on a square (no matter how many of them are there).
like image 107
Howard Avatar answered Feb 01 '23 04:02

Howard