How to match 3 game source code?

Match 3 video game source code is quite well-known those days. From the original Bejeweled to Candy Crush Saga and even Evolve: Hunters Quest, many video games are primarily based totally at the in match three mechanism at the same time as giving specialized bonuses to the user. Such an instance is giving a unique object if it fits extra than 3 items. If the user creates an in match that consists of this bonus, then the entire row or column is destroyed.

Let’s begin with a screenshot of the sport strolling with-inside the Unity Editor

Only outside belongings were the usage of a few candy graphics (Public Domain, located on Open Game Art here) and a totally cool sound (located on Free Sound here) to construct our sport. Users can drag (in and try to change) one candy both horizontally or vertically. When the change happens, the sport exams for a match. As quickly as a vertical or horizontal match of 3 (or extra!) is encountered, the matched candies disappear. Remaining candies collapse, new candies get created to update them which collapse, too (believe gravity appearing upon them).

The sport exams if some other in Match 3 game source code is encountered (with none user intervention). If this happens, the matched ones disappear again, last candies collapse, new candies fall and so forth and so forth. t to hold the sport.


Let’s dive into the code! As in our preceding weblog posts, we’ll see the code document through document.

Enums

Our sport carries enumerations. The Bonus Type carries information approximately the bonus that a form/candy can carry. It has been described with the Flags characteristic to permit more than one values with-inside the enumeration (take a look at here for a pleasant article). The elegance Bonus Type Utilities carries best one method, to decide whether or not an enumeration variable carries the desired bonus type. Finally, the Game State enum carries the 3 states of our sport.

Constants

Contains a few beneficial consistent and self-explainable variables for our sport, concerning animation duration, rating, rows and columns for the array on the way to include our candy and extra.

Match

The match elegance could be used to maintain info for every user candy. Each candy Game Object at the display screen may have a match component, so every match example is a Mono Behavior. It carries information approximately ability bonus(es), the Type of the match (in our case, the candy colour) the Column and Row that the candy is placed, a constructor that initialises the bonus enumeration and a way that compares the contemporary match with some other one, through evaluating its Type. We use a Row and Column seeing that we’ll have a dimensional array host our candies.

Utilities

This static elegance carries a few static helper methods.

The Animate Potential Matches co routine takes a listing of Game Objects and modifies their opacity (from 1.zero to zero.three after which to 1.zero) the usage of a consistent time delay. This is to animate the ability fits which might be given as a touch to the user.

This elegance carries facts about candy that are approximately to be moved after a collapse/new candy advent event. It carries

– a non-public listing with all of the candy to be moved

– an asset that returns the Distinct (i.e. unique) end result of the above listing. This is vital in case the inner listing carries the equal form twice

– a way to feature a brand new candy to the non-public listing

– a constructor that initializes the non-public listing

MatchesInfo

The MatchesInfo elegance carries beneficial facts approximately the candies that had been fitted (both a in match of 3 or extra). It seems lost just like the earlier than cited Altered Candy Info elegance (we may want to feasible use a few inheritance here) with the addition of the Bonus Type facts for the complete in match.

Debugging

During the development of the sport, there has been the want to check particular scenarios. E.g. Are we able to check more than one collapse at the same time? Can we without difficulty get a match of 5 to peer the set of rules’s behavior? As you saw, the set of rules is quite random so we couldn’t without difficulty check such scenarios. This is the cause we advanced a manner to load custom tiers. Take a study of the extent.txt document, located withinside the Resources folder.

Thanks for analyzing this! Hope it’s useful to your subsequent sport. As always, you may try the sport here and discover the supply code here. Contact Us Now!

Comments

Popular posts from this blog

How To Develop A Good Java Slot Machine Source Code

How to Create a Rummy Game That Keeps Players Coming Back for More

Bingo Software Uncovered: Key Features, Benefits, and Business Opportunities