Game Update 逻辑处理 - 整理中

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

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

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

#pragma mark –
#pragma mark Update Method
-(void) update:(ccTime)deltaTime {
	CCArray *listOfGameObjects = [sceneSpriteBatchNode children]; // 1
	for (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:malletAnim
restoreOriginalFrame:NO]];
        [self runAction:action];
    } else {
        [self setVisible:NO]; // Picked up
        [self removeFromParentAndCleanup:YES];
    }
}

-(void)updateStateWithDeltaTime:(ccTime)deltaTime
andListOfGameObjects:(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




  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值