F
Fun Looking Games
Guest
Hello fellow programmers! I am sure many of you are familliar with fog-of-wars, either you played a game that uses them or saw it in a video or friend playing. In case any of you are not familliar with the system by name I'll leave a screenshot of it being used in the famous game Age of Empires:
As you can see the elephant have a line of sight, this line of sight works for every building and units in the game, this line not only reveals enemy units and buildings that hasn't been explored, but also reveals black areas of the map (areas that none of your units have been yet).
This system is very useful for any strategy game, specially in multiplayer focused strategy games, as it gives every player in the match opportunities to be sneaky and come up with surprise strategies (it wouldnt be much of a strategy if your enemy always knows what you are doing).
I am making an RTS where needs this system to work, I've searched many tutorials on youtube and google. Found some that helped me a bit and came up with something that looks like this:
Note: This a very early build of the game, something like version 0.01 much of it are place holders.
As you can see, although what I have is pretty buggy already, I already got the black-fog to be working, what I can't bring it work is the line of sight fog, the one that fades the rest of the world that isnt being seen already by any unit. Here is my code:
This is the black-fog code.
This is the secondary fog code, which for some reason just refuses to exist.
And this, finally, is the fog revealler code, this makes the fog be revealed based on a sprite that is basically a white circle with 'glow effected' border.
______________________________________________________________________________________
The final effect should look something like this (Starcraft series):
I know that grid based fog of war would be easier to make (conceptually), but an grid based system wouldn't work for what I'm aiming.
_____________________________________________________________________________________
Also searched for some algorythms on fog of war systems but none of them helped me. I'm sure that the solution to this would help not only me but many developers who wants to implement this system!
Thank you in advance and have an awesome week!
Spark, FunLookingGames.
As you can see the elephant have a line of sight, this line of sight works for every building and units in the game, this line not only reveals enemy units and buildings that hasn't been explored, but also reveals black areas of the map (areas that none of your units have been yet).
This system is very useful for any strategy game, specially in multiplayer focused strategy games, as it gives every player in the match opportunities to be sneaky and come up with surprise strategies (it wouldnt be much of a strategy if your enemy always knows what you are doing).
I am making an RTS where needs this system to work, I've searched many tutorials on youtube and google. Found some that helped me a bit and came up with something that looks like this:
Note: This a very early build of the game, something like version 0.01 much of it are place holders.
As you can see, although what I have is pretty buggy already, I already got the black-fog to be working, what I can't bring it work is the line of sight fog, the one that fades the rest of the world that isnt being seen already by any unit. Here is my code:
Code:
Information about object: obj_blackfog_controller
Sprite:
Solid: false
Visible: true
Depth: 9999
Persistent: true
Parent:
Children:
Mask:
No Physics Object
Create Event:
execute code:
res = 5; //resolution
sfog = surface_create(room_width/res, room_height/res);
surface_set_target(sfog);
draw_clear(c_black);
surface_reset_target();
Draw Event:
execute code:
draw_surface_ext(sfog, 0, 0, res, res, 0, 0, 1);
Code:
Information about object: obj_fog_controller
Sprite:
Solid: false
Visible: true
Depth: 9999
Persistent: true
Parent:
Children:
Mask:
No Physics Object
Create Event:
execute code:
res = 5; //resolution
sfog = surface_create(room_width/res, room_height/res);
surface_set_target(sfog);
draw_clear(c_black);
surface_reset_target();
Step Event:
execute code:
sfog = surface_create(room_width/res, room_height/res);
surface_set_target(sfog);
draw_clear(c_black);
draw_set_alpha(.5);
surface_reset_target();
Draw Event:
execute code:
draw_surface_ext(sfog, 0, 0, res, res, 0, 0, .5);
Code:
surface_set_target(obj_blackfog_controller.sfog);
draw_set_blend_mode(bm_src_color);
draw_sprite_ext(spr_fogrevealer, 0, x/obj_blackfog_controller.res, y/obj_blackfog_controller.res, 0.8, 0.8, 0, 0, 1);
draw_set_blend_mode(bm_normal);
surface_reset_target();
surface_set_target(obj_fog_controller.sfog);
draw_set_blend_mode(bm_src_color);
draw_sprite_ext(spr_fogrevealer, 0, x/obj_fog_controller.res, y/obj_fog_controller.res, 0.8, 0.8, 0, 0, .5);
draw_set_blend_mode(bm_normal);
surface_reset_target();
______________________________________________________________________________________
The final effect should look something like this (Starcraft series):
I know that grid based fog of war would be easier to make (conceptually), but an grid based system wouldn't work for what I'm aiming.
_____________________________________________________________________________________
Also searched for some algorythms on fog of war systems but none of them helped me. I'm sure that the solution to this would help not only me but many developers who wants to implement this system!
Thank you in advance and have an awesome week!
Spark, FunLookingGames.
Last edited by a moderator: