Renoki: Making An Android Game (part 5)

I worked a little bit today. Added hammer swing animation and logic to handle hitting monsters.

And yes, the hammer swings will queue up if you hit before the previous swing animation is done. It’s a simple queue that accepts up to 3 hits. After that, it just disregards future touches until the queue frees up a space. Hitting pause will always enter into the queue.

At first I thought I was going to need some synchronization because the hammer hits are independent of all the gameboard logic. Then I realized that instead of making the hammer swings asynchronous and needing locks, I can just make the hammers occur on the game clock.

Basically when you tap, you insert the location into the hit queue. On the update part of the game loop, you first check whether a swinging flag is true (animation already going). If not, then you remove from the queue and do a hit on that location and set swinging flag to 1. In the draw part of the game loop, you draw as long as the swinging flag is true. The only synchronization I need is around the queue.

Share Your Thoughts

Leave a Reply