项目介绍:
之前看到过几次,感觉这小游戏很不错,今天写出来给大家分享一下。游戏很简单,初学者也能学会的。
#import "ViewController.h"
#define kWindowWidth [[UIScreen mainScreen] bounds].size.width
#define kWindowHeight [[UIScreen mainScreen] bounds].size.height
@interface ViewController ()
{
NSInteger floatWeight;
NSTimer *timer;
NSInteger fen;
}
@property (nonatomic ,strong) UIImageView *bgImg1;
@property (nonatomic ,strong) UIImageView *bgImg2;
@property (nonatomic ,strong) UIImageView *myPlane;
@property (nonatomic ,strong) NSMutableArray *diJiArray;
@property (nonatomic ,strong) NSMutableArray *ziDanArray;
@property (nonatomic ,strong) UIImageView *baozha;
@property (nonatomic ,strong) NSMutableArray *baozhaArray;
@property (nonatomic ,strong) UILabel *fenLab;
@end
内容主要围绕几个定时器来搞得。
fen = 0;
[self.view addSubview:self.bgImg1];
[self.view addSubview:self.bgImg2];
[self.view addSubview:self.myPlane];
[self.view addSubview:self.baozha];
[self.view addSubview:self.fenLab];
//创建控制地图移动的定时器
[NSTimer scheduledTimerWithTimeInterval:.05 target:self selector:@selector(mapMove) userInfo:nil repeats:YES];
//创建找敌机的定时器
[NSTimer scheduledTimerWithTimeInterval:.2 target:self selector:@selector(findDiJi) userInfo:nil repeats:YES];
//创建控制敌机下落的定时器
[NSTimer scheduledTimerWithTimeInterval:.05 target:self selector:@selector(downDiJi) userInfo:nil repeats:YES];
//创建找子弹的定时器
[NSTimer scheduledTimerWithTimeInterval:.1 target:self selector:@selector(findZiDan) userInfo:nil repeats:YES];
//发射子弹
[NSTimer scheduledTimerWithTimeInterval:0.05 target:self selector:@selector(fireZiDan) userInfo:nil repeats:YES];
//创建爆炸的定时器
timer = [NSTimer scheduledTimerWithTimeInterval:0.1 target:self selector:@selector(baoZha) userInfo:nil repeats:YES];