What I expected to be easy turned out to be a rats nest, all because I didn’t maintain my diligence when completing verse 1:2. I had no tests for velocities higher than one. I knew it would be a problem when I did it, but it turned out much worse than I anticipated. I ended up scrapping the entire physics class in favour of something closer to real physics. I will be more diligent about not writing any code that isn’t satisfying a unit test, even if it means building out features a bit beyond what the current verse requires.

Verse 1:3

In quite a hurry,
but the ice is treacherous.
The walls are not soft.

Hold shift to run. When running, you will slide around on the ice a bit. If you strike a wall hard enough, you can bounce off of it and take some damage.

Challenge: Physics

Every time I make a run at my own physics implementation I utterly fail to remember any of my vector math, so that absorbed some time as I reacquainted myself with an old friend. Once I got it working, the result was really ugly. This was the time for TDD to shine. This was the first real test of TDD’s vaunted ability to make refactoring easier and more comfortable, and it did just that. I didn’t need to test the actual game until I was done all of the changes, and it worked, which was a nice feeling.

My initial implementation saw the Collider class calculating the forces involved in the collision and then applying the forces to the entities. Once I got this working, I noticed this:

From PhysicalSimulation.as

public function applyForceToEntity(in_force:Point, in_entity:Entity):void
   in_entity.xVelocity += in_force.x;
   in_entity.yVelocity += in_force.y;

From Collider.as

public function applyForceToEntity(in_force:Point, in_entity:Entity):void
   in_entity.xVelocity += in_force.x/in_entity.mass;
   in_entity.yVelocity += in_force.y/in_entity.mass;

Not only were these duplicate code, but at the moment, they were working differently. I rolled up my sleeves and updated the Collider class to just calculate and return the force of the collision instead of actually acting on the objects. The PhysicalSimulation takes care of actually applying the force to the Entities, and now takes mass into account. This involved rewriting most of the unit tests for the Collider class, since my expectations were now based on the returned force rather than inspecting the properties of the entities.

One thing I want to do differently, versus my last Roguelike attempt, is to implement saving very early in development, so that every feature can be developed with game saves as part of the testing. My next goal doesn’t directly imply this should be done, but I will be tackling it as part of the test implementation.

Verse 1:4

Door locked securely
First obstacle encountered
Where did that key go?