What algorithm could I use for fire
Posted: Tue Jul 06, 2021 1:11 pm
Jsut wondering which algorithm is used for fire and gas in roguelikes? A*?
Code: Select all
function FireGrowAndSpread()
-- check if each tile has a fire and if so, check if the fire grows and then check if it spreads to a neighbouring tile
-- firesize = the intensity of the fire within that tile from 0 -> 100. A small fire won't spread until it becomes a larger fire.
-- firetime = the time (dt) since the fire last spread. We need to cap this so fires don't instantly grow to 100% take over the whole map.
local firegrowspeed = 10 -- how fast a fire can grow on each tile (up to 100 (%))
local growthreshold = 50 -- a fire that is size 50 (%) has the potential to spread
local spreadchance = 50 -- the chance of a fire spreading (if greater than growthreshold)
local firetimer = 5 -- the frequency that fire growth and spread should be checked (in seconds)
local newfiresize = 20 -- the size new fires start at (%)
for each row
for each col
get firesize for current tile
if firesize > 0 and firetime <= 0 then
-- increse the firesize on this tile
firesize = firesize + love.math.random(1,firegrowspeed)
if firesize > 100 then firesize = 100
firetime = firetimer
-- see if fire spreads to another tile
if firesize >= growthreshold then
if love.math.random(0,100) <= spreadchance then
-- fire spreads
-- determine direction
local intRowDirection = love.math.random(-1,1) -- this could result in 0,0 and that's okay (freebie)
local intColDirection = love.math.random(-1,1)
-- determine tile
local newfiretilerow = row + intRowDirection
local newfiretilecol = col + intColDirection
-- check if new tile is a wall segment (walls don't catch fire)
if newtile.tiletype = enum.tileNormal then
-- if this new tile has no fire then start one
if newtile.firesize < newfiresize then
newtile.firesize = newfiresize
end
end
end
end
end
end
end
end