Is there any way to rotate or flip a sprite map?
I have a platformer room that is a sprite map but want to be able to rotate/flip the map so I can get several rooms out of a single drawn room.
My alternative is to use the map as a blueprint and then just draw the sprites myself in the loop at coordinates so I can rotate them that way, but sounds like quite a bit of effort (for me and the P8). So hoping I can manipulate the sprite map somehow.
You can't flip the sprite map per se, but there's a few tricks you could do (which approach the problem in an entirely different way):
First, you could have a section dedicated to just map generation (maybe an 8x4 group of tiles). Then, you'd iterate and copy it to a "volatile" section, but in reverse. Your worldgen process would just read from the volatile area while you do whatever logic you need to prepare it. This is probably fairly token intensive.
Another option could be using sprites. Each sprite uses just two colors (eg white and black), with white indicating a valid location. You'd take a blank screen, and at every location, draw your sprites randomly. Then, just iterate over the image and convert it to an array or whatever you'd like. You can also do multiple draw passes so that doors, walls, etc only show up on specific pixel colors.
Other people might have a simpler way to accomplish what you want, though.
Is it for psuedo randomly generated maps? Like spelunky so you can have the same room a few times per game and it can be different? I'm not sure I fully understand the question but you could scan the map into a 2 dimensional table on _init() and then rotate or flip the coordinates of any of the "rooms" inside those sections of the table?
Yes, it's the Spelunky-ish model...using the same 32x32 room layout and flipping it around so 1 room could give me 4 options in a screen of 15 rooms.
Reading a map into a coordinates table might be the path of least resistance. I was trying to avoid having to draw all those sprites every loop but I'm thinking that's only way to get that feature if I want it.
Although for now I think I might just make a lot of map rooms and randomize those. I'm only using 15 blocks per level so if I make 24 different rooms, even not flipped, once they're jumbled up it might be okay. It'll prove the game concept that way before I spend time on something I might not need.
Just have a variable that when you flip it, draws the tiles "top to bottom" instead of "bottom to top," or "right to left" instead of "left to right." /GauntletIItricks
FWIW, most of my projects involve some dynamic level generation too, so I feel the frustration. I had to abandon my Metroidlike one because keeping a table of scenes that big was too much; even generating it properly made me hit the token wall. So now I'm going with sets of premade mini-maps instead, and just making some probabilistic object generation.
Could you not copy the map content into a table and flip/rotate the "rooms" you want then write over the current room in the map with its flipped rotated version? Then draw that onto the level. If you did this at the start of each level. Plus with if every room can be flipped and rotated and you only draw over the same rooms with the same room you will never lose any of the original rooms just their original orientations :)
Just for fun, here are some routines for flipping a region of the map in place:
Though as others mentioned, it sounds like what you actually want is to copy a region of the map reserved for room storage into a region of the map used for rendering, possibly transforming the region in the process. Then you can use map() to draw the playable region after generating the level.
[Please log in to post a comment]