Last active
September 14, 2022 14:56
-
-
Save Liquidream/6c512ea17ff0b3eef7d2d7c58fda9e91 to your computer and use it in GitHub Desktop.
Fully commented source code for Lumon-8, a 1KB PICO-8 demake of the MDR program from the TV show Severance (made for #Pico1k jam 2022)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- lumon-8 (#pico1k) | |
-- paul nicholas | |
-- | |
-- step 1: initialisation | |
-- | |
poke(24365,1) -- enable mouse support | |
-- (custom font related) | |
-- first define the size of the custom font | |
poke(22016,4,4,6) | |
-- then define the actual font bitmap data | |
-- (note: only definining the portion of data relating to digits + a couple more for "%","x" and mouse pointer) | |
poke(22401,2,5,5,2,0,0,0,0,3,2,2,2,0,0,0,0,3,4,2,7,0,0,0,0,7,2,4,3,0,0,0,0,5,5,15,4,0,0,0,0,7,1,4,3,0,0,0,0,2,1,5,2,0,0,0,0,7,4,2,1,0,0,0,0,7,5,7,7,0,0,0,0,2,5,4,2,0,0,0,0,0,5,2,5,0,0,0,0,9,4,2,9,0,0,0,0,1,3,5,9,15,1,0) | |
u=0 -- 1st internal timer, used to track number size oscillation | |
v=0 -- 2nd timer, used to lerping the numbers into the selected bin | |
f={} -- table to store the data field of numbers (displayed on screen) | |
g={ -- init the bin data (each of the 5 bins stores data for each of the 4 types of numbers) | |
{0,0,0,0}, | |
{0,0,0,0}, | |
{0,0,0,0}, | |
{0,0,0,0}, | |
{0,0,0,0}} | |
?"\astb3a#ga#a#gg" -- play some notes from the intro to the tv show | |
a={1,2,3,4,5} -- table used to keep track of bins that are not yet full | |
-- | |
-- step 2: game loop | |
-- | |
::_:: | |
-- draw the header | |
oval(90,1,126,15,12) -- draw "world" bg part of the LUMON logo | |
oval(99,2,116,14) -- | |
rect(5,4,121,12) | |
r=false -- used to track when mouse is released | |
x=stat(32) -- track current mouse pos | |
y=stat(33) | |
if stat(34)>0 and #a>0 then -- if mouse button pressed AND not yet 100%... | |
if (not d) d=true j=x k=y -- if first click, then switch into drag mode and capture initial pos | |
else -- else (no buttons down) | |
if (d) then -- if was dragging... | |
r=true -- flag mouse button "released" | |
v=.01 -- start the lerp timer | |
s=rnd(a) -- select a random bin from those still available (not already full) | |
end | |
d=false -- cancel out of drag mode | |
j=nil -- clear last "initial click" position | |
end | |
rect(-1,17,128,19) -- draw the top double-line | |
rect(-1,101,128,103) -- draw the bottom double-line | |
for i=0,127 do -- loop through all of the number slots | |
n=f[i] or { -- get the number at current slot OR if not there, create a new number | |
n=rnd()*10\1, -- pick whole number between 0-9 | |
x=(i*8)%128+2, -- init x-pos based on index | |
y=((i*8)\128)*10+22, -- init y-pos based on index | |
a=(i*8)%128+2, -- store orig x-pos (used for lerping) | |
b=((i*8)\128)*10+22, -- store orig y-pos (used for lerping) | |
z=.5, -- default number "size" | |
v=rnd(), -- randomise number "size" growth seed | |
} | |
z=n.z+sin(u+n.v) -- init number "size" based on seed | |
-- if in drag mode and current number growth size is large enough | |
-- ...then store whether current number within drag area (...in n.s) | |
if(j)n.s=n.x<x and n.x>j and n.y<y and n.y>k and z>1.4 | |
-- draw current number with following criteria... | |
-- if current cursor pos is within 12 pixels, then draw with regular font | |
-- else draw using custom (tiny numbers) font | |
-- also, if current number is "selected" then draw white, else in normal blue col | |
?((((x-n.x)^2+(y-n.y)^2)^█<12 or z>1.4) and "" or "\14")..n.n,n.x,n.y,n.s and 7 or 12 | |
if(r and n.s) n.u=(s-1)*24+12 -- if button just released and current number is selected | |
-- ...then set it's lerp target to be pos of selected bin | |
if n.u then -- if current number has lerp target pos... | |
n.x=n.a*(1-v)+n.u*v -- update current pos using linear interpolation (lerp)-ing | |
n.y=n.b*(1-v)+103*v -- | |
if(v>1)then -- if lerp timer complete.. | |
n=nil -- "kill" current number | |
k=rnd{1,2,3,4} -- pick a random number type | |
g[s][k]=min(g[s][k]+1,25) -- increment the count of number type (to max of 25) | |
end | |
end | |
f[i]=n -- store update number back into field table (or nil, to get new one next cycle) | |
end | |
if (d) rect(j,k,x,y) -- if in drag mode, then draw rectangle for drag bounding area | |
u+=.0005 -- increment main timer (for number growth animations) | |
if v>0 then -- if lerp timer has been enabled | |
v+=.04 -- increment lerp timer (for lerp animations) | |
l=(s-1)*24+5 -- temp variable to store left-hand pos (for status report info box) | |
w=mid(.77-abs(v/2%4-.77),.37)-.25 -- third lerp timer, which does a "ping-pong" with pausing (for info box) | |
for i=1,4 do -- for each number type... | |
-- draw number current(i) type acronyms, using their corresponding colours | |
?"⁶#"..({"WO","FC","DR","MA"})[i].." ",l+2,112+i*6-w*4*65,("3421")[i] | |
-- now draw progress bar for current(i) number type (uses last drawn colour from above) | |
rectfill(l+11,113+i*6-w*4*65,l+11+.36*g[s][i],113+i*6+3-w*4*65) | |
-- draw the hatch "doors" for current bin | |
line(l,110,l+sin(w)*10,110-cos(w)*10,7) -- left | |
line(l+20,110,l+20-sin(w)*10,110-cos(w)*10) -- right | |
end | |
if(v>4)v=0 -- stop timer when it reaches the end | |
end | |
p=0 -- init overall percentage | |
rectfill(0,110,127,127,c) -- draw a black rect to clip/hide info box as animates behind the bin | |
for i=1,5 do -- for each bin... | |
b=g[i] -- get the current bin | |
b[0]=b[1]+b[2]+b[3]+b[4] -- store total for current bin into first slot | |
l=(i-1)*24+5 -- temp variable to store left-hand pos (for drawing bins) | |
rectfill(l,119,l+.2*b[0],126,7) -- draw progress bar for current bin | |
-- draw the bin number, and the percentage filled underneath it | |
?"\14 0"..i.."\n\|j"..b[0]..";",(i-1)*24+8,111,12 | |
rect(l,110,l+20,117) -- draw the bins | |
rect(l,119,l+20,126) -- | |
if(b[0]==100)del(a,i) -- if current bin is full, then take it out of the selection pool | |
p+=b[0] -- add current bin stats to overall percentage progress score | |
c=0 -- default clear col (black) | |
end | |
if(p\5==75)c=t()\1%4 -- if overall percentage progress = 75%, then enjoy a music/dance experience! | |
-- draw project name and also text part of the logo (with black bg to make clear against "world" bg) | |
?"sIENA ⁶w⁶x3\#"..c.."⁶-bLUMON",9,6 | |
if(p\5==100)?"⁶w⁶t⁶#100%",50,50,7 -- if all numbers refined (500, as 100 in each bin) then show user! | |
?"\14\f7<⁶1⁶c"..c,x,y -- draw mouse cursor using custom font letter... | |
-- ...and also flip() and cls() using P8SCII control chars (⁶1⁶c) | |
?(p\5).."% cOMPLETE",38,6 -- draw percentage complete amount | |
goto _ -- end of game loop |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment