Created
April 2, 2019 17:31
-
-
Save morningtoast/a59f2dda1b581289f0ec7e8a96d703d9 to your computer and use it in GitHub Desktop.
Good sprite rotation
This file contains hidden or 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
| -- 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