Start screen

Sorry for the delay in posting this first app, I blew the challenge already! The past few weeks had me very occupied with school work and job hunting, but the hunt is coming to an end and the work is slow for the next week or two, so hopefully the next update will be right on time! I had actually created the app within the week I designated for it, but didn’t get to writing the blog post until now, so maybe that sort of counts as fulfilling AppaWeek :]

For my first weekly iOS app (and my first iOS game), I decided to adapt an old Neopets game called Ice Cream Machine. Since people like games with birds in them, I replaced the Neopets with Neobirds so we have Bird Food Machine. I can taste the ad revenue already!

What It Is

Level 1

The game mechanics are simple enough; the player moves the bird around with their finger and tries to avoid colliding with eggs. Each level you beat causes the eggs to move faster and every fourth level adds another egg to the rows of launched eggs.

Two eggs at a time

What I Learned

I made the game with Apple’s Sprite Kit, which was generally easy to pick up and work with. Some of the challenges I came across, both as a novice to iOS and to game design, were how to handle the player being able to pick up their finger at any time and place it somewhere else on the screen (thereby teleporting the bird instead of dragging it), how to save high scores, and how to actually make the game fun (but I mean who needs fun when you have birds).

To fix the teleporting issue, I though it’d be fun to make the bird “scared” when no touch inputs were detected and have it start drifting around randomly. This behavior serves to discourage players from lifting their fingers, but I didn’t think it was harsh enough. Then, I realized I could just make the bird move relative to the touch gesture’s initial location, rather than have the bird go wherever the finger was. So if the player’s finger is at coordinate (x,y) initially and then moves to coordinate (x+3, y+4), the bird doesn’t necessarily move to (x+3,y+4), it moves to (birdPosition.x+3, birdPosition.y+4). That solved the teleporting issue, but I kept the random drifting in since I thought it was a fun mechanic anyway. Another bonus with this input method is that now the player’s finger doesn’t have to obstruct a key area of their screen, a common problem in touch screen games.

Technically, the hardest part of creating this app was figuring out how to present and control multiple “scenes” throughout the game (the start screen, the game screen, the level transition, and the game over screen). Sprite Kit doesn’t really work nicely with the class I’m used to using for this, which is UIView. That means I don’t have access to the nice features UIView provides, like UIButton, and I ended up having to implement those myself, as well as figure out how to control the SKViews and SKScenes properly.

Typical challenges when making a game like this might include collision detection and handling touch input, but Sprite Kit and iOS’s gesture recognizer take care of most of the difficulty here. Sprite Kit will let you know whenever certain objects collide (given that you defined a hit box around them and an ID to associate with them) by using objective-c’s delegate/protocol system. The programmer tells Sprite Kit it wants to be informed when two objects collide, and Sprite Kit says okay I’ll call a function named “didBeginContact:” when that occurs, so as long as you implement that function you have access to that information and can do whatever you’d like with it. Dealing with touch gestures involves instantiating a gesture recognizer, which gives you access to the coordinates of the touch input as well as information regarding the state of the gesture (gesture beginning, gesture ending, etc) and again you can do whatever you want with that data.

To handle the flow of events in the game, I use Sprite Kit’s “update:” function which is called every frame to grab the current time, then I compute the time since the last update and if it exceeds the spawn time, I send a new row of eggs out.

Making the game fun is a task that could take a while to really nail. Ideally I’d like to add power-ups and a couple more mechanics, but in the spirit of AppaWeek I decided to complete the basic game and move on. I might revisit this game and expand it into a fully realized app one day, but for now it’s in a nice place where it’s fully playable, albeit a little boring.

Final Thoughts

Game over

In just a week of work, I was able to create a basic game from beginning to end using a language I’m just starting to get comfortable with. This fact will hopefully encourage people to stop procrastinating and get started on that project they’ve been thinking about; starting is often the hardest part. If this blog has motivated you, let me know what you’re working on in the comments! I’d love to follow along.

You can check out all of the code for this app in my git repository. If you have a Mac, you can even build and play it for yourself in Xcode’s iOS simulator. If you see anything I could’ve done better, let me know in the comments!

Thanks to Jake Schwarzbaum for creating the bird and egg art!