Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

new fire #42

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
65 changes: 65 additions & 0 deletions src/elements/fire2.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
import * as water from './water'
import * as slime from './slime'
import * as sand from './sand'
import * as smoke from './smoke'
import * as oil from './oil'
import * as lava from './lava'
import * as gunpowder from './gunpowder'
import { EMPTY, empty } from './empty'
import * as element from '../element'
import { chance, pickRand } from '../random'

const BASE_COLOR = [35, 76, 62, 72]

const NAME = 'FIRE2'
const despawnChance = 0.2
const chanceOfGoingStraight = 0.95
const ignitingChance = 0.35

const make = () =>
element.make({
type: NAME,
color: pickRand([0xeb4833, 0xedb668, 0xe32e16]),
direction: pickRand([1, -1]),
})

const update = (sandpit, cell) => {
const above = sandpit.get(0, -1)

let fuel
let igniteTarget

for (let [nx, ny] of sandpit.neighbors1) {
const neighbor = sandpit.get(nx, ny)
if (neighbor.flammable) {
fuel = [nx, ny]
}
if (neighbor.type == EMPTY) {
igniteTarget = [nx, ny]
}
}

if (chance(0.5) && fuel && igniteTarget) {
sandpit.set(...igniteTarget, make())

if (chance(0.05)) {
sandpit.set(...fuel, make())
}
}

if (!fuel && chance(despawnChance)) {
sandpit.set(0, 0, empty())
}

switch (above.type) {
case EMPTY:
if (chance(chanceOfGoingStraight)) {
sandpit.move(0, -1)
} else if (sandpit.is(cell.direction, 1, EMPTY)) {
sandpit.move(cell.direction, -1)
}
break
}
}

export { NAME, make, update, BASE_COLOR }
3 changes: 3 additions & 0 deletions src/elements/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import * as water from './water'
import * as smoke from './smoke'
import * as wood from './wood'
import * as fire from './fire'
import * as fire2 from './fire2'
import * as oil from './oil'
import * as plant from './plant'
import * as slime from './slime'
Expand All @@ -18,6 +19,7 @@ export const activeElements = {
[water.NAME]: water,
[smoke.NAME]: smoke,
[fire.NAME]: fire,
[fire2.NAME]: fire2,
[oil.NAME]: oil,
[plant.NAME]: plant,
[slime.NAME]: slime,
Expand All @@ -35,6 +37,7 @@ export default {
smoke,
wood,
fire,
fire2,
oil,
plant,
slime,
Expand Down