/* * cocos2d for iPhone: http://www.cocos2d-iphone.org * * Copyright (c) 2008-2011 Ricardo Quesada * Copyright (c) 2011 Zynga Inc. * * 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" #import "CCSprite.h" #import "CCSpriteFrame.h" #import "CCAnimation.h" #import "CCNode.h" #import "Support/CGPointExtension.h" // // IntervalAction // #pragma mark - #pragma mark IntervalAction @implementation CCActionInterval @synthesize elapsed = elapsed_; -(id) init { NSAssert(NO, @"IntervalActionInit: Init not supported. Use InitWithDuration"); [self release]; return nil; } +(id) actionWithDuration: (ccTime) d { return [[[self alloc] initWithDuration:d ] autorelease]; } -(id) initWithDuration: (ccTime) d { if( (self=[super init]) ) { duration_ = d; // prevent division by 0 // This comparison could be in step:, but it might decrease the performance // by 3% in heavy based action games. if( duration_ == 0 ) duration_ = FLT_EPSILON; elapsed_ = 0; firstTick_ = YES; } return self; } -(id) copyWithZone: (NSZone*) zone { CCAction *copy = [[[self class] allocWithZone: zone] initWithDuration: [self duration] ]; return copy; } - (BOOL) isDone { return (elapsed_ >= duration_); } -(void) step: (ccTime) dt { if( firstTick_ ) { firstTick_ = NO; elapsed_ = 0; } else elapsed_ += dt; [self update: MIN(1, elapsed_/duration_)]; } -(void) startWithTarget:(id)aTarget { [super startWithTarget:aTarget]; elapsed_ = 0.0f; firstTick_ = YES; } - (CCActionInterval*) reverse { NSAssert(NO, @"CCIntervalAction: reverse not implemented."); return nil; } @end // // Sequence // #pragma mark - #pragma mark Sequence @implementation CCSequence +(id) actions: (CCFiniteTimeAction*) action1, ... { va_list params; va_start(params,action1); CCFiniteTimeAction *now; CCFiniteTimeAction *prev = action1; while( action1 ) { now = va_arg(params,CCFiniteTimeAction*); if ( now ) prev = [self actionOne: prev two: now]; else break; } va_end(params); return prev; } +(id) actionsWithArray: (NSArray*) actions { CCFiniteTimeAction *prev = [actions objectAtIndex:0]; for (NSUInteger i = 1; i < [actions count]; i++) prev = [self actionOne:prev two:[actions objectAtIndex:i]]; return prev; } +(id) actionOne: (CCFiniteTimeAction*) one two: (CCFiniteTimeAction*) two { return [[[self alloc] initOne:one two:two ] autorelease]; } -(id) initOne: (CCFiniteTimeAction*) one two: (CCFiniteTimeAction*) two { NSAssert( one!=nil && two!=nil, @"Sequence: arguments must be non-nil"); NSAssert( one!=actions_[0] && one!=actions_[1], @"Sequence: re-init using the same parameters is not supported"); NSAssert( two!=actions_[1] && two!=actions_[0], @"Sequence: re-init using the same parameters is not supported"); ccTime d = [one duration] + [two duration]; if( (self=[super initWithDuration: d]) ) { // XXX: Supports re-init without leaking. Fails if one==one_ || two==two_ [actions_[0] release]; [actions_[1] release]; actions_[0] = [one retain]; actions_[1] = [two retain]; } return self; } -(id) copyWithZ
doors {
name: "The Panel"
type: LOCATION_ONLY
panels { room: "The Whole Thing" name: "PANEL" }
location_room: "The Whole Thing"
location_name: "Panel"
}