欢迎光临
我们一直在努力

打飞机游戏

建站超值云服务器,限时71元/月

打飞机游戏

项目介绍:

模仿微信打飞机游戏,子弹打到敌机有碰撞效果,使用UIKit框架,以下为主要代码:

[Objective-C] 查看源文件 复制代码

//1.背景移动
-(void)beijing
{
    
    
    bg1 = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, ATGetDeviceWidth, ATGetDeviceHeight)];
    bg1.image = [UIImage imageNamed:@"bg"];
    [self.view addSubview:bg1];
    
    bg2 = [[UIImageView alloc] initWithFrame:CGRectMake(0, -480, ATGetDeviceWidth, ATGetDeviceHeight)];
    bg2.image = [UIImage imageNamed:@"bg"];
    [self.view addSubview:bg2];
    
    
    [NSTimer scheduledTimerWithTimeInterval:0.05 target:self selector:@selector(moveBackgroundView) userInfo:nil repeats:YES];
}
//2.战机
-(void)zhanji
{
    
    
    myPlane = [[UIImageView alloc] initWithFrame:CGRectMake(100, 300, 60, 70)];
    myPlane.image = [UIImage imageNamed:@"plane1"];
    [self.view addSubview:myPlane];
    
    NSArray* array = [[NSArray alloc] initWithObjects:[UIImage imageNamed:@"plane1"],[UIImage imageNamed:@"plane2"], nil];
    
    //帧动画
    myPlane.animationDuration = 0.2;
    myPlane.animationImages = array;
    [myPlane startAnimating];
}
//3.敌机
-(void)diji
{
    
    //敌机数组
    dijiArray = [[NSMutableArray alloc] initWithCapacity:0];
    for (int i = 0; i<20; i++) {
        //(1)初始位置:放置屏幕外
        UIImageView* diji = [[UIImageView alloc] initWithFrame:CGRectMake(arc4random()%(321-30), -30, 30, 30)];
        diji.image = [UIImage imageNamed:@"diji"];
        //(2)初始状态
        diji.tag = 0;//未使用
        [self.view addSubview:diji];
        [dijiArray addObject:diji];
    }
    //找敌机0.2、 移动敌机0.02
    [NSTimer scheduledTimerWithTimeInterval:0.05 target:self selector:@selector(findAndMoveDiji) userInfo:nil repeats:YES];
    

}
//4.子弹
-(void)zidan{
    
    
    zidanArray = [[NSMutableArray alloc] init];
    for (int i = 0; i<10; i++) {
        //(1)初始位置:放在屏幕外
        UIImageView* zidan = [[UIImageView alloc] initWithFrame:CGRectMake(0,-10, 3, 10)];
        zidan.image = [UIImage imageNamed:@"zidan"];
        //(2)初始状态
        zidan.tag = 0;//未使用
        [self.view addSubview:zidan];
        [zidanArray addObject:zidan];
    }
    //找子弹。移动子弹
    [NSTimer scheduledTimerWithTimeInterval:0.05 target:self selector:@selector(findAndMoveZidan) userInfo:nil repeats:YES];
}
赞(0)
版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com 特别注意:本站所有转载文章言论不代表本站观点! 本站所提供的图片等素材,版权归原作者所有,如需使用,请与原作者联系。未经允许不得转载:IDC资讯中心 » 打飞机游戏
分享到: 更多 (0)