August’s theme was SLOT MACHINE, and I was ready to leave this as it is, and add it to the list of ‘I won’t do anything to this’. But I had some trouble with my other project (namely optimization) so just for fun I sketched up some ideas for a slot machine. I thought of a simple slot machine. I thought one with an autobattler type side view, where you roll out powerups, weapons, enemies and bosses. Even a sloth machine, which would have been really slow, and you would have only a couple of minutes to play, until the sloth’s saliva hits a button, and the machine dies in a shower of sparks. But then I remembered I always wanted to try some match three mechanics. Regarding once I made the game called Ninja Tetris (where you play a beat them up game, but also try to kill tetroids so they form full lines for points) the title of this article starts to make sense. Yes, I made a sloth machine, where you try to match up gems of the same color. It’s a concept that wouldn’t work on a mechanical slot machine, but hey, don’t question magic.
Did I have a lot of problems? Yes. Did I manage to overcome all the challenges? I hope so. The game certainly works, and I think it’s fun, though there are times when the game basically plays itself, and the satisfaction of that can quickly dwindle. (EDIT: I had some extra problems and errors that allowed the game score up for intersecting matches. I fexed that, so I am alsmot certain I overcame all the challenges. :P) So I draw a 5×5 grid, an arm, arrows, and a display. Quickly made 5 gems, and started to think about and code the mechanics. The idea is: the player pulls the arm, gems start to fall, and after everything settles, the player can randomly roll every row and column once per arm pull. So there is a big luck factor, but also you can strategize what to roll first, as you can calculate your chances to match up something. Pressing the arrows, the game randomly rolls the gems 1-4 positions, so you cannot roll it back to its original position. Take a look at the picture below, and see: if there is two of the same gems (the purple amethyst) in a column, rolling it next to two of the same gems, you have more chance to land a three of a kind, than if you try to roll the column and try to match the green emerald, or roll the row and try to get the red ruby. Of course in the end it still distilles down to luck.
EDIT: after watching the gameplay video by LordOvLoot I realized how hard it must be to understand every mechanic in the game, so I’ve decided to change the how to play section on the left side of the screen. I coded a little, and I made the relevant lines of rules highlighted. So, when the player starts the game, only the “Pull arm cost: 20c” is highlighted. After pulling the arm, this rule will be dark, and other rules are highlighted, and so on. I also added a smaller counter under the score, which shows the player the target score to get another 10c. Hopefully these changes make the game much more fun.
But, to elevate the strategy, I integrated a reduct-rewind system, so if you make a match, the same colored lamp lights up. If you make a match with the same color, the lamp turns off. The lit gems won’t participate in the next turn (arm pull), and you can make incredible matches. So yes, first I had only one column of lamps for the gems, but I changed it near the end of the development to two, as the game was too easy. Two is better, but the game is still not too hard to play. 🙂 So the new system lights up one lamp for one match, the other one for another match, and turns both off for a third match. (EDIT: I added miniature gems flying towards the lamps to make it clear – more clear at least than without this – that matching gems light up and turn off the lamps.) Any gems that have two lit lamps, won’t participate in the next turn. Should you manage to light all lamps, that is worth 20 credits (one arm pull costs 20). The big win of the game, if you manage to light two lamps for 4 gems. Then only one gem will fall, instantly giving a big load of points. I also mention it here, that it may seem, that the blinking of lamps don’t react to matches you see. It is because all matches are searched under 1 frame, and should more matches are found, the lamps change under 1 frame. Of course it could be that I am wrong and that part of the code is just rubbish, but hey, it’s still fun, and it’s a prototype.
For the scoring I used numbers from the Fibonacci sequence. First, the number was multiplied by the number of gems a match gave, but again, it’s not that hard to make big wins, so I reduced the number to the original values. I wrote the names of the possible matches down. Testplays prove that there are matches probably nobody will see as having those would be highly improbable. (EDIT: I changed the scoring system after I fixed the match searching function, so instead of the Fibonacci sequence I just used 10 per gem for 3 of a kind, 20 per gem for 4 of a kind etc. I made small flying texts, to show the score per match on the board. I also write out the reducted combo on the top display, as maybe the sound cue not enough.)
I tried my best to move around the gems purely from code, but as that didn’t work, I made some conveyor belt objects and those move the gems when the arrows are pressed. So there are times when more than 25 gems are on the board, and after everything is settled, the excess gems are destroyed (no match searching, no points), as the last has to come in the first position at the same time. I also had to put down objects on every grid, those get the number (color) and ID of the gems currently taking that position. I use a global 2D array / matrix for the grid and for the reducted gems, arrays for the gem generators. I also tried to put everything together in sequences, but in the end I didn’t utilize that, and used objects wherever I had to access variable definitions.
The match search function was really hard to make. I also ran into it at least three times until I got it right. (EDIT: four times… I just imagined what present me would tell myself two days ago: “Got it right… how’s that worked out kid?” “Kid? You’re only two days older than me!”) I even tried to search for some code, but couldn’t find anything. I asked a coder colleague, and I got some advice, that gave me an idea how to tackle this problem. And finally, I managed to write a function, where your input is the width and height of the match you’re searching for, and the score it should give. It runs through four embedded for cycles, and manages everything if a match is found. For the 13 different matches I have to run this function 22 times whenever the gems settle down (as, for example, a three of a kind can be horizontal and vertical). It seems a lot, and probably could be optimized, but it’s for one frame only and for this prototype it’s OK. I usually use 60 FPS for my games, but for this I used 120, to speed up the gems’ movement, and the calculations.
I bought another sound and music pack and I found just the right sounds for this project. One of Game Dev Market’s soundguy Fuse Hive made some 8 bit style GUI sounds, and those (with small modifications) fit the game perfectly. I also decided to not use music for this one. Should anybody play with it, even just enjoy the slot machine sounds, or listen to his/her preferred music. I also recorded some announcer voice lines (Three of a kind etc…), but in the end I didn’t use them, as I felt it was too much.
All in all, it was hard, but it was worth my time. Sometimes I still feel I cannot code properly, I feel the systems I make cannot work together nicely and I resort to do workarounds to have a satisfactory outcome. Well, maybe someday. The result is still something I can be proud of, it turned out to be a good little prototype. 🙂