How do I make automatic toggling of the roads?

Get help using Construct 2

Post » Fri Mar 25, 2016 7:48 pm

Hi,
I am making a city builder game of some sort and I have one big problem with roads. I personally do not place the roads on the map, because the player does that so I can't toggle them in the editor. I have only 4-directional roads, but I don't want to code every possibility of road placement, so I need some algorithm that will compare where the nearest roads are and toggle the road to connect to them. Any help from you guys is appreciated. Thanks!
B
3
Posts: 8
Reputation: 187

Post » Fri Mar 25, 2016 8:37 pm

Can you elaborate on 4-directional roads? Are your roads constrained to a grid? How many different types of intersections can you have? Are you using tilemaps or sprites?

Overlap at offset might be of use. Test each direction for existing roads, and set animation frame with the correct intersection.

An array storing the data of what is where could also be very useful in a grid based system, or something similar can be done with a tilemap as well.
Mistakes were made.
B
54
S
28
G
115
Posts: 1,705
Reputation: 65,083

Post » Fri Mar 25, 2016 9:24 pm

Yes, I can. Yes, thery are in a grid. I have 4 types of roads (straight, straight with one connected road, 4 directional intersection, curved road).
I will look at what you said. Seems pretty useful. Thanks.
B
3
Posts: 8
Reputation: 187

Post » Fri Mar 25, 2016 10:44 pm

The key information is for each direction around each road, does it contain a road or not?

I would use four boolean instance variables on your road sprite: up, down, left, and right. They will be true or false -if there is a road at that position it will be true, otherwise false. You can use 4 overlap at offset events to check each position, and set the variable.

Once you have that information for each sprite, you'll need to set the correct animation frame based on the instance variables.

The most straightforward way would be to have a frame for each variation of the curved road or T-intersection, but I'm sure there can be a way to reduce the frames required by rotating the image and using mirror when appropriate.
Mistakes were made.
B
54
S
28
G
115
Posts: 1,705
Reputation: 65,083

Post » Fri Mar 25, 2016 10:56 pm

Thanks. This was really helpful. It is now more clear to me with those 4 boolean variables.
Btw I did that with rotating the road by an angle before.
B
3
Posts: 8
Reputation: 187

Post » Sat Mar 26, 2016 7:46 pm

Search for "bitwise" with the forum search. The method is called bitwise tilemaps, and is usually done with terrain, but it would work perfect for roads.
B
94
S
33
G
117
Posts: 5,390
Reputation: 75,341

Post » Sat Mar 26, 2016 9:48 pm

Cool, thanks R0J0! I've used a binary sort of approach before but I never knew what it was called or how to explain it coherently. Now I know :)

Here is a link I found from another thread -http://www.saltgames.com/article/awareTiles/
Mistakes were made.
B
54
S
28
G
115
Posts: 1,705
Reputation: 65,083


Return to How do I....?

Who is online

Users browsing this forum: blackhornet and 6 guests