Fire spreading with wind

C

Captain_ArrowWound

Guest
In a game I am making, I am trying to create a basic fire system. A fire is spread with the wind direction and speed and the fire spreads based on tiles. So if one tile in on fire, and the wind direction is to the left and the tile to the left can be caught on fire, then the tile to the left will catch on fire after a certain amount of time. I can't figure out, how to figure out if a tile is burnable and then change the tile to a fire tile. Thanks for helping.
 

samspade

Member
In a game I am making, I am trying to create a basic fire system. A fire is spread with the wind direction and speed and the fire spreads based on tiles. So if one tile in on fire, and the wind direction is to the left and the tile to the left can be caught on fire, then the tile to the left will catch on fire after a certain amount of time. I can't figure out, how to figure out if a tile is burnable and then change the tile to a fire tile. Thanks for helping.
One thing that isn't clear from your post is whether you want the 'after a certain amount of time' to apply to the tile that is on fire or the tile that is burnable. In other words, if tile A is on fire, and tile B is the tile that could catch on fire, do you want tile A to be counting down or tile B?

Either way, I would create the following scripts:
  • scr_get_tile_in_direction(direction)
  • scr_is_tile_burnable(tile)
  • scr_set_tile_on_fire(tile)
Then your logic can be (in English and assuming that you want tile A to be counting down):

If tile is one fire
count down
when alarm goes off
tile = scr_get_tile_in_direction(wind_direction)
burnable = scr_is_tile_burnable(tile)
if tile is burnable
scr_set_tile_on_fire(tile)​

Without knowing anything about your code it is impossible to write what those scripts should be, but the primary logic could be used regardless.
 

TheouAegis

Member
One thing that isn't clear from your post is whether you want the 'after a certain amount of time' to apply to the tile that is on fire or the tile that is burnable. In other words, if tile A is on fire, and tile B is the tile that could catch on fire, do you want tile A to be counting down or tile B?
It would have to be tile A that sets the timer, if he is basing the spreading of the fire on a timer. But I like that you were even considering this! it does kind of take extranneous things into consideration. But the main reason he needs to keep it in tile A is because how else would it be put out the fire? He could put out the fire on A then tile B would still catch on fire anyway, even though now there's no fire to spread because he put it out. So even if he had tile be holding the counter, la would still have to be the one that count it down, so there's no point in having any other tile hold counter.

Technically you should have a flammability threshold for every tile type. This you would store in a global array at the start of the game. Each tile on fire would have a temp counter. As the counter goes up, you check for each tile around if the flammability threshold is below the counter. If it is, you set that tile on fire. Edit: to apply when to this, you would do something like half the threshold for the tiles that are in the direction of the wind. so you would fetch the tile type, let's say it is underbrush tile, it has a threshold of let's say 25; you store that value in a temporary variable, then you check if that tile is downwind and in this case it is, so you divide that temporary variable by 2; the temperature of the current tile is 14, which is less than 12.5, so the fire spreads to the next tile.

You will need a 2d array or a grid to hold off counters for all the tiles, so the bigger the room, the bigger the memory load. You could probably Frank down the memory load by only keeping track of tiles which have burnable neighbors. It would slow the code down a little bit, but it would cut back drastically on the memory use.

Edit: if we wanted to get a little more realistic, rather than checking just one time I love her, you sure Trac a wide swath around the fire. The tiles immediately adjacent 2 the currently burning tile in question would use the full temperature of the burning pile, the tiles farther away would use half and the tiles farther still use half of that. if you somehow manage to create a raging inferno in the middle of a room, that whole room is going to go up in flames really quickly. a little dinky fire in the corner of the room is going to burn the room a lot more slowly.
 
Last edited:
C

Captain_ArrowWound

Guest
Thank You! It works, but it has bad frame rate problems and I am not sure how to fix the frame problem. I don't know how to code something that would help the frame rate.

Here is the code

obj_fire

//North
if (place_meeting(x,y - 32, obj_grass)) and (global.windDirection = 1) and (fireTime > 10) and (haveCheckedNorth = 0)
{
instance_create_layer(x,y - 32,"Fire",obj_fire);
fireTime = 0;
haveCheckedNorth = 1;
}
//South
if (place_meeting(x,y + 32, obj_grass)) and (global.windDirection = 3) and (fireTime > 10) and (haveCheckedSouth = 0)
{
instance_create_layer(x,y + 32,"Fire",obj_fire);
fireTime = 0;
haveCheckedSouth = 1;
}
//East
if (place_meeting(x + 32,y, obj_grass)) and (global.windDirection = 2) and (fireTime > 10) and (haveCheckedEast = 0)
{
instance_create_layer(x + 32,y,"Fire",obj_fire);
fireTime = 0;
haveCheckedEast = 1;
}
//West
if (place_meeting(x - 32,y, obj_grass)) and (global.windDirection = 4) and (fireTime > 10) and (haveCheckedWest = 0)
{
instance_create_layer(x - 32,y,"Fire",obj_fire);
fireTime = 0;
haveCheckedWest = 1;
}
fireTime = fireTime + 1;

Thank You!
 

Slyddar

Member
For your frame rate problem, because you are creating a fire object every 10 steps, it might be too many of them. How long before the object destroys itself? Try drawing instance_number(obj_fire) to see how many are being created.

I've recently created fire arrows, and just used particles to create a fire like particle, and a smoke one. Looks pretty decent, and no issues with frame rate as each particle only lasts a second or so.
 
C

Captain_ArrowWound

Guest
Yea, I wasn't destroying the tile under the fire. So I destroyed the tile when it caught on fire, then after a few seconds I replaced the fire tile with a burnt out tile. It is working great now. Thank you all for the help!
 
Top