How can I make a grid of hexagons?

0 favourites
  • 9 posts
From the Asset Store
Snap to visible grid - perfect solution for any game genre
  • 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: dropbox.com/s/bynju9iob9xfaqd/HexCircle.png

  • 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.

  • 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.

  • 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.

  • 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

  • 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) )

  • Thank you Tulamide =) Awesome example, small and to the point. Thumbs up from me   <img src="smileys/smiley10.gif" border="0" align="middle" />

  • My pleasure! <img src="smileys/smiley1.gif" border="0" align="middle" />

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • 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:

    dropbox.com/s/c2894cf0jn7vkbf/hex_grid.capx

    Cheers

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)