Has anyone got some 2d tile array creation code?
Ok. This may be simple, but once again, I'm stumped. :(
I'm trying to generate a 2d tiled board of X length and Y height.
If I was coding it, I'd nest for loops to create the tiles in a 2D array.
I'm presuming fastloops is the way to go for this.
I've got it to create the line of tiles on the X.
But I'm having trouble getting it to repeat on a new line below.
I really want to be able to add 36 pixels to the Y dimension and reset the loopindex and start it going again, but limit it to only doing this 7 times.
Does anyone have an example of creating an X by Y tiled board out of active objects?
Eventually the plan is to read values from an array and set each active objects frame to the corresponding array value.
Which will require some more fastlooping.
Re: Has anyone got some 2d tile array creation code?
Here is the non-array method:
First, define xMargin and yMargin either as counters or a global / alterable value and give them the values of the upper left corner of your board.
* start of frame
- start loop "X" 7 times
* on loop "X"
- start loop "Y" 7 times
* on loop "Y"
- Create Active at 0,0
- Active: set Xpos to value of xMargin + (loopindex("X") * 36)
- Active: set Ypos to value of yMargin + (loopindex("Y") * 36)
This will make a 2D table that is 7 tiles in each dimension.
Re: Has anyone got some 2d tile array creation code?
The way popcorn mentioned above is the way I go about doing things, but another way is to use the Mod expression, but that makes things too messy IMO. You are better of using a method that is easy to follow, otherwise things get messy too quick.
Re: Has anyone got some 2d tile array creation code?
ya, like this
* start of frame
- start loop "A" 49 times
* on loop "A"
- Create Active at 0,0
- Active: set Xpos to value of xMargin + ((loopindex("A") mod 7) * 36)
- Active: set Ypos to value of yMargin + (((loopindex("A") -(loopindex("A") mod 7))/7) * 36)
Re: Has anyone got some 2d tile array creation code?
Thanks for the replies.
I was attempting the method popcorn has described.
My approach was very similar, but I think I just had the bits in the wrong place. :(
I'll get that implemented tonight and then see if I can make the Loops run a user defined number of times, which should allow me to make different board sizes. (should be easy that one)
I don't think I'll bother with different board shapes. (although perhaps could do, after reading in the level data, I could check for 0's and remove them.) But that's waaaay down the line.
Next step is to get it to run through the loop again, while reading the Value from an array and making the active object's frame/direction equal to that.
Does anyone know how the 'Array' stores it's data?
Is it seperated via commas? e.g.
1,23,-3,19
I suppose I could setup a little test to write to an array and ave it out as a text file to see.
Re: Has anyone got some 2d tile array creation code?
Re: Has anyone got some 2d tile array creation code?
Hey people.
I've been trying to get this array saving and loading working.
I think I've got it saving, but the loading part, doesn't seem to work.
Can anyone figure out what I'm doing wrong?
I'm trying to get it to set the animation frame to the current value in the array, as it performs an X and Y fastloop to create the board and increases the value in the array with each.
But what it is doing is just making every active object have frame 1 as their frame.
Is it because the value in the array is binary? and I need to convert it to a normal number such as 0,1,2,3,4,5?
Also, How can I open the saved out array file?
I can only seem to open it in notepad, and it interprets the numerical values as ASCII. (so I can at least check it is working, I need to look at the ASCII table and can see it is savign values out.)
http://rapidshare.com/files/223573021/2D_Board_array_load_test1.zip.html
(Rapidshare is limiting the number of downloads to 10, so please, only download it if you think you can help.)
Re: Has anyone got some 2d tile array creation code?
Upon investigating the problem.
The board creation doesn't save out into the array correctly. It does, 1,1 1,2 1,3 2,4 2,5 2,6 3,7 etc
I had a look at the guy with the Puddinghat website's example, but it doesn't create the board, the board is already laid out, which is clunky and impractical for me. :( So the whole thing is not much use.
After trying for ages to get it to properly create the 2d array, I gave up and started try to save and load a 1d array with my current board creation. But that didn't quite work either.
I've started looking at the String X thing instead, as it might work better.
Either that, or I will have to re-do my board creation stuff to use an array in the first place. :)
But seeing as how I can't get it to work properly I don't hold out much hope.
When I force the animation frame to the X dimension I get this. (which shows that bit is working)
1 2 3 4
1 2 3 4
1 2 3 4
1 2 3 4
1 2 3 4
When I force the animation frame to the Y dimension I get this. (which shows that bit is NOT working)
2 7 12 17
3 8 13 18
4 9 14 19
5 10 15 20
6 11 16 21
So if I'm going to make it store in the array as a 1d array, I need to remove the Adding 1 to X dimension bit, whilst storing values into the Y dimension and reading from them.
Or I need to sort out the Y dimension numbering, as it should be...
1 2 3 4
1 2 3 4
1 2 3 4
1 2 3 4
Anyone got any suggestions?
Re: Has anyone got some 2d tile array creation code?
Ok. Managed to solve it. :)
I needed to reset the X dimension value when it reached the end.
Now, I think..... I should be able to use an array to load the values in, as the X,Y of the board should match the X,Y of the array.
* start of frame
- start loop "X" 7 times
- Clear Array
- Set Dimensional Index X to 1
- Set Dimensional Index Y to 1
* on loop "X"
- start loop "Y" 7 times
- Add 1 to X Dimensional Index
- Set Y Dimensional index to 1
* on loop "Y"
- Create Active at 0,0
- Active: set Xpos to value of xMargin + (loopindex("X") * 36)
- Active: set Ypos to value of yMargin + (loopindex("Y") * 36)
- Add 1 to Y Dimensional Index