Cocoa Game Programming Workshop

Do you have $10 and the desire to quickly get up to speed on game programming and Apple’s Cocoa framework? I did.

I recently finished a book on Objective-C and Cocoa programming that gave me a pretty good introduction and base for developing applications on the Mac. Though the book was helpful, I still felt lost when it game to taking my recently acquired knowledge and applying it to games.

Enter Cocoa Game Programming Workshop, by David Hill from SpiderWorks.

This $9.95 eBook walks you through developing your own Gauntlet clone.

Well okay, not quite the Gauntlet I remember but certainly a big step forward in putting together a simple tile-based hack-n-slash type game.

The finished game isn’t really the goal though. What I got out of it is a solid base for moving forward with my own Mac game project. Hill, fills in the pieces I was missing and gave me just enough of a start that I feel like I can move forward.

Some of the helpful things I picked up that will definitely help moving forward:

  • Subclassing a Cocoa Custom View to serve as the main game view
  • Displaying images on the screen using NSImage objects
  • Reading and Writing XML documents
  • Accessing resource files (graphics and sounds) included inside the application bundle
  • Setting up a timer with callback functions (selectors)
  • The Cocoa sound API and using NSSound objects
  • Handling Keyboard input
  • Refactoring Objective-C

The book really is geared towards a beginning game programmer. I imagine someone who knows Cocoa and Objective-C to even an intermediate level could probably put this simple game together. But for someone like me, who has no real prior experience with Apple’s development tools, this seemed like the perfect introduction.

There’s enough information to get a game up and running without getting bogged down in too much of Cocoa’s details. Now, I can get started and pick up what I need as I need it.

Backups Revisited

After more than two months running my backup system, it’s time to reevaluate the results.

I’ve been running Dantz Retrospect to backup all my files to one external firewire 250GB dual drive RAID. Up to this past week, everything seemed to be going smoothly.

Last Friday, Retrospect reported an error: “Disk Volume Full”. How can that be? I’m backing up data from two drives to this RAID that add up to approximately 55 GB. So I started digging around and I discovered a few problems.

Retrospect archives changes, deleted files, etc. Over time (not a long time), this space was used up. So, I looked into cleaning up the archives and filtering out files I didn’t care about. This turned into a pretty complicated procedure. In other words, I failed at figuring out how to do this.

Additionally, I discovered that one of the drives in the mirrored RAID and become corrupt. I would never have seen this, if the disks had not filled up and I not checked them in Apple’s Disk Utility application. Thankfully, it was easy to fix by simply having Disk Utility rebuild the corrupt drive. It took about three hours, but no data was lost and it was a 1-click procedure.

What did I take away from this? Two things, I need new backup software and being very paranoid, I need another backup RAID.

I decided upon ChronoSync from econ Technologies after some testing of several products. I chose ChronoSync primarily because of the interface. It was intuitive, easy to use, and had built-in email notifications of backup status with summary and errors (which Retrospect seems to lack). It also provides advanced file filters and update triggers that allow for a pretty customized backup solution. On top of that it can act as a synchronization tool between my G5 PowerMac and my PowerBook.

Now with two distinct external RAID systems, I can divide up my backups onto two targets so if one goes, I don’t lose everything. It also doubles my available disk space. Hopefully, this will last me a while.

More on Learning Cocoa

As I stated in yesterday’s article, Learning Cocoa, I’m struggling with the syntax of Objective-C. It’s not that I don’t understand it, it’s just completely different looking than C-derived syntax like Java, C++, C#, and php (the languages I use in “real-life”).

To add to the problem, I’m struggling with style. What I mean here is how to layout the code as I write it. What is the best way to use blank space and comments to full effect? How to name my functions so that they are easy to read and type, etc.

I’ve been following Wil Shipley’s site as he critique’s people’s code for style and best practices. This has been pretty helpful, but not quite the same as having a mentor to look over your shoulder.

So far, the best hope I’ve had is deeming insight from the books I’m reading and any example code I find. Short of that, I’ve been experimenting as I write my code.

For example, I have an initialize method on my Player class. I’ve played with two ways of calling the method. Which format looks easier to read to you?

This may seem like a small thing, but what happens when you have pages upon pages of code? Does your code get messy and hard to read? Right now I’m leaning towards the multi-line style, but Wil Shipley has been recommending everything on one line. Maybe as I get used to looking at Objective-C, I’ll agree with him.

Learning Cocoa

I’ve been spending a considerable amount of time trying to learn Objective-C and especially Cocoa.

After some searching around, I found tons of references to Cocoa Programming for Mac OS X by Aaron Hillegass. It’s a good tool for learning how to build applications with Apple’s development tools and frameworks, though it is missing some of the newer technologies.

I made it through the book and feel a bit better about what is going on, but I never really feel comfortable with a language or framework until I use it in an actual project. I’ve learned a ton of programming languages and frameworks through my years as a professional developer, but I think Objective-C and Cocoa are the hardest so far for me.

The first thing that I struggled with is the strange looking syntax that Objective-C uses to call methods of a class.

For example to call the setHealth method of an instantiated player object and pass in the value of 1, I would do the following:

[player setColumn: 1];

What really gets hairy and hard to read when you are not used to this syntax is when passing in multiple arguments to a method:

[player setPositionAtColumn: 1 andRow: 1];

And just to make it even harder to read, let’s move the player over one column:

[player setPositionAtColumn: [player column] + 1 andRow: 1];

It’s probably just a matter of getting used to the syntax, but boy does it really look and feel foreign to me. Though, I must admit, I really like the way that each method parameter is specified outright with a part of the method name. If you compare the next two method calls, which is more clear on what is happening?

[player initAtColumn: 1 andRow: 1 withHealth: 100 andScore: 0];

player.init(1, 1, 100, 0);

On top of the extremely foreign syntax, the Cocoa framework is huge! Finding out how to do things is an adventure sometimes. It’s one thing to have a book walk you through step-by-step, but when it comes time to actually program something from scratch while looking at the blank screen in the Xcode editor, I feel a bit lost.

Deimios Rising Game Design

I’ve been hunting down articles covering game engine design that last few days. Primarily, to find out what tools and approaches these game developers have used successfully.

Eventually, I found this article on the development and design of the game engine behind the Mac game Deimios Rising. There are some really great ideas and the developers go into some pretty nice details as to how they got their 3d looking backgrounds and sprites in their 2d game without using a tile-based game engine.

The approach taken in this game is similar to what I have in mind for my game design. Though, I’ve been planning something much more simple, their method seems to have worked very nicely to produce a solid, good looking, fun game.

Open-Source Shareware Registration Framework

Are you looking for a way to setup a registration system for your shareware software?

There are several commercial products out there, but Aquatic has released a free (donations accepted) open-source framework: AquaticPrime. It supports both Cocoa and Carbon integration and also includes a php-based library for use on your online e-commerce shopping cart system.

AquaticPrime utilizes the strong one-way encryption algorithm, RSA to provide for a powerful way of locking down your product.

Aquatic also has simple Developer Documentation available to help you along your way when integrating the framework into your product.

Catching Up

I forget how fast the world moves these days. So much can happen in only a few days.

I remember as a kid, I could waste away an entire summer vacation without the sense that I missed a thing. When I returned to school the next fall, life continued just as it left off the previous school year. Yes, everyone was a bit more tanned, maybe a bit taller, and probably had some summer vacation stories, but essentially nothing really changed and I didn’t miss anything important.

This month has been crazy for me. A six month long project for a client of mine came to an end, but required last minute changes and testing before deployment. After many days of long hours and tedious regression testing, I’m done with the project. Now I need to catch up with the world that passed me by during the final stretch.

The great thing is now I have some time off to work on my game project. Unfortunately, I have a ton of real-life things that need to get taken care of during my “bench” time. Hopefully, I can balance everything efficiently enough to make progress on everything.

In an effort to catch up with everyone else, humor me while I give my thoughts on some of what I’ve missed.

Apple News

  • iPod Nano: Awesome! I want one, but already have a 3rd gen iPod, so can’t justify the purchase.
  • ROKR iTunes Phone: Huh? What happened to this train wreck of inustrial design? I guess I understand the idea behind this convergence product, but given all the delays, I expected something a bit more… cool, attractive, slick, something.
  • XServe RAID: Wow, I wish I had the need and the budget. My little external firewire RAID will have to do for now.
  • iTunes 5: Hmmm… I’m not sure what to think on this one. I like the move away from the very heavy look of Brushed Metal to the new Platinum look, but I don’t really like the new trend of the sky blue side bar that iTunes and are pushing. Does anyone else think this looks a bit… Windows-esque? And what’s up with those crappy not quite round corners?
  • Apple Stock: Good stuff, I wish I knew when to take my profits.

The Adventures of El Ballo

Inside Mac Games has published an interview with ProRattaFactor, the developers of a new Mac game called The Adventures of El Ballo, soon to be released by Ambrosia. I was aware of the project before, but not in any detail. It seems like a fascinating game with a unique story.

What really got me interested though is their development log. Cudos to Ambrosia and ProRattaFactor for this gem. It’s a great read filled with an enourmous amount of information. The developers really allow us to follow along in every detail of development.

Ivan Milles, the programmer, reveals the secrets behind the game engine design and its use of cell-based animation instead of the tradional tile-based approach for side-scrollers. There are tons of screen captures showing game graphics, game play, and even some interesting bugs.

Casey Gatti, designer, artist and owner of ProRattaFactor, reveals his work on the graphics and design side as well. We get a look at the level designer, his work flow, and a hint at what tools he uses to produce his art and the cell-based animation that gives this game it’s unique and fun look.

Not only a great learning experience for interested readers, but a great marketing tool. It worked on me, I plan on checking out this game when it’s released.

Change of Plans

I’ve been working on the design of my first game for some time now, slowly ticking away tasks on my project plan.

The goal of the game design was to outline a simple game that would also be realistic to complete by the end of this year.

Several revisions into the draft of my design document, I realized something. I don’t want to play this game. I’ve been concentrating so much on trying to keep it simple and within a sane realistic limit with respect to budget and time that I forgot that it needs to be fun and interesting too. I can’t just approach this as a task to complete and get out of the way, the actual game needs to be something that people will want to play.

I selected the game idea out of many because I felt I could tackle it technically and within the budget I alloted myself. I figured it was more important to complete something, anything.

I’m now taking a step back and rethinking my choices. I need to work on a game that fits the budget and is fun. Duh!

Sometimes I get so focussed on the task at hand, I forget about the big picture. Back to the drawing board.