Game Update 逻辑处理 - 整理中

来源:互联网 发布:算法导论第22章答案 编辑:程序博客网 时间:2024/05/12 05:41

- 初始化时都加到一个batchNode中

3- 循环list中每一个object (这里定义了一个抽象类 GameCharacter,实现类有自己的实现方法)

    每个object都对list遍历一次,检测是否有交互。

#pragma mark –#pragma mark Update Method-(void) update:(ccTime)deltaTime {CCArray *listOfGameObjects = [sceneSpriteBatchNode children]; // 1for (GameCharacter *tempChar in listOfGameObjects) { // 2     [tempChar updateStateWithDeltaTime:deltaTime             andListOfGameObjects: listOfGameObjects]; // 3  }}


- PowerUps 的实现:  GameObject 作为一个抽象类

//  Mallet.h//  SpaceViking//#import <Foundation/Foundation.h>#import "GameObject.h"@interface Mallet : GameObject {CCAnimation *malletAnim;}@property (nonatomic, retain) CCAnimation *malletAnim;@end

//  Mallet.m//  SpaceViking//#import "Mallet.h"@implementation Mallet@synthesize malletAnim;- (void) dealloc {    [malletAnim release];    [super dealloc];}-(void)changeState:(CharacterStates)newState {if (newState == kStateSpawning) {id action = [CCRepeatForever actionWithAction:                     [CCAnimate actionWithAnimation:malletAnimrestoreOriginalFrame:NO]];        [self runAction:action];    } else {        [self setVisible:NO]; // Picked up        [self removeFromParentAndCleanup:YES];    }}-(void)updateStateWithDeltaTime:(ccTime)deltaTimeandListOfGameObjects:(CCArray*)listOfGameObjects {float groundHeight = screenSize.height * 0.065f;if ([self position].y > groundHeight)         [self setPosition:ccp([self position].x,        [self position].y - 5.0f)];}-(void)initAnimations {    [self setMalletAnim:     [self loadPlistForAnimationWithName:@"malletAnim"       andClassName:NSStringFromClass([self class])]];}-(id) init{if( (self=[super init]) )    {screenSize = [CCDirector sharedDirector].winSize;gameObjectType = kPowerUpTypeMallet;        [self initAnimations];        [self changeState:kStateSpawning];    }return self;}@end




原创粉丝点击