All Data Structures Files Functions Variables Enumerations Enumerator Properties Defines
/Projects/Cogito/src/GameObjects/GameObject.m
Go to the documentation of this file.
00001 //
00002 //  GameObject.m
00003 //  Author: Thomas Taylor
00004 //
00005 //  A base class for all game objects
00006 //
00007 //  21/11/2011: Created class
00008 //
00009 
00010 #import "GameObject.h"
00011 
00012 @implementation GameObject
00013 
00014 @synthesize reactsToScreenBoundaries;
00015 @synthesize screenSize;
00016 @synthesize isActive;
00017 @synthesize isCollideable;
00018 @synthesize gameObjectType;
00019 
00020 #pragma mark -
00021 #pragma mark Initialisation
00022 
00027 -(id)init
00028 {    
00029     if(self = [super init])
00030     {
00031         winSize = [CCDirector sharedDirector].winSize;
00032         isActive = YES;
00033         isCollideable = YES;
00034         gameObjectType = kObjectTypeNone;
00035     }
00036     
00037     return self;
00038 }
00039 
00040 #pragma mark -
00041 
00046 -(void)changeState:(CharacterStates)_newState
00047 {
00048     // should be overridden in subclasses
00049 }
00050 
00056 -(void)updateStateWithDeltaTime:(ccTime)_deltaTime andListOfGameObjects:(CCArray *)_listOfGameObjects
00057 {
00058     // should be overridden in subclasses
00059 }
00060 
00065 -(CGRect)adjustedBoundingBox
00066 {
00067     // should be overridden in subclasses
00068     
00069     // return standard bounding box for now
00070     return [self boundingBox];
00071 }
00072 
00073 #pragma mark -
00074 #pragma mark Animation Loading
00075 
00082 -(CCAnimation*)loadAnimationFromPlistWthName:(NSString*)_animationName andClassName:(NSString*)_className
00083 {
00084     CCAnimation *animationToReturn = nil;
00085     NSDictionary *plistDictionary = [Utils loadPlistFromFile:_className];
00086     if(plistDictionary == nil) { CCLOG(@"GameObject.loadAnimationFromPlistWithName: Error loading %@.plist", _className); return nil; }
00087     
00088     // get the mini-dictionary for the animation
00089     NSDictionary *animationSettings = [plistDictionary objectForKey:_animationName];
00090     if(animationSettings == nil) { CCLOG(@"Could not locate animation with name: %@", _animationName); return nil; }
00091     
00092     // get the delay value for the animation
00093     animationToReturn = [CCAnimation animation];
00094     [animationToReturn setDelay:[[animationSettings objectForKey:@"delay"] floatValue]];
00095     
00096     // add the frames to the animation
00097     NSString *animationFramePrefix = [animationSettings objectForKey:@"filenamePrefix"];
00098     NSString *animationFrames = [animationSettings objectForKey:@"animationFrames"];
00099     NSArray *animationFrameNumbers = [animationFrames componentsSeparatedByString:@","];
00100     
00101     for (NSString *frameNumber in animationFrameNumbers) 
00102     {
00103         NSString *frameName = [NSString stringWithFormat:@"%@%@.png", animationFramePrefix, frameNumber];
00104         [animationToReturn addFrame:[[CCSpriteFrameCache sharedSpriteFrameCache] spriteFrameByName:frameName]];
00105     }
00106     
00107     // return the animation
00108     return animationToReturn;
00109 }
00110 
00111 @end