How can I make a grid of hexagons?

Get help using Construct 2

Post » Sat Sep 14, 2013 2:15 am

Hello. I am trying to make a hexagon-grid for a project of mine. What I am trying to do is to place 19 different hexagons in a "circle" and I want them to be randomly placed every time I push a button (or start the layout). One piece must never be placed two times in the same grid. Any ideas how I can do this? To make sure you understand, I made an example. The lonely hexagon is not ment to be included. Please don't make this too hard to understand, I am new at Construct. =)

Example: https://www.dropbox.com/s/bynju9iob9xfaqd/HexCircle.png
B
7
Posts: 3
Reputation: 294

Post » Sun Sep 15, 2013 5:55 am

Use the grid you have as a background. Set up co-ordinates for each of the 19 possible locations. When button is pressed, choose a random location and place the hexagon object at the location.
B
46
S
16
G
74
Posts: 2,089
Reputation: 44,187

Post » Sun Sep 15, 2013 2:56 pm

@plinkie I am not trying to be rude, but isn't that just what I said? Except I need to place 19 hexagons, not just 1. And I want to do it with as few events/actions possible.
B
7
Posts: 3
Reputation: 294

Post » Sun Sep 15, 2013 4:43 pm

Those are the events and actions. You could also do it by placing all 19 hexagons, making them invisible and then making them 'randomly' visible at the click of a button.
B
46
S
16
G
74
Posts: 2,089
Reputation: 44,187

Post » Sun Sep 15, 2013 4:45 pm

Here's one possible way, which is assuming you already layed out the hex tiles and just need to switch to an appropriate animation frame.
random_hex_grid.capx
Image
B
24
S
8
G
10
Posts: 1,821
Reputation: 8,279

Post » Sun Sep 15, 2013 7:02 pm

tulamide example is awesome. You can also use a variant

take your image.
remove all the numbers.
in your image. place 19 more image points reference each position.
use the image points to put down objects of value. (floor(random(1,20) )

B
90
S
18
G
9
Posts: 2,455
Reputation: 15,018

Post » Sun Sep 15, 2013 11:01 pm

Thank you Tulamide =) Awesome example, small and to the point. Thumbs up from me   
B
7
Posts: 3
Reputation: 294

Post » Sun Sep 15, 2013 11:24 pm

My pleasure!
Image
B
24
S
8
G
10
Posts: 1,821
Reputation: 8,279

Post » Mon Sep 16, 2013 2:38 am

Ok not checked out tulamide's version yet but I had a go as I like these type of challenges.

The code is broken up into functions which I hoping will make it easier to understand. The code that creates the hex grid can be changed to create any number of rings by changing the hex_ringTOTAL var.

The code for the shuffle only works correctly for hex circle grid with 19 tiles. The shuffle works by creating a table of data.. which after re-reading your post may beyond your requirements. On the upside you can shuffle the board 19 times and a tile will never appear in the same place twice.

Its pretty compact at 46 events and the hex draw is only 16 events anyhows hopefully someone else may find it useful reading this topic

Cap file Link:
https://www.dropbox.com/s/c2894cf0jn7vkbf/hex_grid.capx

Cheers
B
8
S
3
G
1
Posts: 34
Reputation: 1,395


Return to How do I....?

Who is online

Users browsing this forum: No registered users and 18 guests