Particle Collisions

Well I finally have the game at a place where I am happy with it as a version 1.0 release.

I am currently waiting on the icon art to be done and once that comes through it’s straight to the AppStore for the first time ever!

The final tweak I made to the app was to integrate a collision system with a particle emitter.  After trawling the internet to find many deprecated methods and properties and code snippets that didn’t seem to work I finally cobbled them all together and got it working.

Before any collision implementation I had a plain old CCParticleSystem implemented like…

CCParticleSystem* emitter = [CCParticleSystemQuad particleWithFile:@"bubble-effect.plist"];

In the end I had to subclass the CCParticleSystemQuad and override the method updateQuadWithParticle using the following code/pseudo code…

-(void) updateQuadWithParticle:(tCCParticle*)particle newPosition:(CGPoint)pos
{
    GameLayer* sharedGameLayer = [GameLayer sharedGameLayer];
    BOOL collide = [sharedGameLayer checkCollisionWithPosition:pos];
    if (collide)
    {
        particle->timeToLive = 0;
    }
    else
    {
        [super updateQuadWithParticle:particle newPosition:pos];
    }
}

If this returned TRUE I just set the particle.timeToLive to 0. This effectively killed the particle without actually removing it from the emitter so it could be used again.

The last thing I had to do was change the instantiation to…

CCParticleSystem* emitter = [MyEmmiter particleWithFile:@"bubble-effect.plist"];

Putting this here to hopefully help anyone else out there.

Note to self… get a code snippet plugin!  … Well, I gave up looking for a snippet program and coded it myself.  Looks a hell of a lot better now.

Advertisements

Sorting an NSArray of NSDictionaries

One of my tasks today was to implement local high scores with name associated with them.

Saving them was easy as I put each high score into an NSDictionary with keys “score” and “name”.  Easy, done…

Not so, I then had the task of trying to sort the array.  I knew it should be easy but I couldn’t find any reference to it anywhere.

In the end I found this snippet of code so I thought I’d put it out there for everyone to share.

[highScores sortUsingDescriptors:[NSArray arrayWithObject:[[[NSSortDescriptor alloc] initWithKey:@"score" ascending:NO] autorelease]]];

It’s a hell of a long line but it sorts the array “highScores” using the dictionary key “scores”.

All in one line without having to write any functions or methods or comparisons etc…

My foray into the iOS AppStore

For the past 6 months I have been wanting to make a break into the Apple App Store and I have started a few apps but never with enough conviction to keep going and get them finished.  Although I have begun to realise that as a one man development team it pays to aim for something simple.  Especially for a first attempt at the App Store.

A couple of weeks ago I discovered the recently released book Learn iPhone Cocos2d Game Programming and decided to have another try.  This time I was determined and decided to create a simple but enjoyable game instead of a utility app.  Although I didn’t know what it was going to be yet.

The book was a great help and gave me an idea of what was within the realms of possibility and so my game development began…