From 45efb366f3b4cff0b48d19a3e0658c46faef5403 Mon Sep 17 00:00:00 2001 From: Fabien Freling Date: Thu, 28 Mar 2019 13:16:31 +0100 Subject: [PATCH] Fix fire effect in wren --- doom_fire.wren | 33 +++++++++++++++++++++------------ 1 file changed, 21 insertions(+), 12 deletions(-) diff --git a/doom_fire.wren b/doom_fire.wren index 3377378..f0cdd5e 100644 --- a/doom_fire.wren +++ b/doom_fire.wren @@ -9,9 +9,11 @@ class Game is TIC{ construct new(){ _t=0 + _width = 240 + _height = 136 // Init to black - _base = List.filled(240 * 136, 0) - for (last_line in (240 * 135)...(240 * 136)) { + _base = List.filled(_width * _height, 0) + for (last_line in (_width * (_height-1))...(_width * _height)) { _base[last_line] = 15 } _random = Random.new(12345) @@ -19,26 +21,33 @@ class Game is TIC{ } dofire() { - for (x in 0...240) { - for (y in 135..1) { + for (x in 0..._width) { + for (y in 0...(_height-1)) { spreadfire(x, y) } } } spreadfire(x, y) { - var rand = _random.int(2) - var delta = rand - var index = x + y * 240 - _base[index - 240] = _base[index] - delta - if (_base[index - 240] < 0) { - _base[index - 240] = 0 + var rand = _random.int(4) // [0, 3] + var delta = rand & 1 + var side = -rand+1 // [-2, 1] + if (x+side < 0) { + side=0 + } + if (x+side >= _width) { + side = 0 + } + var index = x + (y*240) + _base[index+side] = _base[index + _width] - delta + if (_base[index+side] < 0) { + _base[index+side] = 0 } } TIC(){ - for (y in 0...136) { - for (x in 0...240) { + for (y in 0..._height) { + for (x in 0..._width) { TIC.pix(x, y, _base[x + y * 240]) } }