What algorithm could I use for fire
- Gunroar:Cannon()
- Party member
- Posts: 1144
- Joined: Thu Dec 10, 2020 1:57 am
What algorithm could I use for fire
Jsut wondering which algorithm is used for fire and gas in roguelikes? A*?
Re: What algorithm could I use for fire
as in fire spreading and growing on a tiled map?
I roll my own based on random probabilities along 4 axis or 8 axis adjusted by the degree of flammable material in each tile.
I roll my own based on random probabilities along 4 axis or 8 axis adjusted by the degree of flammable material in each tile.
Last project:
https://togfox.itch.io/hwarang
A card game that brings sword fighting to life.
Current project:
Idle gridiron. Set team orders then idle and watch: https://togfox.itch.io/pad-and-pencil-gridiron
https://togfox.itch.io/hwarang
A card game that brings sword fighting to life.
Current project:
Idle gridiron. Set team orders then idle and watch: https://togfox.itch.io/pad-and-pencil-gridiron
- Gunroar:Cannon()
- Party member
- Posts: 1144
- Joined: Thu Dec 10, 2020 1:57 am
Re: What algorithm could I use for fire
Thnx, and yes fire spreading on a roguelike. Does that also work for water?
Re: What algorithm could I use for fire
Since I'm literally (re)writing my fire routine, here is my pseudo/code I call from love.update(dt):
You'll need to make it work for yourself and pass parameters etc but the above displays a natural fire spread that can get out of control if players don't react correctly. One day I'll expand it to naturally die down after a period of time. Shouldn't be hard.
Water is a completely different beast as the expectation is that will flow uniformly and not randomly. Not something I've needed to address just yet.
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
Water is a completely different beast as the expectation is that will flow uniformly and not randomly. Not something I've needed to address just yet.
Last project:
https://togfox.itch.io/hwarang
A card game that brings sword fighting to life.
Current project:
Idle gridiron. Set team orders then idle and watch: https://togfox.itch.io/pad-and-pencil-gridiron
https://togfox.itch.io/hwarang
A card game that brings sword fighting to life.
Current project:
Idle gridiron. Set team orders then idle and watch: https://togfox.itch.io/pad-and-pencil-gridiron
- Gunroar:Cannon()
- Party member
- Posts: 1144
- Joined: Thu Dec 10, 2020 1:57 am
Re: What algorithm could I use for fire
Yeah, that's what I'm talking about . It's strange because I can never find water/gas/fire tutorials or anything like that online. FOV? Sure. Pathfinding? Yep? Hunger clocks? Always. But the most I've heard about implementing those others is cellular automaton. Thanks.
Who is online
Users browsing this forum: Google [Bot] and 4 guests