(NO.00001)iOS游戏SpeedBoy Lite成形记(二十)
来源:互联网 发布:管家婆软件那三个 编辑:程序博客网 时间:2024/05/16 09:52
下面修改最为关键的matchRun方法里的代码:
CCActionCallBlock *blk = [CCActionCallBlock actionWithBlock:^{ _finishedCount++; [player endMatch]; [player stopAction:repeatJump]; [player stopAction:repeatSkew]; [self removeChild:player.streak]; if (_finishedCount == 1) { _bestElapsedTime = player.elapsedTime; GameState *gameState = [GameState sharedInstance]; NSInteger money = gameState.money; if (player.playerNumber == _betPlayer) { gameState.totalMoney += money; [_interface updateStatusLabel:[NSString stringWithFormat:@"资金 +%d",money] withColor:[CCColor greenColor]]; }else{ gameState.totalMoney -= money; [_interface updateStatusLabel:[NSString stringWithFormat:@"资金 -%d",money] withColor:[CCColor redColor]]; } } CCLabelTTF* label = (CCLabelTTF*)_labelArray[player.playerNumber-1]; NSTimeInterval intervalOffset = player.elapsedTime - _bestElapsedTime; if (intervalOffset > 0) { label.string = [NSString stringWithFormat:@"NO.%d +%.4f s",_finishedCount,intervalOffset]; }else{ label.string = [NSString stringWithFormat:@"NO.%d %.4f s",_finishedCount,player.elapsedTime]; label.color = [CCColor greenColor]; } label.visible = YES; if (_finishedCount == PlayerCount) { _finishedCount = 0; _matching = NO; _betPlayer = 0; _isBeted = NO; GameState *gameState = [GameState sharedInstance]; gameState.money = 0; [self updateGambleState]; } }];
主要变化都在block回调里,所以只贴出其中的内容.
主要逻辑是在比赛完毕后更新游戏状态.如果玩家赌对了则资金总数加上押注的数目,否则减去该数目.
为了区分出赢钱和输钱,我们在GameInterface类中添加新实例方法,首先改动接口声明:
-(void)updateStatusLabel:(NSString *)msg withColor:(CCColor*)color;
然后再到GameInterface.m中实现该方法:
-(void)updateStatusLabel:(NSString *)msg withColor:(CCColor*)color{ CCColor *orgColor = _statusLabel.color; CCActionTintTo *tintAction = [CCActionTintTo actionWithDuration:1 color:color]; CCActionCallBlock *block = [CCActionCallBlock actionWithBlock:^{ _statusLabel.color = orgColor; }]; CCActionDelay *delayAction = [CCActionDelay actionWithDuration:4]; CCActionSequence *seqAction = [CCActionSequence actions:tintAction,delayAction,block,nil]; [self updateStatusLabel:msg]; [_statusLabel runAction:seqAction];}
大体上是根据color参数动态改变状态标签的颜色,最后复原原来的颜色.
这一阶段新增的游戏逻辑完成的差不多了,下面就是实现GameOver的情形了.
0 0
- (NO.00001)iOS游戏SpeedBoy Lite成形记(二十)
- (NO.00001)iOS游戏SpeedBoy Lite成形记(十)
- (NO.00001)iOS游戏SpeedBoy Lite成形记(二)
- (NO.00001)iOS游戏SpeedBoy Lite成形记(二十一)
- (NO.00001)iOS游戏SpeedBoy Lite成形记(二十二)
- (NO.00001)iOS游戏SpeedBoy Lite成形记(二十三)
- (NO.00001)iOS游戏SpeedBoy Lite成形记(二十四)
- (NO.00001)iOS游戏SpeedBoy Lite成形记(二十五)
- (NO.00001)iOS游戏SpeedBoy Lite成形记(二十六)
- (NO.00001)iOS游戏SpeedBoy Lite成形记(二十七)
- (NO.00001)iOS游戏SpeedBoy Lite成形记(一)
- (NO.00001)iOS游戏SpeedBoy Lite成形记(三)
- (NO.00001)iOS游戏SpeedBoy Lite成形记(四)
- (NO.00001)iOS游戏SpeedBoy Lite成形记(五)
- (NO.00001)iOS游戏SpeedBoy Lite成形记(六)
- (NO.00001)iOS游戏SpeedBoy Lite成形记(七)
- (NO.00001)iOS游戏SpeedBoy Lite成形记(八)
- (NO.00001)iOS游戏SpeedBoy Lite成形记(九)
- Opecv Iplimage
- Linux远程备份工具Rsync使用案例
- Linux 上使用 backup-manager 进行系统备份
- Coursera_Stanford_ML_ex6_支持向量机(SVM) 作业记录
- Android Scrollview+Listview 实现不同条目点赞并计数功能及原理分析(1)
- (NO.00001)iOS游戏SpeedBoy Lite成形记(二十)
- flv格式
- 使用ExcelPackage生成Excel2007电子表格
- 基于Irrlicht引擎的3D游戏实例v0.7
- 使用cocoapods管理第三方库RestKit遇到的问题
- linux 软件/库 命令集合
- Linux - Ubuntu14.04 wifi 信号 找不到
- avc格式
- OC01 类和对象 作业1