+++ /dev/null
-/*
- * cocos2d for iPhone: http://www.cocos2d-iphone.org
- *
- * Copyright (c) 2008-2010 Ricardo Quesada
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- * THE SOFTWARE.
- *
- */
-
-
-#include <sys/time.h>
-#import <Foundation/Foundation.h>
-
-#import "ccTypes.h"
-
-enum {
- //! Default tag
- kCCActionTagInvalid = -1,
-};
-
-/** Base class for CCAction objects.
- */
-@interface CCAction : NSObject <NSCopying>
-{
- id originalTarget_;
- id target_;
- NSInteger tag_;
-}
-
-/** The "target". The action will modify the target properties.
- The target will be set with the 'startWithTarget' method.
- When the 'stop' method is called, target will be set to nil.
- The target is 'assigned', it is not 'retained'.
- */
-@property (nonatomic,readonly,assign) id target;
-
-/** The original target, since target can be nil.
- Is the target that were used to run the action. Unless you are doing something complex, like ActionManager, you should NOT call this method.
- @since v0.8.2
-*/
-@property (nonatomic,readonly,assign) id originalTarget;
-
-
-/** The action tag. An identifier of the action */
-@property (nonatomic,readwrite,assign) NSInteger tag;
-
-/** Allocates and initializes the action */
-+(id) action;
-
-/** Initializes the action */
--(id) init;
-
--(id) copyWithZone: (NSZone*) zone;
-
-//! return YES if the action has finished
--(BOOL) isDone;
-//! called before the action start. It will also set the target.
--(void) startWithTarget:(id)target;
-//! called after the action has finished. It will set the 'target' to nil.
-//! IMPORTANT: You should never call "[action stop]" manually. Instead, use: "[target stopAction:action];"
--(void) stop;
-//! called every frame with it's delta time. DON'T override unless you know what you are doing.
--(void) step: (ccTime) dt;
-//! called once per frame. time a value between 0 and 1
-//! For example:
-//! * 0 means that the action just started
-//! * 0.5 means that the action is in the middle
-//! * 1 means that the action is over
--(void) update: (ccTime) time;
-
-@end
-
-/** Base class actions that do have a finite time duration.
- Possible actions:
- - An action with a duration of 0 seconds
- - An action with a duration of 35.5 seconds
- Infitite time actions are valid
- */
-@interface CCFiniteTimeAction : CCAction <NSCopying>
-{
- //! duration in seconds
- ccTime duration_;
-}
-//! duration in seconds of the action
-@property (nonatomic,readwrite) ccTime duration;
-
-/** returns a reversed action */
-- (CCFiniteTimeAction*) reverse;
-@end
-
-
-@class CCActionInterval;
-/** Repeats an action for ever.
- To repeat the an action for a limited number of times use the Repeat action.
- @warning This action can't be Sequenceable because it is not an IntervalAction
- */
-@interface CCRepeatForever : CCAction <NSCopying>
-{
- CCActionInterval *other;
-}
-/** creates the action */
-+(id) actionWithAction: (CCActionInterval*) action;
-/** initializes the action */
--(id) initWithAction: (CCActionInterval*) action;
-@end
-
-/** Changes the speed of an action, making it take longer (speed>1)
- or less (speed<1) time.
- Useful to simulate 'slow motion' or 'fast forward' effect.
- @warning This action can't be Sequenceable because it is not an IntervalAction
- */
-@interface CCSpeed : CCAction <NSCopying>
-{
- CCActionInterval *other;
- float speed;
-}
-/** alter the speed of the inner function in runtime */
-@property (nonatomic,readwrite) float speed;
-/** creates the action */
-+(id) actionWithAction: (CCActionInterval*) action speed:(float)rate;
-/** initializes the action */
--(id) initWithAction: (CCActionInterval*) action speed:(float)rate;
-@end
-
-@class CCNode;
-/** CCFollow is an action that "follows" a node.
-
- Eg:
- [layer runAction: [CCFollow actionWithTarget:hero]];
-
- Instead of using CCCamera as a "follower", use this action instead.
- @since v0.99.2
- */
-@interface CCFollow : CCAction <NSCopying>
-{
- /* node to follow */
- CCNode *followedNode_;
-
- /* whether camera should be limited to certain area */
- BOOL boundarySet;
-
- /* if screensize is bigger than the boundary - update not needed */
- BOOL boundaryFullyCovered;
-
- /* fast access to the screen dimensions */
- CGPoint halfScreenSize;
- CGPoint fullScreenSize;
-
- /* world boundaries */
- float leftBoundary;
- float rightBoundary;
- float topBoundary;
- float bottomBoundary;
-}
-
-/** alter behavior - turn on/off boundary */
-@property (nonatomic,readwrite) BOOL boundarySet;
-
-/** creates the action with no boundary set */
-+(id) actionWithTarget:(CCNode *)followedNode;
-
-/** creates the action with a set boundary */
-+(id) actionWithTarget:(CCNode *)followedNode worldBoundary:(CGRect)rect;
-
-/** initializes the action */
--(id) initWithTarget:(CCNode *)followedNode;
-
-/** initializes the action with a set boundary */
--(id) initWithTarget:(CCNode *)followedNode worldBoundary:(CGRect)rect;
-
-@end
-
+++ /dev/null
-/*
- * cocos2d for iPhone: http://www.cocos2d-iphone.org
- *
- * Copyright (c) 2008-2010 Ricardo Quesada
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- * THE SOFTWARE.
- *
- */
-
-
-
-#import <Availability.h>
-#import "CCDirector.h"
-#import "ccMacros.h"
-#import "CCAction.h"
-#import "CCActionInterval.h"
-#import "Support/CGPointExtension.h"
-
-//
-// Action Base Class
-//
-#pragma mark -
-#pragma mark Action
-@implementation CCAction
-
-@synthesize tag = tag_, target = target_, originalTarget = originalTarget_;
-
-+(id) action
-{
- return [[[self alloc] init] autorelease];
-}
-
--(id) init
-{
- if( (self=[super init]) ) {
- originalTarget_ = target_ = nil;
- tag_ = kCCActionTagInvalid;
- }
- return self;
-}
-
--(void) dealloc
-{
- CCLOGINFO(@"cocos2d: deallocing %@", self);
- [super dealloc];
-}
-
--(NSString*) description
-{
- return [NSString stringWithFormat:@"<%@ = %08X | Tag = %i>", [self class], self, tag_];
-}
-
--(id) copyWithZone: (NSZone*) zone
-{
- CCAction *copy = [[[self class] allocWithZone: zone] init];
- copy.tag = tag_;
- return copy;
-}
-
--(void) startWithTarget:(id)aTarget
-{
- originalTarget_ = target_ = aTarget;
-}
-
--(void) stop
-{
- target_ = nil;
-}
-
--(BOOL) isDone
-{
- return YES;
-}
-
--(void) step: (ccTime) dt
-{
- NSLog(@"[Action step]. override me");
-}
-
--(void) update: (ccTime) time
-{
- NSLog(@"[Action update]. override me");
-}
-@end
-
-//
-// FiniteTimeAction
-//
-#pragma mark -
-#pragma mark FiniteTimeAction
-@implementation CCFiniteTimeAction
-@synthesize duration = duration_;
-
-- (CCFiniteTimeAction*) reverse
-{
- CCLOG(@"cocos2d: FiniteTimeAction#reverse: Implement me");
- return nil;
-}
-@end
-
-
-//
-// RepeatForever
-//
-#pragma mark -
-#pragma mark RepeatForever
-@implementation CCRepeatForever
-+(id) actionWithAction: (CCActionInterval*) action
-{
- return [[[self alloc] initWithAction: action] autorelease];
-}
-
--(id) initWithAction: (CCActionInterval*) action
-{
- if( (self=[super init]) )
- other = [action retain];
-
- return self;
-}
-
--(id) copyWithZone: (NSZone*) zone
-{
- CCAction *copy = [[[self class] allocWithZone: zone] initWithAction:[[other copy] autorelease] ];
- return copy;
-}
-
--(void) dealloc
-{
- [other release];
- [super dealloc];
-}
-
--(void) startWithTarget:(id)aTarget
-{
- [super startWithTarget:aTarget];
- [other startWithTarget:target_];
-}
-
--(void) step:(ccTime) dt
-{
- [other step: dt];
- if( [other isDone] ) {
- ccTime diff = dt + other.duration - other.elapsed;
- [other startWithTarget:target_];
-
- // to prevent jerk. issue #390
- [other step: diff];
- }
-}
-
-
--(BOOL) isDone
-{
- return NO;
-}
-
-- (CCActionInterval *) reverse
-{
- return [CCRepeatForever actionWithAction:[other reverse]];
-}
-
-@end
-
-//
-// Speed
-//
-#pragma mark -
-#pragma mark Speed
-@implementation CCSpeed
-@synthesize speed;
-
-+(id) actionWithAction: (CCActionInterval*) action speed:(float)r
-{
- return [[[self alloc] initWithAction: action speed:r] autorelease];
-}
-
--(id) initWithAction: (CCActionInterval*) action speed:(float)r
-{
- if( (self=[super init]) ) {
- other = [action retain];
- speed = r;
- }
- return self;
-}
-
--(id) copyWithZone: (NSZone*) zone
-{
- CCAction *copy = [[[self class] allocWithZone: zone] initWithAction:[[other copy] autorelease] speed:speed];
- return copy;
-}
-
--(void) dealloc
-{
- [other release];
- [super dealloc];
-}
-
--(void) startWithTarget:(id)aTarget
-{
- [super startWithTarget:aTarget];
- [other startWithTarget:target_];
-}
-
--(void) stop
-{
- [other stop];
- [super stop];
-}
-
--(void) step:(ccTime) dt
-{
- [other step: dt * speed];
-}
-
--(BOOL) isDone
-{
- return [other isDone];
-}
-
-- (CCActionInterval *) reverse
-{
- return [CCSpeed actionWithAction:[other reverse] speed:speed];
-}
-@end
-
-//
-// Follow
-//
-#pragma mark -
-#pragma mark Follow
-@implementation CCFollow
-
-@synthesize boundarySet;
-
-+(id) actionWithTarget:(CCNode *) fNode
-{
- return [[[self alloc] initWithTarget:fNode] autorelease];
-}
-
-+(id) actionWithTarget:(CCNode *) fNode worldBoundary:(CGRect)rect
-{
- return [[[self alloc] initWithTarget:fNode worldBoundary:rect] autorelease];
-}
-
--(id) initWithTarget:(CCNode *)fNode
-{
- if( (self=[super init]) ) {
-
- followedNode_ = [fNode retain];
- boundarySet = FALSE;
- boundaryFullyCovered = FALSE;
-
- CGSize s = [[CCDirector sharedDirector] winSize];
- fullScreenSize = CGPointMake(s.width, s.height);
- halfScreenSize = ccpMult(fullScreenSize, .5f);
- }
-
- return self;
-}
-
--(id) initWithTarget:(CCNode *)fNode worldBoundary:(CGRect)rect
-{
- if( (self=[super init]) ) {
-
- followedNode_ = [fNode retain];
- boundarySet = TRUE;
- boundaryFullyCovered = FALSE;
-
- CGSize winSize = [[CCDirector sharedDirector] winSize];
- fullScreenSize = CGPointMake(winSize.width, winSize.height);
- halfScreenSize = ccpMult(fullScreenSize, .5f);
-
- leftBoundary = -((rect.origin.x+rect.size.width) - fullScreenSize.x);
- rightBoundary = -rect.origin.x ;
- topBoundary = -rect.origin.y;
- bottomBoundary = -((rect.origin.y+rect.size.height) - fullScreenSize.y);
-
- if(rightBoundary < leftBoundary)
- {
- // screen width is larger than world's boundary width
- //set both in the middle of the world
- rightBoundary = leftBoundary = (leftBoundary + rightBoundary) / 2;
- }
- if(topBoundary < bottomBoundary)
- {
- // screen width is larger than world's boundary width
- //set both in the middle of the world
- topBoundary = bottomBoundary = (topBoundary + bottomBoundary) / 2;
- }
-
- if( (topBoundary == bottomBoundary) && (leftBoundary == rightBoundary) )
- boundaryFullyCovered = TRUE;
- }
-
- return self;
-}
-
--(id) copyWithZone: (NSZone*) zone
-{
- CCAction *copy = [[[self class] allocWithZone: zone] init];
- copy.tag = tag_;
- return copy;
-}
-
--(void) step:(ccTime) dt
-{
-#define CLAMP(x,y,z) MIN(MAX(x,y),z)
-
- if(boundarySet)
- {
- // whole map fits inside a single screen, no need to modify the position - unless map boundaries are increased
- if(boundaryFullyCovered)
- return;
-
- CGPoint tempPos = ccpSub( halfScreenSize, followedNode_.position);
- [target_ setPosition:ccp(CLAMP(tempPos.x,leftBoundary,rightBoundary), CLAMP(tempPos.y,bottomBoundary,topBoundary))];
- }
- else
- [target_ setPosition:ccpSub( halfScreenSize, followedNode_.position )];
-
-#undef CLAMP
-}
-
-
--(BOOL) isDone
-{
- return !followedNode_.isRunning;
-}
-
--(void) stop
-{
- target_ = nil;
- [super stop];
-}
-
--(void) dealloc
-{
- [followedNode_ release];
- [super dealloc];
-}
-
-@end
-
-
+++ /dev/null
-/*
- * cocos2d for iPhone: http://www.cocos2d-iphone.org
- *
- * Copyright (c) 2008-2010 Ricardo Quesada
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- * THE SOFTWARE.
- *
- */
-
-#import "CCActionInterval.h"
-
-@class CCCamera;
-
-/** Base class for CCCamera actions
- */
-@interface CCActionCamera : CCActionInterval <NSCopying>
-{
- float centerXOrig_;
- float centerYOrig_;
- float centerZOrig_;
-
- float eyeXOrig_;
- float eyeYOrig_;
- float eyeZOrig_;
-
- float upXOrig_;
- float upYOrig_;
- float upZOrig_;
-}
-@end
-
-/** CCOrbitCamera action
- Orbits the camera around the center of the screen using spherical coordinates
- */
-@interface CCOrbitCamera : CCActionCamera <NSCopying>
-{
- float radius_;
- float deltaRadius_;
- float angleZ_;
- float deltaAngleZ_;
- float angleX_;
- float deltaAngleX_;
-
- float radZ_;
- float radDeltaZ_;
- float radX_;
- float radDeltaX_;
-
-}
-/** creates a CCOrbitCamera action with radius, delta-radius, z, deltaZ, x, deltaX */
-+(id) actionWithDuration:(float) t radius:(float)r deltaRadius:(float) dr angleZ:(float)z deltaAngleZ:(float)dz angleX:(float)x deltaAngleX:(float)dx;
-/** initializes a CCOrbitCamera action with radius, delta-radius, z, deltaZ, x, deltaX */
--(id) initWithDuration:(float) t radius:(float)r deltaRadius:(float) dr angleZ:(float)z deltaAngleZ:(float)dz angleX:(float)x deltaAngleX:(float)dx;
-/** positions the camera according to spherical coordinates */
--(void) sphericalRadius:(float*) r zenith:(float*) zenith azimuth:(float*) azimuth;
-@end
+++ /dev/null
-/*
- * cocos2d for iPhone: http://www.cocos2d-iphone.org
- *
- * Copyright (c) 2008-2010 Ricardo Quesada
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- * THE SOFTWARE.
- *
- */
-
-
-
-#import "CCActionCamera.h"
-#import "CCNode.h"
-#import "CCCamera.h"
-#import "ccMacros.h"
-
-//
-// CameraAction
-//
-@implementation CCActionCamera
--(void) startWithTarget:(id)aTarget
-{
- [super startWithTarget:aTarget];
- CCCamera *camera = [target_ camera];
- [camera centerX:¢erXOrig_ centerY:¢erYOrig_ centerZ:¢erZOrig_];
- [camera eyeX:&eyeXOrig_ eyeY:&eyeYOrig_ eyeZ:&eyeZOrig_];
- [camera upX:&upXOrig_ upY:&upYOrig_ upZ: &upZOrig_];
-}
-
--(id) reverse
-{
- return [CCReverseTime actionWithAction:self];
-}
-@end
-
-@implementation CCOrbitCamera
-+(id) actionWithDuration:(float)t radius:(float)r deltaRadius:(float) dr angleZ:(float)z deltaAngleZ:(float)dz angleX:(float)x deltaAngleX:(float)dx
-{
- return [[[self alloc] initWithDuration:t radius:r deltaRadius:dr angleZ:z deltaAngleZ:dz angleX:x deltaAngleX:dx] autorelease];
-}
-
--(id) copyWithZone: (NSZone*) zone
-{
- return [[[self class] allocWithZone: zone] initWithDuration:duration_ radius:radius_ deltaRadius:deltaRadius_ angleZ:angleZ_ deltaAngleZ:deltaAngleZ_ angleX:angleX_ deltaAngleX:deltaAngleX_];
-}
-
-
--(id) initWithDuration:(float)t radius:(float)r deltaRadius:(float) dr angleZ:(float)z deltaAngleZ:(float)dz angleX:(float)x deltaAngleX:(float)dx
-{
- if((self=[super initWithDuration:t]) ) {
-
- radius_ = r;
- deltaRadius_ = dr;
- angleZ_ = z;
- deltaAngleZ_ = dz;
- angleX_ = x;
- deltaAngleX_ = dx;
-
- radDeltaZ_ = (CGFloat)CC_DEGREES_TO_RADIANS(dz);
- radDeltaX_ = (CGFloat)CC_DEGREES_TO_RADIANS(dx);
- }
-
- return self;
-}
-
--(void) startWithTarget:(id)aTarget
-{
- [super startWithTarget:aTarget];
- float r, zenith, azimuth;
-
- [self sphericalRadius: &r zenith:&zenith azimuth:&azimuth];
-
-#if 0 // isnan() is not supported on the simulator, and isnan() always returns false.
- if( isnan(radius_) )
- radius_ = r;
-
- &nb