Skip to content

Instantly share code, notes, and snippets.

@morningtoast
Created April 2, 2019 17:31
Show Gist options
  • Select an option

  • Save morningtoast/a59f2dda1b581289f0ec7e8a96d703d9 to your computer and use it in GitHub Desktop.

Select an option

Save morningtoast/a59f2dda1b581289f0ec7e8a96d703d9 to your computer and use it in GitHub Desktop.
Good sprite rotation
-- rspr(spritesheetX,spritesheetY, screenX,screenY, angle, tileWidth, transColor)
-- tileWidth is squared when look at sprites. So a tileWidth=2 will do a 2x2 tile size (16x16) at sx,sy
function rspr(sx,sy,x,y,a,w,trans)
local ca,sa=cos(a),sin(a)
local srcx,srcy,addr,pixel_pair
local ddx0,ddy0=ca,sa
local mask=shl(0xfff8,(w-1))
w*=4
ca*=w
sa*=w
local dx0,dy0=sa-ca+w,-ca-sa+w
w=2*w-1
for ix=0,w do
srcx,srcy=dx0,dy0
for iy=0,w do
if band(bor(srcx,srcy),mask)==0 then
local c=sget(sx+srcx,sy+srcy)
if c!=trans then
pset(x+ix,y+iy,c)
end
end
srcx-=ddy0
srcy+=ddx0
end
dx0+=ddx0
dy0+=ddy0
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment