Search Unity

Scripting a Match Mechanic

Discussion in 'Scripting' started by JacksonTheXtremeGamer, Jul 17, 2019.

  1. JacksonTheXtremeGamer

    JacksonTheXtremeGamer

    Joined:
    Jun 15, 2019
    Posts:
    108
    I plan to make a game that matches 3 or more of the same color, horizontally and vertically. I have the grid and sprite scripting taken care of, but how should I approach this in a basic form?
     
  2. palex-nx

    palex-nx

    Joined:
    Jul 23, 2018
    Posts:
    1,748
    In basic, you create either 2d array or array of arrays and fill it with items representing the game field. After every move you iterate through that array and check matches for every item if it has enough equal items in neighbor cells. If so, you destroy that item. Repeat this process until there's no matches. Then let player make turn again.
     
  3. JacksonTheXtremeGamer

    JacksonTheXtremeGamer

    Joined:
    Jun 15, 2019
    Posts:
    108
    Actually this is different, and I failed to mention this, but it’s like Tetris Attack and Columns. But all in all I need an array, right? Do I use something like ‘ifMatched()’ and ‘checkMatch()’?
     
  4. palex-nx

    palex-nx

    Joined:
    Jul 23, 2018
    Posts:
    1,748
    The difference is very little. In case of tetris, you make turn (move figure down, possible rotate it) programmatically, and everything else remains the same.
     
  5. JacksonTheXtremeGamer

    JacksonTheXtremeGamer

    Joined:
    Jun 15, 2019
    Posts:
    108
    Got it. And the array still checks for a match. Well give me a bit, and I’ll pull up the script on my grid class. Show you what I have so far. Maybe we can work out a solution.