-
-
Save Woflox/c5c8bf57c36799553afc1400ebba5085 to your computer and use it in GitHub Desktop.
Picopelago commented source code
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
--Created by Eric Billingsley. This code is licensed under the Attribution-NonCommercial-ShareAlike 4.0 International license (CC BY-NC-SA 4.0): https://creativecommons.org/licenses/by-nc-sa/4.0/ | |
--clear screen & sprite sheet | |
cls() | |
memset(0,0,0x1000) | |
--color ramps | |
--increase elevation | |
r={2,3,4,5,6,7,8,9,10,11,12,13,14,15,15,1} | |
--decrease elevation | |
r2={0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,0} | |
--height to shadow color | |
rs={1,1,8,2,9,9,8,8,8,8,9,9,9,9,9,0} | |
--water sparkle palette | |
rw={2,2,3,12,[0]=1} | |
--height to unshadowed color | |
rpost={1,1,2,3,4,5,6,6,7,7,7,13,10,11,12,0} | |
--screen palette | |
pal({1,140,12,135,9,139,3,131,5,134,6,7,13,132,133,129},1) | |
palt(0) | |
mode="title" | |
selection=0 | |
o=0 | |
draw=1 | |
x,y=64,64 | |
sparkles={} | |
function dirtyline(y) | |
dirtylines[mid(127,flr(y))]=true | |
end | |
for y=0,255 do | |
--sparkles are two pixels in | |
--a horizontal line, random | |
--distance apart | |
x=flr(rnd(128)) | |
sparkles[y]={x,x+flr(rnd(4)),flr(rnd(4))} | |
end | |
--sspr that wraps screen edges | |
function ssprwrap(x,y,w,h,yoffs) | |
for sy=y,y+h-1 do | |
--h was meant to be 1 here but I didn't catch it. | |
--seems to look ok as is and | |
--fixing it increases compressed chars | |
sspr(x,sy%128,w,h,x,(sy+yoffs)%128) | |
sspr(x-128,sy%128,w,h,x-128,(sy+yoffs)%128) | |
dirtyline(sy%128) | |
end | |
end | |
--refresh screen | |
--(mark all lines to be | |
--redrawn from height data) | |
function rf() | |
for i=0,127 do | |
dirtyline(i) | |
end | |
end | |
function _draw() | |
--draw to sprite sheet | |
--(where we keep height data) | |
poke(0x5f55, 0x00) | |
dirtylines={} | |
--select mode | |
if mode=="title" and btnp(❎) then | |
mode=selection | |
rf() | |
if mode==1 then | |
cls() | |
poke(0x5f2d,3) | |
end | |
elseif mode==1 then | |
--redraw lines where | |
--mouse cursor was last frame | |
dirtyline(my-1) | |
dirtyline(my) | |
dirtyline(my+1) | |
end | |
--get mouse coords | |
mx,my=stat(32),stat(33) | |
if mode==1 then | |
--for draw mode, | |
--set draw coords to mouse | |
x,y=mx,my | |
end | |
for n=1,16 do | |
--move coords randomly | |
x=(x+rnd(4)-2)%128 | |
y=(y+rnd(2)-1)%128 | |
--brush size | |
draw=mid(draw+rnd"0.5"-0.25,2,mode==1 and 1) | |
--only draw if mouse pressed | |
--or we're in title/screensaver mode | |
if mode!=1 or stat(34)!=0 then | |
if draw>1 then | |
pal(rnd{r,0}) | |
palt(0) | |
--increase elevation and | |
--move up in y coord for | |
--rectangular area | |
ssprwrap(x-2,y,draw*4,draw*2,-1) | |
--do it again in a smaller | |
--rect if brush size is | |
--big enough | |
if draw>1.5 then | |
ssprwrap(x,y-1,draw*4-4,1,0) | |
end | |
end | |
end | |
pal(0) | |
palt(0) | |
--erosion -- done a bunch of | |
--times on the same line so | |
--fewer lines dirtied | |
erody=flr(rnd(128)) | |
for n=1,20 do | |
erodx=rnd(128) | |
--erode downwards only for | |
--3d effect. vary x offset | |
erod2x,erod2y=(erodx+rnd{-1,0,1})%128,(erody+1)%128 | |
col1,col2=pget(erodx,erody),pget(erod2x,erod2y) | |
--randomly add or subtract | |
--1 from erosion result | |
--for more variation | |
toadd=rnd{-1,0,0,1} | |
--only erode if difference>=2 | |
if col1>col2+1 then | |
--bring the 2 points closer | |
--together in height | |
pset(erodx,erody,col1-1+toadd) | |
dirtyline(erody) | |
pset(erod2x,erod2y,col2+1+toadd) | |
dirtyline(erod2y) | |
end | |
--if we find max height pixel, | |
--decrease height of whole map | |
--(small probability) | |
if col1==15 and rnd()<0.001 then | |
pal(r2) | |
sspr(0,0,128,128) | |
rf() | |
end | |
end | |
--vary which pixels of a | |
--sparkle are visible | |
sparkles[flr(rnd(255))][3]=flr(rnd(4)) | |
end | |
--draw to screen (final rendered | |
--image) | |
poke(0x5f55, 0x60) | |
--only draw dirty lines | |
for y,v in pairs(dirtylines) do | |
--shadow height | |
s=0 | |
pal(rpost) | |
--draw whole line with | |
--unshadowed colours | |
sspr(0,y,128,1,0,y) | |
pal(rs) | |
--step through line and | |
--calculate shadows | |
for x=0,127 do | |
col=sget(x,y) | |
if s>col+0.5 then | |
--in shade, draw shadow color | |
pset(x,y,col) | |
elseif col<5 and ((sparkles[y][3]>1 and sparkles[y][1]==x) or (sparkles[y][3]%2==1 and sparkles[y][2]==x)) then | |
--draw water sparkle | |
--(no sparkles in shadows) | |
pal(rw) | |
pset(x,y,col) | |
pal(rs) | |
end | |
--update shadow height | |
if col>s then | |
s=col | |
end | |
s-=0.5 | |
end | |
end | |
pal(0) | |
--draw title screen | |
if mode==1 then | |
?"\31",mx-1,my-1,12 | |
pset(mx,my,0) | |
elseif mode=="title" then | |
pal(0) | |
rectfill(0,29,127,50,2) | |
rectfill(0,83,127,96,2) | |
selection=(selection+tonum(btnp(⬆️))-tonum(btnp(⬇️)))%2 | |
?"\^t\^wpICO\|hp\|fElAgO",25,32,3 | |
?"\^t\^wpICO\|hp\|fElAgO",26,31,12 | |
?"BY ERIC BILLINGSLEY",29,44,12 | |
?"sCREENSAVER MODE",33,84,12 | |
?"dRAW MODE",33,91,12 | |
?"❎",22,84+selection*7,1 | |
?"❎",22,83+selection*7+4*t()%2,12 | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment