Almost playable prototype

For today’s foray into game development in TypeScript, we have some changes that almost make Rx a playable game; all that’s missing is, you know, the ability for the player  to actually play it. As you can read in the commit log in the repository, today was mostly about code refactoring with some new features added, including a crude level and virus count using a hand rolled font.

I made the bottle aware of the number of viruses that it contains; when it is emptied it has 0, when it adds a virus it adds one, and every time it converts a VIRUS segment into a MATCHED segment, it decrements the count. Additionally, every time you modify the contents of the bottle with the debugging tools, it recounts the number of viruses to make sure that it’s correct.

An important visual element in the original Dr. Mario is that as the viruses are populating into the bottle at the start of the level. Of course the easiest way to do that is to have the loop that inserts viruses into the bottle be driven by the update loop, so that some number of viruses can be inserted in every frame update.

Currently this is a hard coded value designed to make it take about 2 seconds or so for an entire virus load to insert into the bottle, based on the maximum number of viruses allowed (currently 84 at the highest level). Since the engine is running at 30 updates per second, this requires fractional update timing so that some updates insert more than one virus in order to keep the time consistent. I think the speed should be ramped up so that on the lower levels you still get a bit of a satisfying view of the viruses appearing even when there are only a few, but that’s a polish kind of thing.

I shifted the loop that populates the bottle out of the bottle entity and into the game scene, although that was not completely necessary. I made a judgement call that this is the sort of thing that should be driven by the scene and not by the entity itself.

Lastly, although it is the bottle that knows how to find matches and perform drops, it still needs to communicate this sort of thing back to the game scene, lest this single entity be responsible for all of the logic in the game (this is also a factor in why I decided to strip the insertion control out to the scene as well). To this end the bottle gets a reference to its scene when it is created and can invoke callbacks as needed.

Currently there is only one callback; when the last virus is matched and the matches vanish, the scene is told about it. Currently this is handled by immediately starting the next level.

Viruses in the bottle are counted; also virus pop in

Viruses in the bottle are counted; also virus pop in

This mechanism will be used to communicate matches and combos back to the game scene so that it knows how to tally score.

My next plan is to implement actual capsule dropping; once that part is done, the prototype will actually be playable.