For today’s changes we have some slight refactoring as well as the change that I wanted to complete yesterday before I ran out of time. Well technically I could have worked on it longer, but as it was I was up rather late and these old bones don’t like that very much any more. Ahh, the vigors of youth, how I miss you.
For video of this in action, I direct you to a tweet I posted:
— Terence Martin (@OdatNurd) December 14, 2016
This builds on the logic put in place yesterday. Once we have detected that all of the gray bricks have finished vanishing, we switch into a mode where all of the balls still in the maze are given one last chance to move. This happens from the bottom up, so that balls will get out of the way of other balls and give them more of a chance to move.
Now that there are two places where a ball is being dropped (manually clicking and this method) the code responsible for setting everything up has been factored out into it’s own method. It also sets a faster ball drop speed than normal, which makes the whole thing go a lot faster. I think there could still be some tweaking done to this mechanism.
As implemented, after each ball gets a chance to move, it is removed. This opens up the possibility for other balls to move more than they would (which includes that ball at the top that was blocked from making a move at all). I would have to play the source game again to see exactly how it handles this, but this does not seem like how it works there.
Rather than moving everything and vanishing it, we could vanish away all of the balls that we know will never get a chance to move (they were not blocked by a gray brick), just vanish away balls that never got a chance to move at all, or move all possible balls like we do now, but don’t vanish them when they’re done so they get in the way. I’m not sure which method the source game uses and I’m also not sure which of those seems more strategic to me. I can see good and bad points for all options
Tomorrow will mark the second week of Devember being over, but not the half way point. So I’m thinking that I will focus tomorrow on some last bits of code cleanup. For expediency in development everything is being clustered into the Maze entity, but it’s getting a little too big for its britches, as it were. It is an unweildy, long file and getting tricky to navigate.
Some of the logic contained in it should be pushed out to the other various entities or put into the scene code instead of directly into the entity. I’m also extremely uncomfortable with all of the uses of instanceof to select things (except where it’s used in debug only code) because that just screams poor design to me.
Another big reason for this is that currently the logic for dropping the ball is stored within the Maze entity itself and modifies the actual maze and all entities within it; for example when the ball encounters an arrow, it changes directions. In order to use this logic for AI purposes this needs to be changed so that the code can be invoked without making lasting changes.
If all goes according to plan, the progress update for tomorrow will be that everything still works the way it does now, but is much better structured for others to understand. Then we’ll be in a good place to add in Player entities for the player and computer, some scoring, and we’ll have ourselves a little game.