Here we are at Day 15, I’m a little tired from getting to bed late last night, but today’s change has been completed! We now have a player entity that walks back and forth over the top of the maze, and can push the ball into the maze:
This change adds in a new Player entity which can idle in any of three directions, rotate from any facing to any other facing, and push in all three directions (although currently only a downward push does anything). Although ts-game-engine supports rotating entities, I prepared the sprite sheet to have the same animations as the arrow rotations do, so this is actually done via a sprite sheet instead.
The longest part of the operation was setting up the animations, since there needs to be so many of them, one for each possible facing change combination. That is very much a good reason to just rotate the actual entity, but I’m going to pretend that since the game is a clone of an old DOS game, I did it this way to be retro and not because I never thought of it until after I had prepared the sprites.
An additional bit of code makes sure that while an animated transition from one state to another is currently in progress, a new change can’t be made. So for example if we’re already rotating from left to right, we can’t swap to rotating down, or push the ball. This is a situation in which actual entity rotation could be safely interrupted without causing any visual glitches.
Most of the magic seen here is right inside of the Player entity. At startup we give it a reference position that tells it where on the screen it would need to render to be above the first column of the maze (which we get by asking the Maze where it is). We then use the built in map position point to track what column the entity is in, getting it to update it’s X location on the screen when the value changes. This also means that when a push is triggered we automatically know what column in the maze the push happened in.
From here it’s a simple matter to have the arrow keys either rotate to face a direction or walk in a direction (by updating the position) as needed. I have appropriated the space bar for the push mechanism, so the debug toggle key has been swapped to F12.
Tomorrow I plan on enhancing the new Player entity a bit (it currently does not support the comptuer sprite) and adding in logic needed to have two sets of balls visible in the top row at once, which are toggled between as each player makes their move. Assuming that doesn’t take too much time I’ll continue on with the state machine code, since we’re rapidly approaching the point at which we need to carefully keep track of what’s going on.