From 4b09e54b64f2eb6c0e37eb5e631e290aea1afd66 Mon Sep 17 00:00:00 2001 From: Fabien Freling Date: Wed, 27 Mar 2019 14:08:48 +0100 Subject: [PATCH] Create fire effect --- doom_fire.wren | 52 ++++++++++++++++++++++++++++++++------------------ 1 file changed, 33 insertions(+), 19 deletions(-) diff --git a/doom_fire.wren b/doom_fire.wren index 391a620..3377378 100644 --- a/doom_fire.wren +++ b/doom_fire.wren @@ -3,32 +3,46 @@ // desc: inspired by https://fabiensanglard.net/doom_fire_psx/ // script: wren +import "random" for Random + class Game is TIC{ construct new(){ _t=0 - _x=96 - _y=24 + // Init to black + _base = List.filled(240 * 136, 0) + for (last_line in (240 * 135)...(240 * 136)) { + _base[last_line] = 15 + } + _random = Random.new(12345) + TIC.cls(0) + } + + dofire() { + for (x in 0...240) { + for (y in 135..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 + } } TIC(){ - if(TIC.btn(0)){ - _y=_y-1 + for (y in 0...136) { + for (x in 0...240) { + TIC.pix(x, y, _base[x + y * 240]) + } } - if(TIC.btn(1)){ - _y=_y+1 - } - if(TIC.btn(2)){ - _x=_x-1 - } - if(TIC.btn(3)){ - _x=_x+1 - } - - TIC.cls(13) - TIC.spr(1+((_t%60)/30|0)*2,_x,_y,14,3,0,0,2,2) - TIC.print("HELLO WORLD!",84,84) - + dofire() _t=_t+1 } } @@ -54,6 +68,6 @@ class Game is TIC{ // // -// 000:140c1c44243430346d4e4a4e854c30346524d04648757161597dced27d2c8595a16daa2cd2aa996dc2cadad45edeeed6 +// 000:0000002424245d343471614ea54c30b66534ff4648da8930b27d55d27d2cc69548caaa2cd2aa4cc2c25ddad45effffff //