[Solved]Random map generation - Array - Tiles

Get help using Construct 2

Post » Thu Jul 12, 2012 11:31 pm

What I am trying to do is generate a map that with randomize the streets. That is the first step. I will then add more conditions to make it more specific.

I really want 0,0 to be random and then from left to right choose different frames. I would just love to have 0,0 random and build from there.
B
12
S
1
Posts: 22
Reputation: 1,109

Post » Fri Jul 13, 2012 10:24 pm

Hello guys,

I have try different solutions and I think my code is right, but now I am stuck with 1,0 in my array that is staying on the same Sprite frame.

Can someone look at the code in my .capx and tell me what I am doing wrong ? I have been working on this for days now and none of my tries work.

It's the code in event sheet 2

https://dl.dropbox.com/u/89646560/Walker2.capx
I would really appreciate.
Cheers !

-Michael
B
12
S
1
Posts: 22
Reputation: 1,109

Post » Fri Jul 13, 2012 10:31 pm

[QUOTE=Wicstar] What I am trying to do is generate a map that with randomize the streets.[/QUOTE]

When we ask you what you're aiming for, this kind of answer is still vague.
What do you mean by "randomize the streets" ? In your program what are the "streets" supposed to be ?

Also your start of layout is quite messy.
You're running a loop to check the former value in the array and set the current value according to that, why is that so ?

For your first question you wanted to randomize the value at 0,0 coordinates in your array.

Why not simply use the action "Set Map.at(0,0) to random(the_range_of_values)" ?

As it is still unclear what you're wanting EXACTLY to do, it's hard to provide assistance.

Moreover you say you will add other conditions later ? It almost sounds as you don't even know what you're trying to do yourself. Detail EVERYTHING at once, and we might from this point propose implementations or guidance.Kyatric2012-07-13 22:32:13
New to Construct ? Where to start

Image Image
Image Image

Please attach a capx to any help request or bug report !
Moderator
B
247
S
85
G
40
Posts: 7,000
Reputation: 57,795

Post » Fri Jul 13, 2012 10:44 pm

Sorry if I am unclear on what I am trying to do.
It is my first time, and though I was doing it right.

Every time someone starts the game the map will be generated. I want it to be random and different each time.
I divided my layout in tiles, which are represented by the array.

I want 0,0 to be a random frame.
Then the 1,0 will look up what is to its left and select a frame number. I am using the choose() for that.

Then another line is telling to look at the array and to create a sprite at a determined position with the selected frame (array.CurValue)

The frames are made that they will create patterns of streets.

Saying that I will add more conditions was probably wrong. What I meant is: I want to have the first line in my array to work before trying to make the other rows match up. I want to get it right from the beginning to refrain from redoing tons of code.

In the end I want the game to look a bit GTA style.

I though that if I use "Set Map.at(0,0) to random(the_range_of_values)" the loop following it will replace the value that was randomized...

Is there anything more you require for info ? I am not sure if I am missing something.

Thanks for the help :)
B
12
S
1
Posts: 22
Reputation: 1,109

Post » Fri Jul 13, 2012 11:29 pm

First, your road sprite aren't really well designed. You shouldn't split the road in half. You should create a whole section of road and also create intersection sprites of the same size. Here in your cap you can't create a T intersection for instance. Then you start to see that you'd need many more sprites.

Second, one of the way to generate a street would be to create the road network first. By road network I mean simple 0 or 1 in your array to figure out if it's a road cell or a non road cell.
Then you just have to spawn the road sprite and check their surrounding to display the proper frame.

Now the algo to create such a road could be :

loop until you can't find any available cell
-> cell at X,Y = 1 (1 = road, 0 = no road)
-> choose a random direction between (1,0) (0,1) (-1,0) (0,-1)
-> if the next cell is a valid one (not already a road cell and not out of grid) set X and Y to it.

But then you will have a simple path without branching. For branching you'd have to go back in the road you've made and check for other adjacent available cells.

Anyway, look at some maze algorigthm you might find some good tips.
Yann2012-07-13 23:29:26
B
60
S
22
G
14
Posts: 1,479
Reputation: 16,346

Post » Fri Jul 13, 2012 11:38 pm

Wow thanks a lot Yann. You just gave me another way to look at it !
I really appreciate that and will give it a try!
B
12
S
1
Posts: 22
Reputation: 1,109

Post » Sat Jul 14, 2012 5:03 am

I have been working on this all night, and now I think my brain is dying slowly lol
(by the way Yann I tried CubeMaze and it's pretty awesome)

https://dl.dropbox.com/u/89646560/Walker3.capx

So here is what I came up with. I think I understand the principle, the problem is: I don't know how to get it to stop...
When I run it it either fills my layout or not, depending of the direction.

I read a lot of tutorial and array post, and nothing is really explaining how to make it add "1" in different direction (and keep going).
By using "For each XY element", if it read the new value "1" that was created it either stops or fill the layout. If the "1" is place to the left or the top it is too late because the "For each XY element" already passed those cells.

Would you be able to point me in the right direction, code wise, for:
If I just told the system to add a 1 in the array to question that new XY and not keep going from left-right and top-down (as part of the "For each XY element".)

I hope this is not too confuse, I am trying to explain what I think is happening, and what I think I read from your previous post.

Let me know if I need to be more clear.

Thanks for all the help !
-Michael
Wicstar2012-07-14 05:06:53
B
12
S
1
Posts: 22
Reputation: 1,109

Post » Sat Jul 14, 2012 6:24 am

Last edited by Yann on Sun Sep 14, 2014 9:09 pm, edited 1 time in total.
B
60
S
22
G
14
Posts: 1,479
Reputation: 16,346

Post » Sat Jul 14, 2012 5:30 pm

[QUOTE=Yann] https://dl.dropbox.com/u/23551572/C2/startingPoint.capx[/QUOTE]

Wow ! Thanks Yann. By looking at the code I think I just learned a lot. There is a lot of expressions I didn't know in what situation to use them, even after reading the tutorial.

I will recreate the code to learn it and play with it to create different things.

I guess I will get use think a certain way by doing it stuff like this over and over.
B
12
S
1
Posts: 22
Reputation: 1,109

Post » Sat Jul 14, 2012 6:37 pm

@Yann makes the best pancakes!
Don't see the fnords and they won't eat you!
B
75
S
16
G
12
Posts: 322
Reputation: 11,608

PreviousNext

Return to How do I....?

Who is online

Users browsing this forum: No registered users and 20 guests