BungeeNinja – Origins

October 7, 2011

So where did BungeeNinja come from I hear you cry! (actually no one has asked me but I’m going to tell you anyway!)

BungeeNinja is the game idea of my good friend KPM-Philbo and the currently released form is far from it’s original concept! Originally codenamed PvN (Pirates Vs. Ninjas) the ninja was swinging his way across an invading fleet of Pirate ships. Alternatively you could also play a pirate swinging across some ninja buildings!

Now the difference with this game was that should you land on a ship / building a mini point and click game would kick in where the main character would have to doge projectiles and shoot the enemies throwing projectiles. Upon defeating a boss you would then reenter swinging mode and so on and so forth.

As soon as KPM-Philbo told me his concept I downloaded Eclipse and AS3, although the game was always intended for iPhone and Android, and knocked together a quick and dirty version of the point and click mode!

PvN Shoot

Tap to shoot!! How long can you last!

Inside of a week we had our mock level and inspired by the progress I moved onto the swing levels. Now the swing level was going to take a lot more work and as we were going to target the iPhone I needed a lib that was compatible, after some research I discovered Box2d originally in C++ and ported to AS3. As Box2d originated in C++ it could be used natively by the iPhone and Android had a java port too so I cracked on.

Once I had learned the basics from Emanuel Emanuele On Box2d (cheers) I got to grips with KPM-Philbos’s concept and started on a more polished mock up and ended up with this…

Generic Ninja Game

Remember its not finished! Click on the Number 0 Next to the first ship to start and then on each ship you unlock to play on, the continue button on the tutorial is behind the image in the top left and not the button on the image, Enjoy 😀

Tip: try and get to Level 3 for a Mattius original idea …. Da Fish!!!!
Note: the awesome cutscene is by KPM-Philbo 😉

Not finished but I might one day finish it and slap it on FaceBook or something. The finished BungeeNinja had a lot of features removed due to screen size limitations and also as we want some features for BN2 😀 (when we get round to it!).

So there you have it, BungeeNinja Origins (was it as exciting as Wolverine Origins…. No! Ah well).

The released version can be found here…

iPhone
Bungee Ninja (iPhone)
Bungee Ninja Lite (iPhone)

Android
Bungee Ninja (Android)
Bungee Ninja Lite (Android)

Advertisements

Floobz

October 7, 2011

Following the Huge Success of Bungee Ninja (giving KPM enough money to cover a quarter of the MacBook Pro we bought for me to write it) KPM-Russ has invested in a Mac Mini and we are on Project 3. Project 2 (Blobz) which was started just after BungeeNinja has been placed on hold while we work on Floobz which is a much more manageable game to write!

Using the C# XML Level Designer (coded by KPM-Russ) created initially for Blobz and the XML DeSerialiser (coded by me mentioned in a previous post) we are flying along and hope to have a release out for Christmas! We have also enlisted “The Chee” who already had a MacPro and is knocking out features for it! You can follow the progress blogged by KPM-Russ here http://floobzgame.wordpress.com

Once the framework for this game is in place we hope to enlist some chums to use the Level Designer and knock together our first set of Levels for the initial release!

We are developing a reusable engine as much as developing individual games and anyone wanting to know how we implement any of the features are welcome to drop me a comment / email and I will endeavour to blog about it!

Sneaky preview…



Objective C Zombie

June 8, 2011

How a Zombie saved my Blog!

20110608-224353.jpg

As I mentioned in my earlier blog (at least I think I mentioned it, it was at least yesterday when I wrote it!) I have been programming in C# for years now and have become acclimatised to having a garbage collector! And although I love the “using” statement and use it wherever I can in C# (more OCD layout thing than anything) I have become lazy in terms of Memory Management.

Yesterday in my impatience to show the world my XMLLoader, I posted sample code with memory issues in, it Oops Sorry! This mistake has however given me the opportunity to explain how I fixed it!

First what is a Zombie… Well it’s a dead person who has been brought back to …. 😀 sorry couldn’t resist (geek sense of humour!). A Zombie is an Object that has been swapped with another Object instead of being released from memory!

My memory issue (double release) was produced by releasing an Object that was already in the AutoRelease* queue! This occurs in my code in the XMLLoader class where I release an NSArray which is created using a method that does not contain the keywords “new” or “init” (meaning it’s AutoReleased by the rules of Objective C). I assumed the XMLLoader class I wrote was working because my debug point passed the creation / loading of the Object and had NSLog’ed my results. The error manifested itself later on at a random place when the AutoRelease code tried to cleanup!

So how did I find it? I happened upon NSZombieEnabled which is a runtime argument that causes released Objects to not be released but changed into a Zombie class! This means you can trace the memory reference in the random error to an Object. Don’t forget to turn it off though because it turns your app into one big memory leak (or as I like to think of it an army of Zombies … Arghhh)!!!

More info: http://www.cocoadev.com/index.pl?NSZombieEnabled

I’ll attempt to remember to fix my original post (or at least point to this one!).

*Just in case you don’t know AutoRelease is a method you can call instead of Release on an Objective C class which will Auto free memory when there are no more references.

Objective C Serialization

June 7, 2011

So I am under way with KPM Project 2 on the iPhone and we have decided to go down a Level Designer route for Box2D so we can produce levels easily! The level designer is being coded by my esteemed colleague Russ King (the K in KPM) and I am interpreting the XML on the iPhone to produce a level.

I have been google’ing about and cant seem to find a way to load the XML into an Object Structure in a way that I am happy with! Coming from a C# background I get this out of the box, being a newbie Objective C programmer I might have missed some easy way of doing it, if I have its too late now anyway because I coded one!

I thought this might be useful in case other people are struggling so I’ll post it up here (so far I have only needed to load from XML and the schema I use doesn’t use attributes but should be easily extendable).

First off follow the instructions here:

http://foobarpig.com/iphone/touchxml-installation-guide.html

to install TouchXML then add my XMLLoader class you your project and extend it with anything you want loading from XML. I was going to use Objective C’s form of reflection to automatically link Node to Property but I haven’t had time and this works for my purposes for now!

Here is the code! Please be nice I am new to Objective C 😀 also if this is useful let me know and I might make it a proper lib some day!

Usage:

Extend XMLLoader and Implement the initWithXML method in all classes that are being populated from XML in the usual way and use the methods available to populate the properties e.g. My favourite is the ClassArrayFromXPathOfType method as this accepts a collection of Nodes and populates it with instances of the Class you specify (the Class you specify must extend XMLLoader to work).

Example Load Code:

+(ClassType *) createClassFromXML:(NSString *)path
{
    NSData *xmlData = [NSData dataWithContentsOfFile:path];

    CXMLDocument *doc = [[[CXMLDocument alloc] initWithData:xmlData options:0 error:nil] autorelease];
    CXMLElement *xmlDoc;
    NSArray *nodes = NULL; 

    nodes = [doc nodesForXPath:@"/FirstNode" error:nil];

    if ([nodes count] > 0)
    {
        xmlDoc = (CXMLElement *)[nodes objectAtIndex:0];
    }
    else
    {
        [NSException raise:@"First Node Missing" format:@"XPath: /FirstNode"];
    }

    [nodes release];

    ClassType *classInstance = [[ClassType alloc] initWithXML:xmlDoc];

    [classInstance autorelease];

    return classInstance;
}

Example Constructor:

-(id) initWithXML:(CXMLElement *) xmlDocument
{
    if ((self = [super initWithXML:xmlDocument]))
    {
        _intProperty = [super intFromXPath:@"IntProperty"];
        _floatProperty = [super intFromXPath:@"FloatProperty"];
        _stringProperty = [super stringFromXPath:@"StringProperty"];
        _classProperty = [[ClassName alloc] initWithXML:[super nodeFromXPath:@"ClassName"]];
        _arrayProperty = [super classArrayFromXPath:@"CollectionNodes/*" OfType:@"ClassType"];
    }

    return self;
}

Header:

#import 

@class CXMLElement;

@interface XMLLoader : NSObject
{
    CXMLElement *_document;
}

-(id) initWithXML:(CXMLElement *) xmlDocument;
-(NSString *) stringFromXPath:(NSString *) xPath;
-(int) intFromXPath:(NSString *) xPath;
-(float) floatFromXPath:(NSString *) xPath;
-(BOOL) boolFromXPath:(NSString *) xPath;
-(CXMLElement *) nodeFromXPath:(NSString *) xPath;
-(NSArray *) nodesFromXPath:(NSString *) xPath;
-(NSArray *) classArrayFromXPath:(NSString *) xPath OfType:(NSString *) classType;

@end

Class:

#import "XMLLoader.h"
#import "TouchXML.h"

@implementation XMLLoader

-(id) initWithXML:(CXMLElement *) xmlDocument
{
    if ((self = [super init]))
    {
        _document = xmlDocument;
    }

    return self;
}

-(void) dealloc
{
    [_document release];

    [super dealloc];
}

-(NSString *) stringFromXPath:(NSString *) xPath
{
    NSString *value;
    NSArray *nodes = NULL;
    CXMLElement *element = nil; 

    nodes = [_document nodesForXPath:xPath error:nil];

    if ([nodes count] > 0)
    {
        element = (CXMLElement *)[nodes objectAtIndex:0];
        value = [element stringValue];
    }
    else
    {
        [NSException raise:@"XMLLoader: XPath not found!" format:@"XPath: %@", xPath];
    }

    [nodes release];

    return value;
}

-(int) intFromXPath:(NSString *) xPath
{
    NSString *stringValue = [self stringFromXPath:xPath];

    return [stringValue intValue];
}

-(float) floatFromXPath:(NSString *) xPath
{
    NSString *stringValue = [self stringFromXPath:xPath];

    return [stringValue floatValue];
}

-(BOOL) boolFromXPath:(NSString *) xPath
{
    NSString *stringValue = [self stringFromXPath:xPath];

    return [stringValue boolValue];
}

-(CXMLElement *) nodeFromXPath:(NSString *) xPath
{
    CXMLElement *value;
    NSArray *nodes = NULL; 

    nodes = [_document nodesForXPath:xPath error:nil];

    if ([nodes count] > 0)
    {
        value = (CXMLElement *)[nodes objectAtIndex:0];
    }
    else
    {
        [NSException raise:@"XMLLoader: XPath not found!" format:@"XPath: %@", xPath];
    }

    [nodes release];

    return value;
}

-(NSArray *) nodesFromXPath:(NSString *) xPath
{
    NSArray *nodes = NULL; 

    nodes = [_document nodesForXPath:xPath error:nil];

    return nodes;
}

-(NSArray *) classArrayFromXPath:(NSString *) xPath OfType:(NSString *) classType
{
    NSArray *returnValues;
    NSMutableArray *values = [[NSMutableArray alloc] init];
    NSArray *nodes = [self nodesFromXPath:xPath];

    for (CXMLElement *node in nodes)
    {
        XMLLoader *classInstance = [[NSClassFromString(classType) alloc] initWithXML:node];

        [values addObject:classInstance];

        [classInstance release];
    }

    returnValues = [NSArray arrayWithArray:values];

    [values release];

    return returnValues;
}

@end