Create fire effect

This commit is contained in:
Fabien Freling 2019-03-27 14:08:48 +01:00
parent d3cb331c95
commit 4b09e54b64

View file

@ -3,32 +3,46 @@
// desc: inspired by https://fabiensanglard.net/doom_fire_psx/ // desc: inspired by https://fabiensanglard.net/doom_fire_psx/
// script: wren // script: wren
import "random" for Random
class Game is TIC{ class Game is TIC{
construct new(){ construct new(){
_t=0 _t=0
_x=96 // Init to black
_y=24 _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(){ TIC(){
if(TIC.btn(0)){ for (y in 0...136) {
_y=_y-1 for (x in 0...240) {
TIC.pix(x, y, _base[x + y * 240])
}
} }
if(TIC.btn(1)){ dofire()
_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)
_t=_t+1 _t=_t+1
} }
} }
@ -54,6 +68,6 @@ class Game is TIC{
// </SFX> // </SFX>
// <PALETTE> // <PALETTE>
// 000:140c1c44243430346d4e4a4e854c30346524d04648757161597dced27d2c8595a16daa2cd2aa996dc2cadad45edeeed6 // 000:0000002424245d343471614ea54c30b66534ff4648da8930b27d55d27d2cc69548caaa2cd2aa4cc2c25ddad45effffff
// </PALETTE> // </PALETTE>