Skip to main content

Match-3

New demo in 'Oddities' folder: Match

  • Implements the basic Match-3 mechanic using tiles as the tokens.
  • Token movement done by Tweening the tile sprites then moving the tiles.
  • Not a complete game, just the mechanic.

The Tile asset used for this demo is called "MatchTile" and is merely a simple wrapper around a TpSlideShow.

The TpInputActionToTile component handles the tile swapping and issues a callback to the GameLogic component.

GameLogic.cs comprises the entirety of the 'game' via a simple state machine, and handles the 'swapping' callback here:

ActionToTileOnOnSwipe(TpActionToTile controller, TilePlusBase t1, TilePlusBase t2, Awaitable<bool>? task)

This callback provides the controller instance, the two swapped tiles, and an Awaitable that completes when the swap is complete. Hence, the callback just waits for the swap to complete and then changes the state machine's state from Idle to PostSwap.

Let's discuss these states for a minute:

public enum ProcessingState
{
    /// <summary>
    /// During startup, clears and refills the array
    /// </summary>
    FirstPass,
    /// <summary>
    /// No user input and no match processing
    /// </summary>
    Idle,
    /// <summary>
    /// tokens have been swapped
    /// </summary>
    PostSwap,
    /// <summary>
    /// tokens are being removed
    /// </summary>
    Removal,
    /// <summary>
    /// Array needs refilling
    /// </summary>
    NeedsFill,
    /// <summary>
    /// Array IS refilling
    /// </summary>
    Filling,
    /// <summary>
    /// Array has just completed refill
    /// </summary>
    PostFill,
    /// <summary>
    /// Swapped tokens don't create a match: unswap them
    /// </summary>
    UnSwap,

}

Understanding the simple state machine is left as an exercise for the reader, but put simply, the state machine checks for matches after a swap, removes any matched tokens or unswaps the original tokens if no match is found.

Then it refills the empty areas and repeately looks for matches, removes matches and refills until there are no more matches.

It's not a complete match 3 game.