Trial and Error - the best way to learn

November 20th, 2008

There are countless ways to learn how to code. You can hire a private tutor, sign up for classes, buy a book, look at example code, or shutup, buckle down, and teach yourself.

Whoah, cmon, be nice you say. Alright, let’s back up a little.

When I say “learn how to code,” I don’t just mean learning the fundamentals, like top-down design or the basics of object-oriented programming or the waterfall method or anything like that. Those are intangible concepts; it’s best to have them explained to you by an expert. No, I’m talking about the nitty-gritty of coding: about strange and random linker errors, about poorly (if at all) documented frameworks, about why the hell the CSS dropdowns don’t work in IE when I’ve removed all selectors and the li elements are not links.

We’ve all been there. We’ve all pulled our hair out over stupid problems that are completely the computer’s fault except for that one keyword we misspelled a few lines back (pubic class HelloWorld). The nitty-gritty is the most frustrating part of learning. But guess what?

We got through it.

Somehow, we were able to keep truckin’, commenting out huge blocks of code and throwing in random printf(”here”) and printf(”there”) statements every other line to figure out where the hell the memory hangup occurs.

Try, try, try again. Don’t let runtime errors get you down - debug and optimize, search* forums, and use google. You’ll end up feeling a lot smarter for solving the problem yourself (even if it means just looking up the answer on google), and, more importantly, you will remember the solution.

The nitty-gritty of coding is essential to learning - you can’t avoid it, but you can shorten it by toughing it out.

And for God’s sake, rtfm.

/rant.
- Joe

*Contrary to popular belief, search does not actually mean post

cocos2d: First Impressions

November 19th, 2008

I spent a few hours today throwing together a GameScene.m class with cocos2d, and I’d say it’s pretty sweet. With just a few lines I was able to include Chipmunk physics system and add gravity and collision, etc. I’ve never done anything like it before:

// Chipmunk Physics staticBody = cpBodyNew(INFINITY, INFINITY); cpResetShapeIdCounter(); space = cpSpaceNew(); cpSpaceResizeStaticHash(space, 20.0, 999); space->gravity = cpv(0, -100); cpShape *shape; int num = 4; cpVect verts[] = { cpv(-15,-15), cpv(-15, 15), cpv( 15, 15), cpv( 15,-15), }; //add the ground shape = cpSegmentShapeNew(staticBody,cpv(0, 30), cpv(320,30), 0.0f); shape->collision_type = 0; shape->e = 1.0; shape->u = 1.0; cpSpaceAddStaticShape(space, shape); //create a body for the puppy pupBody = cpBodyNew(1.0, cpMomentForPoly(1.0, num, verts, cpvzero)); pupBody->p = cpv(120, 240); cpSpaceAddBody(space, pupBody); shape = cpPolyShapeNew(pupBody, num, verts, cpvzero); shape->e = 0.0; shape->u = 1.5; shape->collision_type = 1; cpSpaceAddShape(space, shape);
And bam, you’ve got the physics for a small box that bounces around on the ground. To step the physics, you simply call:
cpSpaceStep(space, delta);
The official Chipmunk docs can be found here.

Anyways, I spent some time on GameScene class, and managed to get a rotating cannon and a falling dog up as well:



So that’s enough for today, I’ll try and make the dog bounce and add a way to control the rotation of the cannon sometime tomorrow.

-Joe

The Coding Begins

November 19th, 2008

After whipping up some mockup art in Photoshop yesterday, I figured today I’d look into the coding side of things. I opened up XCode and made a new iPhone project, and started to think up a class structure for this game in my head. After throwing around a few ideas, I figured I’d take a look around for any frameworks that might be helpful (physics, side-scrolling, any type of framework that in any way relates to puppy-cannoning…).

I stumbled upon two equally helpful frameworks:

Unity is a very heavy game-making IDE (pretty much a full replacement for XCode) that makes it easy to create 3D and 2D games, whereas cocos2d is a simple 2d game framework (with a physics library) that you embed into an XCode project. Needless to say, I opted for cocos2d; the fact that Unity was around $500 didn’t help its chances either.

So I got cocos2d linked into my project (which was a pain in the a** by the way), and finally began coding. I made a simple menu-based navigation system with some nice looking transitions (almost straight out of the cocos2d sample code), and played around with the Sprite class and a few other objects for a while. So anyway, here’s a screenshot of what I’ve got so far:



Cocos manages all the scenes (menu, main game, and high score in our case) with an object called the Director. The director can push, pop, and replace the visible scene. Look how simple it is to go from a game scene to a high score scene:
director.replace(FadeUpTransition(highScores));
This fades the game scene into the high scores scene.

Anyway, I thought cocos2d was pretty neat. Will definitely save me a ton of time in this project.

Another day down
- Joe

New blog, new project…

November 18th, 2008

Welcome, everyone, to the new silentmac.com. I decided to throw a nice little wordpress blog up on here so that I could keep track of my projects and such. Why did I start over? Well I get tired of my old sites, and often just want to create something new, instead of constantly updating something old. Maintenance never was my strong suit…

Right now I am working on porting that addicting game that everyone loves, Kitten Cannon, to the iPhone, using Apple’s SDK. I am starting from scratch, so none of the original graphics or anything like that will be used (I’m not sure of the status of the artwork from the original developer anyways), but it’s clear where my inspiration is from (the name of the game is Puppy Cannon for Christ’s sake). I will be documenting my work so that the public can see the process that goes into creating a game on the iPhone.

So I put a little design work in, and here’s the mockup I’ve created so far:



I will try to update this daily, or at least after everytime I complete a bit of the project.

That’s it for now…
- Joe