I have a prototype started for a simple game using Objective-C and Cocoa. It’s been slow going, but I feel like I’m finally getting somewhere. I worked on it on and off while flying around the country the past couple of weeks on vacation (which helps explain the recent lack of updates to this site).
Okay, so it doesn’t look like much, but it’s a start. Have to start someplace right?
Mostly, what I’m getting out of this is a deeper understanding of Mac game programming in Objective-C and Cocoa.
So far nothing really happens visually except that the player gets drawn to the screen. But the window accepts keyboard input and determines what key(s) were pressed and has the structure ready to send commands to various game objects to tell them what to do: move, shoot, etc.
In order to handle this basic functionality, I put together the following class hierarchy:
OLGameView is a subclass of
NSView and handles the display of the game state. It in turn calls game objects to draw themselves inside a provided
NSRect object via the
drawInRect:(NSRect)rect method. Object movement is handled by the
keyUp:(NSEvent)theEvent methods of the
OLGameView class which then calls the
moveInDirection:(int)direction method of the
The next step is to add an
NSTimer instance that will handle the refreshing of the window that will create the game animation.