The Cocoa port is done - can we make this work on the iPhone? Absolutely. Instead of Quartz, I'll use GameKit and the OpenGL template. There is no reason why I can't use Quartz, but using GameKit and the graphics hardware will give me the following advantages:
I'll get rotate "for free"
I can optimize the 1-bit conversion by using a texture
I can get filtered scaling "for free" (very necessary because the game will be absolutely tiny on the phone at 1:1)
I'm using Xcode 7.2 and targeting iOS 9. The steps are correct as of this writing. The templates and dialogs seem to change with every version of Xcode, so if they aren't correct for your version of Xcode, good luck! Just try to modify the steps using common sense.
When you use the templates in Xcode, they make a complete running application, and the developer has to modify the template. So the setup for this project will go fast.
Launch Xcode and start a new project with File -> New Project.
Select iOS and Application, then choose the Game from the pane on the right.
In the options sheet, select Devices: iPhone, Language Objective-C, and Game Technology OpenGL ES. Give it a name (I'm calling mine PhoneInvaders), and click the Next button.
Choose a save location.
Now if you run the project at this point (cmd-R or from the menu, choose Product->Run), you will see a fully working OpenGL ES application. As of this writing, the code in the template displays a couple of rotating cubes with lighting. The GameViewController.m file will have to be modified to replace drawing the cubes with the drawing of our game. A lot of this file will go away, but not all of it.
I'll go ahead and make the machine object. Create a new NSObject object to represent the Space Invaders machine.
In the iOS section, select iOS, then choose Cocoa Touch Class and click Next.
In the options sheet, name the class - I called mine "SpaceInvadersMachine". In the Subclass of field, put NSObject. For Language, Objective-C. Click Next.
Choose a save location.
I'll have to put the ROM files and the sounds in the project. I dragged in the Invaders.[e-h] ROM files and [0-9].wav sound files. When I drag them in, make sure that "Add to Project" is not selected in the sheet. If they are automatically added, the naming of the invaders ROM files makes Xcode think they are source files.
In Finder, select the invaders.e, .f, .g, and .h ROM files and the 10 sound wav files into the project
Drag them into the Xcode project making sure to put them in the "Supporting Files" folder
In the sheet that drops down, check "Copy items if needed", and make sure "Add to Targets" is not selected.
Click on the PhoneInvaders project in the project browser
Click on the PhoneInvaders target
Click on Build Phases
Disclose Copy Bundle Resources
Add all the invaders rom and sound files to the Copy phase
Choose Product->Run to try it out one more time in the iPhone simulator. You should still see the rotating cube animation.
That was super easy because the Xcode template is very close to what I need. In the next section, I'll add in the CPU emulator and the machine code.← Prev: cocoa-port-pt-7---threading Next: iphone-port-pt-2---machine-object →