Skip to content

Instantly share code, notes, and snippets.

@Eiyeron
Created September 19, 2019 20:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Eiyeron/d55f516f695c1a6f490ec2aa1d28bcff to your computer and use it in GitHub Desktop.
Save Eiyeron/d55f516f695c1a6f490ec2aa1d28bcff to your computer and use it in GitHub Desktop.
-- accumulative random
-- allows for progressively
-- variating value instead
-- of pure random
function vrnd()
local start = 50
return function()
start = start + rnd(1)* (flr(rnd(2)) == 1 and 1 or -1)
start = mid(40,start,100)
return start
end
end
vrnd = vrnd()
fade_colors={
[11]=10,
[12]=10,
[13]=10,
[7]=11,
[10]=9,
[9]=8,
[8]=0
}
function spal(i,v)
poke(0x5f10+i,v)
end
spal(8,128+9)
spal(9,9)
spal(10,10)
spal(11,128+7)
spal(12,128)
spal(13,128+5)
spal(14,128+6)
-- the sprite uses green as
-- transparency
palt(3,true)
palt(0,false)
function _draw()
-- fire effect
-- first, make the fire
-- rise speed vary with time
local prt = vrnd()
for i=0,prt*45 do
-- let's take a random pixel
-- so first let's take a byte
-- in the screen memory.
local a=flr(rnd(0x2000))+0x6000
local v=peek(a)
-- split it in two pixels (4bits)
local v1=band(shr(v,4),0x0f)
local v2=band(v,0x0f)
local r = 0
-- if we're going to make
-- it fade (downgrade from
-- white to yellow to orange
-- to black
if rnd(5)<1 then
-- either the first or the
-- second pixel
if rnd(2)<1 then
r = bor(shl(fade_colors[v1],4),v2)
else
r = bor(shl(v1,4),fade_colors[v2])
end
-- else we're just keeping
-- the color as is.
else
r = v
end
-- update the current pixel
poke(a,r)
-- if we can write one pixel
-- higher
if a > 0x6000+64 then
-- let's do it
local r2 = peek(a-64)
poke(a-64,r)
end
end
rectfill(0,121,127,121,7)
for i=0,2 do
local y = 122+i*2
rectfill(0,y,127,y+1,14-i)
end
spr(0,16,59,6,8)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment