The Daily Click ::. Forums ::. Klik Coding Help ::. Fog of war
 

Post Reply  Post Oekaki 
 

Posted By Message

Johan Hargne (Wartagon)

Lover Of Circys

Registered
  15/06/2003
Points
  1289

Game of the Week WinnerCROBASOFTVIP MemberPS3 OwnerWii OwnerMushroom
6th April, 2005 at 10:41:30 -

Hello.
Is it possible to do a visible fog in the directions that the player can't see?
Is there a way of creating a so called 'fog of war' in MMF ? If so, are there any tutorials, examples ?

thank you for taking your time.


 
Music Composer.
http://johan.hargne.se

Crobasoft
www.crobasoft.com

DeadmanDines

Best Article Writer

Registered
  27/04/2006
Points
  4758
6th April, 2005 at 11:04:47 -

Well I've never tried it, but lots have mentioned it before. I'm sure it's been done a few times.

Maybe you could have a set of objects over the screen, like 'tiles' of fog. Every second or so the player shoots a small raycasting object (you'd need fastloop for this) in all 32 directions. If the raycasting object touches an obstacle, it's destroyed. If it touches one of the 'fog' objects, then that object is made invisible, and one of its alterable values is set to 5.

Every second, MMF should loop through all the fog objects and reduce that value by 1 (so the 5 becomes 4, then 3, then 2, etc). When the value = 0, that fog object becomes visible again.

This way, the fog will stay invisible for 5 seconds before it assumes that the player has moved on, and the fog will come back. If the player stays where he is, then the raycaster objects (being fired every 3 seconds or so) will keep hitting the fog tiles and resetting their alterable value before they get a chance to reach 0.

If your game scrolls, then we have a bit more of a problem. Suppose the game window is 640x480, and each fog tile is 32x32 in size. This would mean that the screen is filled with a grid of 20x15 fog tiles. However we also have another row of tiles just outside the window, which the player can't see. This gives us a grid of 22x17 fog tiles (that's 374 tiles in total.

When the screen scrolls up, the tiles just off-screen at the bottom are placed just off-screen at the top (so what the user thinks are more fog tiles are in fact the same fog tiles he saw at the bottom of the screen a few seconds ago). The same goes for if the screen scrolls left, right or down. This way the same 374 tiles are being re-used.


Of course, 374 tiles is quite a bit - more active objects than you can fit in an entire TGF level! But MMF should be able to cope. If not, make the tiles bigger.

Image Edited by the Author.

 
191 / 9999 * 7 + 191 * 7
   

Post Reply



 



Advertisement

Worth A Click