How do I detect shapes in a grid of b&w diamonds?

0 favourites
  • 7 posts
From the Asset Store
Grid - snap to grid
$1 USD
80% off
Snap to visible grid - perfect solution for any game genre
  • How do I detect shapes in a grid of b&w diamonds?

    Imagine a grid of diamonds, say 5x5, on the top of a cube. Each diamond is black or white. I want to be able to detect various arrangements of diamonds. For example, a larger diamond made up of 4 white diamonds or a line of 3 white diamonds diamonds and 1 black diamond. What would be a good way to do this?

  • Try using an array to represent the information on the grid. For example, in a 5x5 array, have white diamonds represented by 1 and black diamonds represented by 2.

    For each specific arrangement you are interested in, use "For each element" to create a set of conditions to check.

    Ex: Line of 3 white diamonds and a black diamond

    Array - For Each XY Element

    Array.CurValue = 1

    Array.At(Array.CurX+1,Array.CurY)=1

    Array.At(Array.CurX+2,Array.CurY)=1

    Array.At(Array.CurX+3,Array.CurY)=2

    You can also use "black" and "white" as a string in the array, but numbers are usually easier to deal with.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Thanks Is there a way to do this without arrays or are arrays far easier than other methods?

  • You might be able to do it by using the object's location, but I can't think of how to pick and compare locations of multiples of the same object off the top of my head.

    Arrays are very useful in storing and manipulating data.

  • I'm giving arrays a go. I can't figure out how to link the 5x5 grid of sprites to the array. Is it based on position? Would this mean an isometric grid would be more difficult than a square grid?

    EDIT: I'm having a go. I may be onto something...

  • Thanks for the help I see what you did there.

    Now, I'm trying to figure out the most efficient way of relaying information from the diamonds to the array and from the array to the diamonds. For example, syncing up a sprite to switch from black to white while the array switches from 1 to 2 and having that trigger from the sprite side or from the array side.

  • Two ways I would consider -

    Have the sprite objects always update to whatever value is in the array at any time. Clean, but might be a little more taxing on the system to update everything every tick. Depends on the scale of your project, this might not even be a concern.

    Or, whenever you have an action to change the array, also add an action to change the respective sprite. Doubles up on actions in your event sheet, but it is the most efficient.

    Regarding isometric grid vs square grid, it is all the same to the array. The isometric grid is a little trickier when positioning your sprites, but that should be all. Each sprite diamond should still be associated with one array cell. If it makes things easier, you can use an pair of instance variables on the sprite object to permanently reference its array position. ex. in DiamondSprite object, add variables Xposition = 1 Yposition = 3 , Then you can use those to look for the data with Array.At(DiamondSprite.Xposition, DiamondSprite.Yposition), which would give you the value in the array at 1,3

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