现在的位置: 首页 > 综合 > 正文

ios小游戏:简易植物大战僵尸

2013年02月19日 ⁄ 综合 ⁄ 共 1387字 ⁄ 字号 评论关闭

一、贴图为快

 

 

 

玩法: 如果杀死10个僵尸,通过次关;点击进入下一关时,僵尸的速度变大。

         如果家里进来15只僵尸,则输了,重玩此关。

         点击杀死僵尸时播放音频,输赢也有音频播放,有背景音乐。 

 

 

二、业务逻辑及知识点

 

1.主要由两个类来完成,类1:主页面显示类RootViewController:UIImageView;类2:僵尸类:ZombieView:UIImageView。

2.播放音频类:#import <AVFoundation/AVAudioPlayer.h> ,需要添加,

 

 

NSString *deadPath = [[NSBundle mainBundle] pathForResource:@"lose" ofType:@"mp3"];
    NSURL *deadUrl = [NSURL fileURLWithPath:deadPath];
    deadPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:deadUrl error:nil];
    [deadPlayer prepareToPlay];

     

 3.提醒框:

 UIAlertView* alert=[[UIAlertView alloc] initWithTitle:@"输 啦! !" message:@"你输了!" delegate:nil cancelButtonTitle:@"确认!" otherButtonTitles:nil];
[alert show];

[alert release]; 

4. 导入包,一般放到.m文件中,防止交叉编译

5.计时器,

   timer = [NSTimer  scheduledTimerWithTimeInterval:time target:self 

                                            selector:@selector(move) userInfo:nil repeats:YES]; 

 

 [timer invalidate];//停止计时器 

6.仿射变换(矩阵变换) 

                           
// 改变僵尸的大小

- (void)changeSize
{
    //难点,仿射变换(矩阵变换)
    CGAffineTransform t = CGAffineTransformMakeScale(2.0, 2.0);//Scale缩放
    //增大动画
    [UIView animateWithDuration:0.35 
                     animations:^{
                         self.transform = t;
    } completion:^(BOOL finished){
        //缩小动画
        [UIView animateWithDuration:0.35
                         animations:^{
                             CGAffineTransform t1 =
                             CGAffineTransformScale(self.transform, 0.5, 0.5);
                             self.transform = t1;
        } completion:^(BOOL finished) {
            [self removeFromSuperview];
        }];
    }];
}

 

 

抱歉!评论已关闭.