Presentation is loading. Please wait.

Presentation is loading. Please wait.

Flappy bird 结题报告.

Similar presentations


Presentation on theme: "Flappy bird 结题报告."— Presentation transcript:

1 Flappy bird 结题报告

2 Flappybird 课题介绍 我们Flappybird小课题旨在制作一款敏捷类小游戏。
游戏规则:游戏中玩家必须控制一只胖乎乎的小鸟,跨越由各种不同长度水 管所组成的障碍。单击鼠标左键小鸟就会往上飞,不断的点击就会不断的往高 处飞。放松手指,小鸟则会快速下降。所以玩家要控制小鸟一直向前飞行,然 后注意躲避途中高低不平的管子,游戏的得分是,小鸟安全穿过一个柱子且不 撞上就是1分。当然撞上就直接死亡,游戏结束。

3 控制台版

4 二、qt版实现方案 在这款游戏中: 有柱子,小鸟,地面这几个游戏对象。
另外还需要设置游戏开始的开始界面,引导界面,游戏中显示分数的分数板, 游戏结束界面。 我们把qblock类,qground类,qbird类的声明统一写在qgameobject.h内,各个 类中函数的实现统一写在qgameobject.cpp内。下面逐一解说。

5 1.游戏对象柱子(block)的功能实现 在qgameobject.h内声明qblock类 public: prviate :
explicit qblock(QObject *parent = 0); static int randomnumber; void setrect(qreal,qreal,qreal,qreal); int Type; QRectF& getbindrect(); bool emited; void addframe(QPixmap); QRectF bindRect; void clearallframe(); int frameCount; void setEnabled(bool); QVector<QPixmap> pixmapList; void draw(QPainter *); bool enabled; void setType(int _type){Type=_type;} Void operate

6 2.游戏对象地面的实现 public: prviate :
explicit qground(QObject *parent = 0); int x1; void setrect(qreal,qreal,qreal,qreal); int x2; QRectF& getbindrect(); bool emited; void addframe(QPixmap); QRectF bindRect; void clearallframe(); int frameCount; void setEnabled(bool); QVector<QPixmap> pixmapList; void draw(QPainter *); bool enabled; Void operate

7 3.游戏对象小鸟的实现 private: QRectF bindRect; int frameCount;
public: explicit qbird(QObject *parent = 0);   void setrect(QRectF); void setrect(qreal,qreal,qreal,qreal); QRectF& getbindrect(); void addframe(QPixmap); void clearallframe(); void setEnabled(bool); void operate()  void draw(QPainter *); void change(){up=false;} void sety(){y=200;} void setv(){v=0;} private: QRectF bindRect; int frameCount; QVector<QPixmap> pixmapList; bool enabled; qreal y ; qreal v; int n ; bool up;

8 4.小鸟与地面、柱子、天空等障碍的碰撞测试 birddead()信号 Intersect() 函数 Gameover槽函数

9 5游戏记分显示板 在mainwindows.h内添加一个QLCDNumber:socredisplay
scoredisplay= new QLCDNumber(3,this); scoredisplay->setGeometry(152,40,80,50); scoredisplay->setLineWidth(0); scoredisplay->setStyleSheet("QLCDNumber{color: white}"); scoredisplay->setVisible(false); void MainWindow::addscore() { gamescore++; scoredisplay->display(QString("%1").arg(gamescore,3,10,QChar('0')));}

10 6. 开始界面引导界面与游戏结束界面 1)开始界面
首先,创建C++文件Dialog.h与Dialog.cpp,专门编写开始界面的程序。在 Dialog类中加pushButton函数。 然后,在Dialog.cpp中完成对该函数的实现。其中如果pushButton clicked() 被激 发,QDialog发出accepted的信号 最后,在main.cpp中做相应更改 2)引导界面 引导界面要实现的功能比较简单,只需在开始界面的开始按钮被按下后显示, 而Game over 重新开始游戏时不显示。在Mainwindow类中加入私有成员start, 以记录游戏是否开始;若为未开始状态,第一次单击鼠标左键时显示画面。

11 6. 开始界面引导界面与游戏结束界面 3)游戏结束界面
用start记录游戏是否开始,用decide记录小鸟是否死亡。并根据所得分数显示 相应奖牌。

12 7. 初始化 游戏开始,分数为0 加载背景 设置分数显示板 创建游戏对象地面 创建游戏对象柱子 创建游戏对象小鸟  连接信号和槽机制

13 8. 常量处理 (省略单位:像素) 开始界面:550*399 游戏界面:384*512 小鸟大小:45*45 每帧间隔时间:30毫秒
柱子每帧移动距离:6 小鸟加速度:1像素点/30毫秒

14

15

16

17 总结与体会 1:控制台应用到可视化界面 2:游戏对象的移动 3:碰撞判断 4:参考书籍与文档: 《QT Creator快速入门》
Jasmin.Blanchette Mark.Summerfield 《C++ GUI QT4编程》 《Qt及Qt Quick开发实战精解》 《Qt 高级编程》等 以及网上的博客


Download ppt "Flappy bird 结题报告."

Similar presentations


Ads by Google