All Data Structures Files Functions Variables Enumerations Enumerator Properties Defines
/Projects/Cogito/src/GameObjects/Obstacle.m
Go to the documentation of this file.
00001 //
00002 //  Obstacle.m
00003 //  Author: Thomas Taylor
00004 //
00005 //  A basic class to contain obstacle relevant data
00006 //
00007 //  05/12/2011: Created class
00008 //
00009 
00010 #import "Obstacle.h"
00011 
00012 @interface Obstacle()
00013 
00014 -(void)animateObstacleBy:(int)_movementAmount withLength:(float)_length andDelay:(float)_delay alongAxis:(Axis)_axis;
00015 
00016 @end
00017 
00018 @implementation Obstacle
00019 
00020 #pragma mark -
00021 #pragma mark Initialisation
00022 
00030 - (id)initObstacleType:(GameObjectType)_type withPosition:(CGPoint)_position andFilename:(NSString*)_filename
00031 {    
00032     self = [super init];
00033     
00034     if (self != nil) 
00035     {        
00036         self.gameObjectType = _type;
00037         filename = [NSString stringWithFormat:@"%@.png", _filename];
00038         
00039         [self setPosition:_position];
00040         
00041         // set the display frame
00042         [self setDisplayFrame:[[CCSpriteFrameCache sharedSpriteFrameCache] spriteFrameByName:filename]];
00043         
00044         // set up the animation if necessary
00045         if(_type == kObstacleStamper) [self animateObstacleBy:-50 withLength:1.25f andDelay:2.5f alongAxis:kAxisVertical];
00046         else if(_type == kObstacleWater) [self animateObstacleBy:-15 withLength:2.0f andDelay:0.0f alongAxis:kAxisHorizontal];
00047     }
00048     return self;
00049 }
00050 
00057 -(void)animateObstacleBy:(int)_movementAmount withLength:(float)_length andDelay:(float)_delay alongAxis:(Axis)_axis 
00058 {    
00059     id action = nil;
00060     
00061     // create and run the action
00062     if(_axis == kAxisHorizontal)
00063     {
00064         action = [CCSequence actions:
00065                     [CCMoveBy actionWithDuration:_length/2 position:ccp(_movementAmount,0)],
00066                     [CCMoveBy actionWithDuration:_length/2 position:ccp(_movementAmount*-1,0)], 
00067                     [CCMoveBy actionWithDuration:_delay position:ccp(0,0)],
00068                   nil];
00069     }
00070     else 
00071     {
00072         action = [CCSequence actions:
00073                   [CCMoveBy actionWithDuration:_length/2 position:ccp(0,_movementAmount)],
00074                   [CCMoveBy actionWithDuration:_length/2 position:ccp(0,_movementAmount*-1)], 
00075                   [CCMoveBy actionWithDuration:_delay position:ccp(0,0)],
00076                   nil];
00077     }
00078     
00079     action = [CCRepeatForever actionWithAction:action];
00080     [self runAction:action];
00081 }
00082 
00083 @end