# Creating landscape from array

### » Wed Sep 22, 2010 12:04 pm

[quote="Dunkelseele":ene7wvq6]Another miracle: Where exactly do you say how big the array should be?[/quote:ene7wvq6]

To the left in the properties bar the X, Y and Z dimensions of the array can be entered.

[quote="Dunkelseele":ene7wvq6]What does the "For each element" condition do exactly? I guess it is a loop?[/quote:ene7wvq6]

Indeed. It loops through all the elements of the array.

[quote="Dunkelseele":ene7wvq6]What is "Array.CurrentX" exactly? [/quote:ene7wvq6]

When you're looping through the elements of the array, Array.CurrentX describes the current X position.

And if you haven't done so already, you can always take a look at the wiki: [url:ene7wvq6]http://sourceforge.net/apps/mediawiki/construct/index.php?title=Array[/url:ene7wvq6]

Oh, and since you're asking about Perlin Noise and arrays to create a random landscape you might learn one or two things by looking at the source of my older Perlinscape thingie: [url:ene7wvq6]http://www.scirra.com/forum/viewtopic.php?f=4&t=5084[/url:ene7wvq6]
B
21
S
6
G
10
Posts: 1,024
Reputation: 7,445

### » Wed Sep 22, 2010 12:36 pm

[quote="Dunkelseele":2gyzozww]Okay, so far a few new questions have arisen.
As far as I understand: You are filling the array with random data (I didn't noticed at first) from the range between 1 and 2. What does the "+1" after the "Random(2)" do? Does "Random()" start indexing at 0? So you add 1 afterwards to prevent a 0 showing up in the array?
[/quote:2gyzozww]
Yes

[quote="Dunkelseele":2gyzozww]
Another miracle: Where exactly do you say how big the array should be?
[/quote:2gyzozww]
PixelRebirth already answered this one, but i thought i would mention you can set the size of the array at runtime also, using the Set size action for the array object, just make sure the Z dimension is at least 1 or else it will break.
B
7
S
2
G
4
Posts: 164
Reputation: 2,418

### » Wed Sep 22, 2010 2:50 pm

Thanks to you two, I now understand another concept: referencing others objects values as variables in objects. I'm now near solving the problem that my map would need to be looking diamond-shaped while the map from your example, Citnarf, was a angular. box shape. You get it.

I'll probably upload a first version of the generator with some eye-candy tomorrow, so you can see all your effort in helping didn't went down the drain.
B
3
G
2
Posts: 35
Reputation: 770

### » Thu Sep 23, 2010 3:41 am

[quote:3jo1kln0]I'm now near solving the problem that my map would need to be looking diamond-shaped while the map from your example, Citnarf, was a angular. box shape. You get it[/quote:3jo1kln0]

That's a whole other box of worms since every other row/column is offset by a tile size.
If it makes things easier you can make a grid manually in the editor, and then load all your images into one sprite, then simply change the frames at runtime.
Thing is your still going to have to figure a way to get the offset, as well as pick that particular instance.

One thing I'll suggest is pick your tile sizes now, and make sure they work for both height and width... and divisible into the map. 48 x 23 doesn't work too well.
B
161
S
48
G
89
Posts: 7,347
Reputation: 66,249

### » Thu Sep 23, 2010 6:17 am

I just tried iso sprites with rts behavior with no issue (except sorting, of course, but that's better solved with the filmation algorithm... it gets easier if everything is ground-based)

Beautiful concept pixel art btw. Really, kudos.
B
3
S
2
G
4
Posts: 1,445
Reputation: 4,665

### » Thu Sep 23, 2010 7:53 am

[quote="newt":1bngpcsa]
That's a whole other box of worms since every other row/column is offset by a tile size.
If it makes things easier you can make a grid manually in the editor, and then load all your images into one sprite, then simply change the frames at runtime.[/quote:1bngpcsa]
I don't fully understand that. I can toggle on a visual grid to help manual placement, but that's not what you meant, right?
And how (and why) should I want to put all tiles into one sprite? Im utterly confused

[quote="newt":1bngpcsa]Thing is your still going to have to figure a way to get the offset, as well as pick that particular instance.[/quote:1bngpcsa]I'm out, maybe we talk about different things? At the moment the x/y positions of tile placement are defined as: (LayoutWidth / 2) + (Array.CurrentX * Global('tile_offset_x')), (20 + (Array.CurrentX * Global('tile_offset_y')) whereas the half-tileset-variable is used to offset the tiles, and is after every complete vertical row reduced by a full tilesize (50, 26). So I should start with a row as long as the arrays Y-value and continue to the left with new rows Array-x-length times...

My problem at the moment is, that the condition at which it should jump into the new row (by changing the offset) to place it, is too true. My current event sheet in shortform:
[code:1bngpcsa]Fill Array with random numbers,
go into for each loop {
if Array.CurrentX, Array.CurrentY is 1 - place Desert sprite at (see formulae above) and add 1 to variable x_counter.
if above condition is true and the variable x_counter is greater or equal than the Arrays X size - substract 50 from tile_offset_x and substract 26 from tile_offset_y

the same thing above again with the only difference that, if Array.CurrentX, Array.CurrentY is 2, a grass tile will be placed.
[/code:1bngpcsa]

I'm aware that at the moment, it would only produce two correct aligned rows... and probably all other rows over the second one after that. But even this don't work. Because every loop he substracts again from tile_offset_y and x which leads to abysmal values like -4029 and greater. I need this substraction only once, for now.

[quote="newt":1bngpcsa]One thing I'll suggest is pick your tile sizes now, and make sure they work for both height and width... and divisible into the map. 48 x 23 doesn't work too well.[/quote:1bngpcsa]
Yep, I did that after finding out I need to offset each next tile by half the tilesize, and 23 really isn't that great for dividing. So the new tilesize is 50x26px which divides nicely into 25x16 offsets.

[quote="madster":1bngpcsa]I just tried iso sprites with rts behavior with no issue (except sorting, of course, but that's better solved with the filmation algorithm... it gets easier if everything is ground-based)[/quote:1bngpcsa]
You're not telling me my effort was pointless because I could used an built in behaviour which does everything I am trying to do manually, are you? I can't even seem to find that RTS-behaviour-thingy in Constructor...

[quote="madster":1bngpcsa]Beautiful concept pixel art btw. Really, kudos.[/quote:1bngpcsa]
Thanks, wait till you see the real deal ingame, and in (modest) motion.
B
3
G
2
Posts: 35
Reputation: 770

### » Thu Sep 23, 2010 8:07 am

B
161
S
48
G
89
Posts: 7,347
Reputation: 66,249

### » Thu Sep 23, 2010 9:04 am

Epic. Using frames with zero animation speed is a clever thing. But I think this doesn't really helps me with the placing of my tiles. Besides the problem would then be, to change the animation frame of every tile according to numbers in an array.
B
3
G
2
Posts: 35
Reputation: 770

### » Thu Sep 23, 2010 9:59 am

Yes the idea is to have all the tiles already created, so all you would need to do is change the frame using your array IE:
if data at x, y is greater than one set frame of sprite at x,y to frame 2.
B
161
S
48
G
89
Posts: 7,347
Reputation: 66,249

### » Fri Sep 24, 2010 9:00 am

Okay, that's my current problem:

I want to draw him a column of tiles. I do this via:
[code:2hl03ttl]
FOR EACH entry in array "Array" {
IF:
value at Array.CurrentX, Array.CurrentY
THEN:
create object "GenericTile" at (LayoutWidth / 2) + (Array.CurrentX * Global('tileoffset_x')), 20 + (Array.CurrentX * Global('tileoffset_y'))
add 1 to global variable 'x_counter'
[/code:2hl03ttl]

Fine. He should have drawn a number of tiles now ... but if he doesnt stop, he will draw the next few rows also at the same position. So at the end, no matter how many columns I wanted, I will have only one column with all other columns stacked over it. So I want him to stop after the first column is done, correct the offset and continue.

[code:2hl03ttl]
IF:
'x_counter' equal to 'number_of_columns'
THEN:
substract 'substractor_x' from 'tileoffset_x
substract 'substractor_y' from 'tileoffset_y
add 1 to global variable 'number_of_columns'
}
[/code:2hl03ttl]

So the next column will be set off by the value of the substractor (usually the width of the tile). I continue this behaviour as often as needed till all columns are done. Is this wrong? It has to be, because it doesn't work.

BTW: Today is a rainy grey day. -.-
B
3
G
2
Posts: 35
Reputation: 770

PreviousNext