rotating a grid

Ask and answer questions about making games and related topics. Unrelated topics go in that other forum.

Moderators: marionline, SDHawk

Post Reply
User avatar
SwordPlay
Chemical Slime
Posts: 966
Joined: Sun Jan 22, 2017 9:32 am
Location: London, England
Contact:

rotating a grid

Post by SwordPlay »

rotating a grid (or, its contents)
does anyone know a simple or easy way of doing this?
I am considering writing a script that will reorder the children of a 2-dimensional array(?) (which is nearly the same thing) based on some things from here
You could use some kind of system where it places NPCs and writes map blocks based on a grid slice.

It can be combined with 4 way movement to keep the view directly behind the hero('s walking direction) (if they were to move on a grid)

I think it could be used for a lot of things, for example, (perhaps) 3D dungeon crawling style gameplay, where the grid slice is rotated to represent facing in 4 directions around the player. I think.

Maybe if there was an option for grid slices to choose the direction and startpoint of its children, that could be helpful? (If it is feasible)
Last edited by SwordPlay on Sat Jan 06, 2018 9:55 pm, edited 2 times in total.
"Imagination. Life is your creation."
TMC
Metal King Slime
Posts: 4308
Joined: Sun Apr 10, 2011 9:19 am

Post by TMC »

If you want to rotate a block of tiles or npcs, it's definitely easiest to do it directly using some of the code from the stack overflow question you linked to: either "in-place" meaning that the original grid of values is modified (which is more complicated), or else by creating a new grid of values, for example creating a rotated block of tiles elsewhere on the map, which will then require copying back to the original position.

On the other hand, rearranging the children of a grid slice to rotate their positions is pretty tricky, because reordering any child moves all the others too. If you want to do it in-place, it's going to be exceptionally tricky. You could create a new set of slices (use "duplicate slice" on each child to copy it), and then delete the original. That would be quite reasonable. If you can't delete the originals, the easiest solution is to use an array of global variables.

It could make sense for grid slices to have options for which to place the children in, just like layout slices do. I worked on it for 5 minutes but decided it's not going to be all that easy. Don't want to work on it unless there's an actual use for it.
Last edited by TMC on Sun Jan 07, 2018 4:27 pm, edited 1 time in total.
User avatar
Bob the Hamster
Lord of the Slimes
Posts: 7660
Joined: Tue Oct 16, 2007 2:34 pm
Location: Hamster Republic (Ontario Enclave)
Contact:

Post by Bob the Hamster »

I think you could reasonably rotate the children of a grid by doing a manual sort. You would loop through all the children. For each child, calculate it's 2D index based on its 1D index. Rotate those coordinates, convert back to 1D index and write that new index as the sort key.

I haven't tested it, but I think it ought to work.
TMC
Metal King Slime
Posts: 4308
Joined: Sun Apr 10, 2011 9:19 am

Post by TMC »

Oh, I didn't consider using sortchildren! Yes, that definitely seems to be the easiest possible way.
Post Reply