Let there be score! Also a couple of other changes.
Since it is the bottle that does the matching and dropping, it needs to communicate to the bottle every time a match happens, as it was only notifying when all matching was complete to signal the next capsule. I did a bunch of pondering on the complexities of this only to discover that it’s actually not complex at all.
In a classic case of over-thinking the simple, I was concerned about how to signal multiple independent matches (i.e. if there was a non-intersecting horizontal and vertical match) as well as how to detect when multiple matches DO intersect, so they can be treated as one. You would almost think that I’ve never played the original Dr. Mario before or something.
The natural state of the game is “not enough matches”, and the only thing that changes it is when a capsule drops and stops somewhere. If there are any matches, they have to intersect with that capsule; if not, they were pre-existing matches. I knew this when I wrote the matching code because realistically you only need to search a certain distance away from the capsule that just dropped to know if there are any matches, which I didn’t care about at the time.
It is possible for the capsule to generate a match for two colors, which in a technical sense is two distinct matches based on color, but even in the original game this is treated as one big match with the total number of viruses in it, so this distinction is not really interesting.
Similarly, due to the way the viruses are laid out in the bottle, it’s not possible to match more than 6 different viruses with one drop because the proximity of like colors is limited, which I hadn’t actually considered.
The bottle now has some values that it stores and alters for each drop/match step that count how many viruses were matched during each match (which it was already doing to drop the virus count anyway), plus how many consecutive times matches have been found before there is nothing else to drop and no more matches to find.
These get passed back to the game scene so that it can calculate score. This is not fully fleshed out yet while I reel from the knowledge that you don’t actually get bonus points for a cascade in Dr. Mario.
Seriously, have I ever played this before?
Actually what happens is that there is an increasing value for the number of viruses included in a match; 200 for the first, 400 for the second, 800 for the third, and so on (which is not actually true because the scores are based on the low/med/high speed you picked). The scores are cumulative (viruses are counted more than once).
For example, the first virus counts for 200, the second counts for 200 + 400, the third counts for 200 + 400 + 800. Since it’s pretty rare to get more than a couple of viruses in a single drop without a cascade getting you more, it only appears that there is a cascade bonus.
As such I have this cascade count that’s not actually needed, but I have decided that I will use it as a multiplier in the score anyway.
The only other change made was to controlled dropping. The down arrow now drops the capsule by one segment instead of as far as it can. Since our new input handling resets the key pressed state, you can rapidly tap the button to drop a few spaces, or press and wait for key repeat to kick in to start dropping faster. This feels pretty natural and makes things less annoying.
Next up will be a more fully fleshed out scoring mechanism.