Created
April 25, 2021 19:24
-
-
Save filipesoccol/04366aa76002c52bc36281abfca29bad to your computer and use it in GitHub Desktop.
PICO8 - Sprite rotation
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
pico-8 cartridge // http://www.pico-8.com | |
version 18 | |
__lua__ | |
-->8 | |
-- rotating sprite adapted from @freds72 code | |
-- sx - sprite coordinate to be used | |
-- sy - sprite y coordinate to be used | |
-- x - sprite x position to be drawn | |
-- y - sprite y position to be drawn | |
-- a - sprite rotation angle in degrees | |
-- w - half width in pixels | |
-- h - half heigth in pixels | |
function rspr(sx,sy,x,y,a,w,h) | |
local ca,sa=cos_sin(a) | |
local xst = x-(sa*h)-(ca*w) | |
local yst = y-(ca*h)+(sa*w) | |
w*=2 | |
h*=2 | |
for ix=0,w,0.5 do | |
for iy=0,h,0.5 do | |
local c = sget(ix+sx, iy+sy) | |
if (c>0) pset(xst+(sa*iy)+(ca*ix), yst-(sa*ix)+(ca*iy), c) | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment