100 Hour Game—Days 9, 10 & 11

Hours Remaining: 31

Days 9 & 10

Days 9 & 10 were mostly spent fixing the giant horrible mess that I’d created getting things to work.

Once I had a better understanding of how it all fit together, it was time to make the code more manageable. I also realised I’d made a pretty significant error in how I was handling attaching Actors to Zones.

This issue (the Reattachment Problem) was that Actors would quickly re-attach themselves to a Zone they were previously attached to when touches began. It was all to easy for the SKPhysicsContactDelegate to be called after the player accidentally brushed the Actor they had started touching against the Zone it was just attached to. Incredibly frustrating if you’re playing against a clock.

My first pass involved trying to keep track of which Actors were attached to which Zones, then once touches began, that Actor could not reattach itself to that Zone unless it had moved at least 100 pixels away.

The flaw—obvious in retrospect—was the complex hoops required to remove the Actor’s reference from the Zone after the Actor started moving. At one point, I ended up with the Zone holding on to a reference to the Actor and the Actor holding on to a reference to the last Zone so I could do ugly little things like this:

Nope. Nuh-uh. No, thank you.

As always, stepping away from it for a day helped and I quickly realised that I was using space to manage the Reattachment Problem, when I should have been using time. All I needed was a simple timer that began on touchesBegan(withEvent:) and refused to lock anything to any Zone for either half a second or until touchesEnded(withEvent:) was called, whichever came first.

Simple and easy to understand. A satisfying solution.

The other major thing was tackling that really ugly code for adding ingredients. After trying a dozen different ways, I settled on using a Protocol called Containable that defined the behaviour for adding and dispensing ingredients. It ended up simplifying that horrible mess into this:

Not only is it simpler to understand, it takes advantage of callbacks. This means that I can have ingredients take an arbitrary amount of time to transfer. For example, pouring an espresso into a cup now takes half a second per shot. If the cup is moved before the espresso finishes pouring, it counts as a miss.

Day 11

After a little bit more cleanup, I am now at the stage where I can start making it look better. Steam and coffee particle effects were added first to give some visual feedback on how long the player has to wait before they can move things around.

An animated gif showing my progress on Barista for days 9 and 10
Physics beans!

Scoring is also working—you can see that when the Espresso is delivered to the serving tray, the Single Espresso label disappears, and the score goes up.

In terms of coding, all of the game logic is there, and now it’s just about tweaking various parameters to make it as fun as possible.

The rest of the remaining 31 hours will be spent on design, effects, beta testing, and preparing it for the App Store.

  • Share: