After I spent the last weeks mainly focussed on the level editor for the unnamed project I’m working on with some friends, I found some time to work on my match 3 game today. I did some work on the objects that are supposed to be matched. While I’ve thought about making them something typical for the land one is currently playing, I’ve now decided (mainly because of my inability to create good looking models) to use country flags on spheres. I also implemented the basic game logic. Just a reminder, here is what I had in mind for the levels:
And here is what it looks like in Unity right now:
How did I do it?
Again a lot of it was inspired by a tutorial. This time the Match Three Tutorial Series by Grim Grin Gaming. The biggest changes I made were the simplified exchanging of objects and of course the objects itself. I also changed the way in which neighbors are added to an object. My CheckNeighbors function looks like this:
public void CheckNeighbors(){ neighbors.Clear (); GameObject[] goWithTag = GameObject.FindGameObjectsWithTag("Gem"); for (int i = 0; i < goWithTag.Length; ++i) { float xDist = transform.position.x - goWithTag[i].transform.position.x; float yDist = transform.position.y - goWithTag[i].transform.position.y; if ( ((((-1.2 <= xDist && xDist <= 1.2)) && (yDist < 0.2 && yDist > -0.2)) || (((-1.2 <= yDist && yDist <= 1.2)) && (xDist < 0.2 && xDist > -0.2))) && !(xDist == 0 && yDist == 0)) neighbors.Add(goWithTag[i].GetComponent<Gem>()); } }
The code looks for objects with the tag “Gem” and checks if they are positioned on top, below, left or right of the object. Also the UI is not from the tutorial since some things have changed in Unity since the tutorials where recorded.
Next steps
I’m currently working on win and game over, there will also be some more UI elements. Next up is menu, different levels, eventually sounds and – of course – always small general improvements.