Skip to content

Instantly share code, notes, and snippets.

@Level0gamedev
Last active July 10, 2017 02:07
Show Gist options
  • Save Level0gamedev/6ab43939a6d376a3763e9348670f49f5 to your computer and use it in GitHub Desktop.
Save Level0gamedev/6ab43939a6d376a3763e9348670f49f5 to your computer and use it in GitHub Desktop.
cls()
function _init()
--we need a table to store what is transparent
transparent = {8,5,4,10,3,11}
--ignore beow two, they are just helpers to move
px = 60
py = 60
end
--outlining function
function ospr(sprite, x,y, outline_col, w, h) --use x and y where you want to draw normally, outline_col normally 0
w=w or 1 --those two vars allow
h=h or 1--for a multi-tiled sprites
--the function proper
for i=0,15 do -- go through all the colors
for j = 1,#transparent do -- go through everything in table of transparent colors
--this is where magic happens
--if color is in our transparent table
if i==transparent[j] then
palt(i,true) -- make it transparent
else
pal(i,outline_col) --changes this color to outline
end
end
end
--draw outline
spr(sprite, x-1,y, w, h) --draw the shadows 4x offsetting it by 1px (size of outline) do it 8x for better outline (with diagonals on x+/-size,y+/-size)
spr(sprite, x,y-1, w, h)
spr(sprite, x+1,y, w, h)
spr(sprite, x,y+1, w, h)
--now we just have a blob in color of outline
pal() -- return palette to normal
pal(10,6) --this makes the yellow hands white
make_transparent() -- make things inside our table transparent
spr(sprite, x,y, w,h) -- draw a sprite over those shadows
pal() --and finally, return palette to normal again, for drawing the rest of sprites
end
--this makes any color inside
--transparent table, transparent
function make_transparent()
--go through the transparent table
for i = 1,#transparent do
--and make each color not show
palt (transparent[i], true)
end
end
function _update60()
rectfill(0,0,128,128,1)
--call outline function
--for player sprite
ospr(1,px,py,0,2,2)
--all the btn and btnp things are just for pico testing
if btn(0) then px-=2 end
if btn(1) then px+=2 end
if btn(2) then py-=2 end
if btn(3) then py+=2 end
if btnp(4) then
del(transparent, transparent[#transparent])
end
end
--
--during the game we just add
--or remove colors to/from
--transparent table depending
--on what body parts you have
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment