Skip to content

Instantly share code, notes, and snippets.

@JettMonstersGoBoom
Created April 20, 2020 15:15
Show Gist options
  • Save JettMonstersGoBoom/e5b9e604b08a19ff12a991b0e723b279 to your computer and use it in GitHub Desktop.
Save JettMonstersGoBoom/e5b9e604b08a19ff12a991b0e723b279 to your computer and use it in GitHub Desktop.
-- draw a mode7 style floor
scene = {x=10,y=10,z=140,hz=25,rot=0,spd=0}
-- fade table http://kometbomb.net/pico8/fadegen.html
local fadetable={
{0,0,129,129,129,129,1},
{1,1,1,1,1,1,1},
{2,2,133,133,133,1,1},
{3,3,131,131,131,131,1},
{4,4,132,5,133,133,1},
{5,5,133,133,1,1,1},
{6,13,13,13,141,5,1},
{6,6,6,13,13,5,1},
{8,136,136,2,2,133,1},
{9,137,4,4,5,5,133},
{10,138,138,134,5,5,133},
{11,139,139,3,3,131,131},
{12,12,140,140,140,131,1},
{13,13,141,141,5,1,1},
{14,134,134,141,141,141,1},
{15,134,134,134,141,5,1}
}
function fade(i)
for c=0,15 do
if flr(i+1)>=8 then
pal(c,1)
else
pal(c,fadetable[c+1][flr(i+1)])
end
end
end
-- draw the floor
function mode()
scene.rot = scene.rot % 1
-- grab cos and sin of scene angle
c = cos(scene.rot)
s = sin(scene.rot)
local sy_step = 1
local sy = sy_step
-- reset palettes
palt()
pal()
palt(0,false)
-- draw blue under ( tline doesn't draw color zero ? )
rectfill(0,scene.hz,127,127,1)
-- draw sky
rectfill(0,0,127,scene.hz,13)
for y=scene.hz,128 do
local t = (scene.z / sy)
sy = sy+sy_step
-- u v and edge uv step
local v,v_step = (-c - s)*t + scene.y,(2/128)*c*t
local u,u_step = (-s + c)*t + scene.x,(2/128)*s*t
local ur = (((u_step)))
local vr = (((v_step)))
local zz =((t)/scene.hz)
if (zz>0) then
fade((t/6)%8)
tline(0,y,127,y,u,v,ur,vr)
end
end
end
function _draw()
cls(0)
mode()
end
function _update()
if btn(4) then
if btn(2) then
scene.z+=1
end
if btn(3) then
scene.z-=1
end
else
if btn(0) then
scene.rot-=0.01
end
if btn(1) then
scene.rot+=0.01
end
if btn(2) then
scene.spd+=0.1
end
if btn(3) then
scene.spd-=0.1
end
end
scene.x += cos(-scene.rot)*scene.spd
scene.y += sin(-scene.rot)*scene.spd
scene.spd*=0.8
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment