素材源码:http://download.csdn.net/download/swanzhu/8975259

效果图:

部分代码:

//
//  WarViewController.m
//  DaFeiJi
//
//  Created by mac on 15-8-7.
//  Copyright (c) 2015年 zhiyou. All rights reserved.
//#import "WarViewController.h"
#import "MyUIImageView.h"
@interface WarViewController ()@end@implementation WarViewController- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];if (self) {// Custom initialization}return self;
}- (void)viewDidLoad
{[super viewDidLoad];topImageView=[[UIImageView alloc] initWithImage:[UIImage imageNamed:@"bg.png"]];topImageView.frame=CGRectMake(0, -480, 320, 480);[self.view addSubview:topImageView];BottomImageView=[[UIImageView alloc] initWithImage:[UIImage imageNamed:@"bg.png"]];BottomImageView.frame=CGRectMake(0, 0, 320, 480);[self.view addSubview:BottomImageView];[NSTimer scheduledTimerWithTimeInterval:0.05 target:self selector:@selector(bgMove) userInfo:nil repeats:YES];//    战机heroImageView=[[UIImageView alloc] initWithImage:[UIImage imageNamed:@"plane1.png"]];heroImageView.frame=CGRectMake(120, 400, 60, 60);[self.view addSubview:heroImageView];NSArray *array=[[NSArray alloc]initWithObjects:[UIImage  imageNamed:@"plane1.png"],[UIImage  imageNamed:@"plane2.png"], nil];//    战机帧动画heroImageView.animationImages=array;heroImageView.animationDuration=0.2;heroImageView.animationRepeatCount=0;[heroImageView startAnimating];//   创建敌机enemyArray=[[NSMutableArray alloc] initWithCapacity:0];for (int i=0; i<20; i++) {enemyImageView=[[MyUIImageView alloc] initWithImage:[UIImage imageNamed:@"diji.png"]];enemyImageView.frame=CGRectMake(0, -50, 50, 50);enemyImageView.isUsed=NO;[enemyArray  addObject:enemyImageView];[self.view addSubview:enemyImageView];}//    敌机下落[NSTimer scheduledTimerWithTimeInterval:0.1 target:self selector:@selector(dijiDown) userInfo:nil repeats:YES];//    创建子弹zidanArray=[[NSMutableArray alloc] initWithCapacity:0];for (int i=0; i<30; i++) {zidanImageView=[[MyUIImageView alloc] initWithImage:[UIImage imageNamed:@"zidan.png"]];zidanImageView.frame=CGRectMake(-30, -30, 5, 5);zidanImageView.isUsed=NO;[zidanArray addObject:zidanImageView];[self.view addSubview:zidanImageView];}//    子弹下落[NSTimer scheduledTimerWithTimeInterval:0.02 target:self selector:@selector(zidanDown) userInfo:nil repeats:YES];//    碰撞}-(void)bgMove
{topImageView.frame=CGRectMake(0, topImageView.frame.origin.y+5, 320, 480);BottomImageView.frame=CGRectMake(0, BottomImageView.frame.origin.y+5, 320, 480);if (topImageView.frame.origin.y>=480) {topImageView.frame=CGRectMake(0, -480, 320, 480);}if (BottomImageView.frame.origin.y>=480) {BottomImageView.frame=CGRectMake(0, -480, 320, 480);}}-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{}-(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
{touch=[touches anyObject];point=[touch locationInView:self.view];heroImageView.center=point;}-(void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
{}-(void)dijiDown
{static int count=0;if (count%10==0) {for (int i=0; i<enemyArray.count; i++) {MyUIImageView *enemyImageView1=[enemyArray objectAtIndex:i];if (enemyImageView1.isUsed==NO) {enemyImageView1.frame=CGRectMake(arc4random()%270, -50, 50, 50);enemyImageView1.isUsed=YES;break;}}}count++;for (MyUIImageView *enemyImageView1 in enemyArray) {if (enemyImageView1.isUsed==YES) {enemyImageView1.frame=CGRectMake(enemyImageView1.frame.origin.x, enemyImageView1.frame.origin.y+5, 50, 50);if (enemyImageView1.frame.origin.y>480) {enemyImageView1.isUsed=NO;}}}}-(void)zidanDown
{static int count=0;if (count%10==0) {for (int i=0; i<zidanArray.count; i++) {MyUIImageView *zidanImageView1=[zidanArray objectAtIndex:i];if (zidanImageView1.isUsed==NO) {zidanImageView1.frame=CGRectMake(heroImageView.frame.origin.x+27, heroImageView.frame.origin.y-5, 10, 10);zidanImageView1.isUsed=YES;break;}}}count++;for (MyUIImageView *zidanImageView1 in zidanArray) {if (zidanImageView1.isUsed==YES) {zidanImageView1.frame=CGRectMake(zidanImageView1.frame.origin.x, zidanImageView1.frame.origin.y-5, 10, 10);if (zidanImageView1.frame.origin.y<-10) {zidanImageView1.isUsed=NO;}}}for (MyUIImageView *zidan in zidanArray) {if (zidan.isUsed==YES) {for (MyUIImageView *enemy in enemyArray) {if (enemy.isUsed==YES) {if (CGRectIntersectsRect(zidan.frame, enemy.frame)) {//zidan.frame=CGRectMake(-10, 0, 0, 0);zidan.isUsed=NO;//UIImageView *bg=[[UIImageView alloc]init];bg.frame=enemy.frame;NSMutableArray *imageArray=[[NSMutableArray alloc]initWithCapacity:0];for(int i=1;i<=5;i++){NSString *Baozha=[NSString stringWithFormat:@"bz%d",i];UIImage *Baozhaimage=[UIImage imageNamed:Baozha];[imageArray addObject:Baozhaimage];[self.view addSubview:bg];bg.animationImages=imageArray;bg.animationDuration=0.5;bg.animationRepeatCount=1;[bg startAnimating];enemy.frame=CGRectMake(0, -100, 0, 0);enemy.isUsed=NO;}}}}}}}- (void)didReceiveMemoryWarning
{[super didReceiveMemoryWarning];// Dispose of any resources that can be recreated.
}@end

(素材源码)swanzhu学IOS(三)打飞机相关推荐

  1. (素材源码) 猫猫学iOS 之UIDynamic重力、弹性碰撞吸附等现象PS有惊喜

    猫猫分享,必须精品 原创文章,欢迎转载.转载请注明:翟乃玉的博客 地址:http://blog.csdn.net/u013357243 一:效果 二:代码 #import "ViewCont ...

  2. (素材源码) 猫猫学IOS(十二)UI之UITableView学习(上)LOL英雄联盟练习

    猫猫分享,必须精品 素材代码地址:http://download.csdn.net/detail/u013357243/8542789 原文地址:http://blog.csdn.net/u01335 ...

  3. (素材源码)猫猫学IOS(十七)UI之纯代码自定义Cell实现新浪微博UI

    猫猫分享,必须精品 素材代码地址:http://download.csdn.net/detail/u013357243/8580249 原文地址:http://blog.csdn.net/u01335 ...

  4. (素材源码)猫猫学IOS(十四)UI之UITableView扩充_表格的修改_(增删移动)

    猫猫分享,必须精品 素材代码地址:http://download.csdn.net/detail/u013357243/8544315 原文地址:http://blog.csdn.net/u01335 ...

  5. (素材源码)猫猫学IOS(十五)UI之曾经大热的打砖块小游戏

    猫猫分享,必须精品 素材代码地址:http://download.csdn.net/detail/u013357243/8555567 原文地址:http://blog.csdn.net/u01335 ...

  6. (素材源码)猫猫学IOS(十八)UI之QQ聊天布局_键盘通知实现自动弹出隐藏_自动回复

    猫猫分享,必须精品 素材代码地址:http://download.csdn.net/detail/u013357243/8585703 原文地址:http://blog.csdn.net/u01335 ...

  7. cocos creator2.3.5休闲游戏英文版(连连看)源码H5+安卓+IOS三端源码

    cocos creator2.3.5休闲游戏英文版(连连看)源码H5+安卓+IOS三端源码,开发脚本为typeScript方便扩展和阅读,支持cocos creator2.X版本,完整的源码可直接运营 ...

  8. cocos creator3.3.0休闲游戏(云浮消消乐)源码H5+安卓+IOS三端源码

    cocos creator3.3.0休闲游戏(云浮消消乐)源码H5+安卓+IOS三端源码,开发脚本为typeScript方便扩展和阅读,支持cocos creator3.X版本,完整的源码可直接运营. ...

  9. 休闲游戏合成植物打僵尸源码-H5+安卓+IOS三端源码

    游戏引擎:Cocos Creator 2.3.3 编程语言:TypeScript cocos creator休闲游戏合成植物打僵尸源码-H5+安卓+IOS三端源码,开发脚本为javaScript方便扩 ...

  10. cocos creator经典游戏英文版《俄罗斯方块》源码H5+安卓+IOS三端源码

    cocos creator2.2.2经典游戏英文版<俄罗斯方块>源码H5+安卓+IOS三端源码,开发脚本为typeScript方便扩展和阅读,支持cocos creator2.X版本,完整 ...

最新文章

  1. 前端开发实习生的第一天
  2. 【深度学习】深度学习语义分割理论与实战指南.pdf
  3. npm:can not find module 'xxx'
  4. opencv2.4.9报错找不到opencv_video249d.dll
  5. gba徽章机器人_《徽章机器人》倒计时网站开启 20周年纪念插画欣赏
  6. 计算机组成原理—Cache和主存的映射模式
  7. pyton 编写脚本检测两台主机之间的通信状态,异常邮件通知
  8. vm虚拟机安装gho系统_虚拟机怎么安装gho系统
  9. 2011年中国大陆十佳IC设计公司
  10. 教你一招恢复100分信用分,新手违规被扣40分,还有救吗?
  11. 潮汕明代皇封御葬古墓受损追踪:当地相关部门介入
  12. 计算机专业学什么代码,计算机科学与技术专业代码,本科计算机科学与技术专业代码查询...
  13. java图片透明度,Java检查图像是否具有透明度
  14. springMVC+mybatis+maven搭建过程
  15. 冰湖,风筝,喜鹊,跳水台
  16. Selective Search原理及实现
  17. 微信开发 事件 trim subscribe
  18. 小学奥数思维训练题(十二)
  19. 温莎牛顿高级油画颜料简介
  20. 7-11前常务董事碓井诚:7-11的数字化对中国零售行业有哪些借鉴意义

热门文章

  1. 易语言大漠一键登录实现自动输入账号密码
  2. mysql数据库,语法语句总结。以及事务理解-基础篇
  3. Modern CMake 简介
  4. 初识Modern UI for WPF
  5. Typora使用技巧
  6. 红蜘蛛显示器测试软件,红蜘蛛5校色仪怎么用?显示器校色及测试色域和色彩精准度详细教程...
  7. VS安装包下载和环境配置
  8. 算力测试Linux,附录:计算力的标准Linpack测试详细指南(1)
  9. 贝叶斯网络经典matlab源代码解析
  10. 《药物设计学》单词表