While making a top-down map for my game, I needed to arrange some of its parts to fit better together, which required rotating some sections. Since PICO-8 does not provide a way to rotate a map selection, I wrote a simple utility function to do that.
This function rotates a square section of the map clockwise.
MX and MY are the map X and Y coordinates of the upper left corner, and MS is the length of the square side - 1 (e.g. to rotate an 8x8 square, set MS=7)
Notes:
- Make sure that you do not modify the map in any way before you call the rotate function, or the in-memory changes will be written to the cart
- Uncomment the second CSTORE (or edit the to edit the lower portion of the map
- This function is not optimized and is not intended for frequent use (unless you are making some gravity-based platformer, I suppose...)
-- rotate a square section -- of a map clockwise function rotate_map(mx,my,ms) -- read tiles local tiles={} for x=0,ms do tiles[x]={} for y=0,ms do tiles[x][y]= mget(mx+x,my+y) end end -- write tiles for x=0,ms do for y=0,ms do local tx=y local ty=mx+ms-x mset(mx+x,my+y,tiles[tx][ty]) end end cstore(0x2000,0x2000,0x1000) -- to edit extended map, uncomment --cstore(0x1000,0x1000,0x1000) end |
[Please log in to post a comment]