Flappy Bird
来源:互联网 发布:例外女装淘宝 编辑:程序博客网 时间:2024/04/29 07:21
愤怒的小鸟这个游戏非常经典,火了很长一段时间
我们可以不借助第三方库进行实现,这里只是进行了一些简单的实现
没有添加碰撞检测 完成了一些功能 我们点击屏幕小鸟会飞
如果不点击小鸟会落下
这里用到的技术也很简单,用到了用户交互,transform 动画
#import "BirdViewController.h"//初速const float MaxTime = 30;//加速度 方向向下const float VG = 0.05;//初速度const float MaxV = 2.5;//初始化总路程const float AllLength = 692;typedef enum{ GameStart, GamePlaying, GameOver} GameState;@interface BirdViewController (){ NSTimer *birdTimer; //开始游戏开关 BOOL isStart; //游戏状态 GameState gameState; //小鸟 UIImageView *birdImgView; UIImageView *birdClotherView; //总场景 UIView *playLayer; //跳跃时间 float maxJumpTime;}@end@implementation BirdViewController- (void)viewDidLoad { [super viewDidLoad]; self.view.backgroundColor =[UIColor orangeColor]; [self initBirdAndOther]; birdTimer = [NSTimer scheduledTimerWithTimeInterval:0.008 target:self selector:@selector(update) userInfo:nil repeats:YES];}-(void)update{ //判断 if (isStart == YES && gameState == GamePlaying) { [self updateBird]; }}-(void)initBirdAndOther{ playLayer = [[UIView alloc]initWithFrame:self.view.bounds]; [self.view addSubview:playLayer]; //添加手势 UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(screenTap)]; [self.view addGestureRecognizer:tapGesture]; birdClotherView = (UIImageView *)[[UIView alloc]initWithFrame:CGRectMake(60, 300, 40, 30)]; [playLayer addSubview:birdClotherView]; //初始化小鸟 birdImgView = [[UIImageView alloc] init]; birdImgView.frame = CGRectMake(0, 0, 40, 28); birdImgView.image = [UIImage imageNamed:@"bird"]; [birdClotherView addSubview:birdImgView]; UILabel *label = [[UILabel alloc]init]; label.frame = CGRectMake(20, 30, 100, 30); label.text = @"愤怒的小鸟"; [self.view addSubview:label]; }-(void)screenTap{ //每点击一次 maxJumpTime = MaxTime; if (isStart == NO) { isStart = YES; gameState = GamePlaying; for (UIView *tmp in self.view.subviews) { [tmp removeFromSuperview]; } [self initBirdAndOther]; } CGAffineTransform transform = CGAffineTransformIdentity; birdImgView.transform = CGAffineTransformRotate(transform, -30 * M_PI / 180 );}- (void) updateBird{ maxJumpTime --; CGRect rect = birdClotherView.frame; if (maxJumpTime >= 0) { rect.origin.y = rect.origin.y - (MaxV - (MaxTime - maxJumpTime)*VG); } else { //俯角30度旋转 CGAffineTransform transform = CGAffineTransformIdentity; birdImgView.transform = CGAffineTransformRotate(transform, 30 * M_PI / 180 ); rect.origin.y = rect.origin.y - (maxJumpTime*VG); } birdClotherView.frame = rect; }@end
1 0
- flappy bird
- Flappy Bird
- flappy bird
- Flappy Bird
- flappy bird
- flappy bird
- flappy bird /C++
- HTML5 flappy bird
- 160行flappy bird
- Flappy bird源代码
- flappy bird大集集
- (难度:30%)flappy bird
- CRBM 玩flappy bird
- cocos2dx-flappy bird
- Flappy Bird ---game
- 洛谷P1941 Flappy Bird
- bzoj4723 [POI2017]Flappy Bird
- BZOJ4723 [POI2017]Flappy Bird
- 质数中的质数 SDUT 3305
- 机房收费系统总结篇(3)--------验收总结
- 17 Letter Combinations of a Phone Number
- centos 7.0 mysql的启动问题
- nginx负载均衡配置---nginx的学习之路
- Flappy Bird
- 开启java生活
- hdu5407CRB and Candies 求逆元
- 信息论基本公式汇总
- android存储空间以及文件权限
- 从迷茫到清晰,先被别人领,再被自己领——记8月英语
- 使用nginx的proxy_cache做网站缓存
- 关于C#下使用轻量级数据库的一些经验
- [python爬虫] Selenium常见元素定位方法和操作的学习介绍