C语言怎么实现简易版flappybird小游戏

  • 时间:
  • 浏览:67
  • 来源:恰卡网

导读小编给大家分享一下C语言怎么实现简易版flappy bird小游戏,相信大部分人都还不怎么了解,因此分享这篇文章给大家参考一下,希望大家阅读完这篇文章后大有收获,下面让我们一起去了解一...

小编给大家分享一下C语言怎么实现简易版flappy bird小游戏,相信大部分人都还不怎么了解,因此分享这篇文章给大家参考一下,希望大家阅读完这篇文章后大有收获,下面让我们一起去了解一下吧!

游戏界面如下:

思路很简单,整个游戏界面是由一个大的char类型数组构成,更新数组的值然后不停的打印出来就形成了动态效果。

由上图看,大循环是保证游戏一直不断的进行下去,小循环是让小鸟的速度大于游戏界面里背景(由#构成的柱子)的速度(小鸟动四下柱子才动一下)。

下面是具体代码(水平有限大家多多见谅,但是效果还是有的!)

Bird.c文件

#include
#include
#include"Interface.h"

intmain(void)
{
InitialInterface();
for(;;)
{
newinterface();
scoring();//过一个柱子计一次分,所以和柱子更新速度一致
for(inti=0;i<4;i++)//小鸟的速度是柱子的4倍
{
birdmove();
draw();
Sleep(50);
}
}
return0;
}

Interface.h文件

#ifndefINTERFACE_H
#defineINTERFACE_H

#defineM20
#defineN36

voidInitialInterface(void);
voidnewinterface(void);
voidbirdmove(void);
voidscoring(void);
voiddraw(void);

#endif

Interface.c文件

#include
#include
#include
#include"interface.h"


charinterf[M][N]={{32,32,32,32,32,32,32,32,32,32,35,35,32,32,32,32,32,32,32,32,32,32,35,35,32,32,32,32,32,32,32,32,32,32,35,35},
{32,32,32,32,32,32,32,32,32,32,35,35,32,32,32,32,32,32,32,32,32,32,35,35,32,32,32,32,32,32,32,32,32,32,35,35},
{32,32,32,32,32,32,32,32,32,32,35,35,32,32,32,32,32,32,32,32,32,32,35,35,32,32,32,32,32,32,32,32,32,32,35,35},
{32,32,32,32,32,32,32,32,32,32,35,35,32,32,32,32,32,32,32,32,32,32,35,35,32,32,32,32,32,32,32,32,32,32,35,35},
{32,32,32,32,32,32,32,32,32,32,35,35,32,32,32,32,32,32,32,32,32,32,35,35,32,32,32,32,32,32,32,32,32,32,35,35},
{32,32,32,32,32,32,32,32,32,32,35,35,32,32,32,32,32,32,32,32,32,32,35,35,32,32,32,32,32,32,32,32,32,32,35,35},
{32,32,32,32,32,32,32,32,32,32,35,35,32,32,32,32,32,32,32,32,32,32,35,35,32,32,32,32,32,32,32,32,32,32,35,35},
{32,32,32,32,32,32,32,32,32,32,35,35,32,32,32,32,32,32,32,32,32,32,35,35,32,32,32,32,32,32,32,32,32,32,35,35},
{32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,35,35,32,32,32,32,32,32,32,32,32,32,32,32},
{32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,35,35,32,32,32,32,32,32,32,32,32,32,32,32},
{38,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32},
{32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32},
{32,32,32,32,32,32,32,32,32,32,35,35,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,35,35},
{32,32,32,32,32,32,32,32,32,32,35,35,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,32,35,35},
{32,32,32,32,32,32,32,32,32,32,35,35,32,32,32,32,32,32,32,32,32,32,35,35,32,32,32,32,32,32,32,32,32,32,35,35},
{32,32,32,32,32,32,32,32,32,32,35,35,32,32,32,32,32,32,32,32,32,32,35,35,32,32,32,32,32,32,32,32,32,32,35,35},
{32,32,32,32,32,32,32,32,32,32,35,35,32,32,32,32,32,32,32,32,32,32,35,35,32,32,32,32,32,32,32,32,32,32,35,35},
{32,32,32,32,32,32,32,32,32,32,35,35,32,32,32,32,32,32,32,32,32,32,35,35,32,32,32,32,32,32,32,32,32,32,35,35},
{32,32,32,32,32,32,32,32,32,32,35,35,32,32,32,32,32,32,32,32,32,32,35,35,32,32,32,32,32,32,32,32,32,32,35,35},
{32,32,32,32,32,32,32,32,32,32,35,35,32,32,32,32,32,32,32,32,32,32,35,35,32,32,32,32,32,32,32,32,32,32,35,35},};
//初始界面矩阵,ASCII码中“”是32,“&”是38表示小鸟,“#”是35用来画柱子

intnum=0;//用于计数输出并排两列黑柱子同一位置
intblack;//黑方块位置
intp=M/2;//小鸟初始位置
intscore=0;//分数

/*初始化界面*/
voidInitialInterface(void)
{
printf("\n作者:xhyang,博客地址:http://blog.csdn.net/weixin_39449570\n");
printf("按\"w\"使小鸟跳起来,别落地,顺利穿过尽可能多的柱子!\n");
for(inti=0;i(black+5)))//此时上面的第二列变成了第一列,更新下一个黑柱子,有了黑柱子上半部分位置+5即是下半部分的起始位置
{
interf[i][N-1]=35;
}
else
{
interf[i][N-1]=32;
}
}
if(num>0)
num--;
}


/*更新小鸟位置*/
voidbirdmove(void)
{
for(inta=0;a<3;a++)
{
if(a==2&&p>0)//减缓鸟的速度,使按键上跳速度是下落的4倍
{
p=p+1;
}
if(_kbhit())
{
if(_getch()=='w'||_getch()=='W')
{
p=p-3;
}
}
}
}

/*计分*/
voidscoring(void)
{
if(p>20||interf[p][0]==35)
{
system("cls");
printf("\n\n游戏结束!\n\n");
printf("最终得分:%d\n\n\n",score);
system("pause");
}

if(interf[0][0]==35&&interf[0][1]==32)
score++;
}

/*重画界面*/
voiddraw(void)
{
system("cls");
printf("\n作者:xhyang,博客地址:http://blog.csdn.net/weixin_39449570\n");
printf("按\"w\"使小鸟跳起来,别落地,顺利穿过尽可能多的柱子!\n");
for(inti=0;i

以上是“C语言怎么实现简易版flappy bird小游戏”这篇文章的所有内容,感谢各位的阅读!相信大家都有了一定的了解,希望分享的内容对大家有所帮助,如果还想学习更多知识,欢迎关注恰卡网行业资讯频道!

猜你喜欢

30个上古神话传说(有哪些神话故事)

有哪些神话故事(30个上古神话传说) 神话传说和民间传说,是一个民族和国家的宝贵精神财富,有多少是你没有听说过的,又或是耳熟能详的? 1.盘古开天 传说太古时候,天地不分,整个宇

2021-08-05

布达拉宫简介(布达拉宫资料大全)

布达拉宫资料大全(布达拉宫简介) 布达拉宫坐落于西藏拉萨中心的红山之上,海拔3700余米,建筑总面积13万余平方米,主楼高115.703米,共13层,是西藏地区现存规模最大,样式最全,保存最

2021-08-05

小额投资理财项目有哪些?(小额投资理财有哪几种)

小额投资理财有哪几种?(小额投资理财项目有哪些?) 投资成为了人们比较热衷的事情,普通人也都参与进来,但是普通的人投资跟真正的投资人投资又是有很大的区别的。对于普通人而言

2021-08-05

世界上最美十座桥梁都有哪些?(世界十大最美大桥排行榜)

世界十大最美大桥排行榜(世界上最美十座桥梁都有哪些?) 桥梁是人类所建造的最古老、最壮观、最美丽的建筑工程之一。历史上著名的桥梁,都以鲜明的形象、强烈的艺术感染力,反映了

2021-08-05