c语言flappy bird编程,C语言实现Flappy Bird小游戏
本文实例为大家分享了C语言实现Flappy Bird小游戏的具体代码,供大家参考,具体内容如下
#include
#include
#include
#include
#include
/********函数变量声明********/
#define PR_Box printf("■")
#define PR_Gold printf("★")
#define PR_Ag printf("☆")
#define PR_FBird printf("Ю")
#define PR_DBird printf("Ф")
#define PR_Land printf("┳┳┯")
#define PR_Bg_TL printf("╔")
#define PR_Bg_TR printf("╗")
#define PR_Bg_DL printf("╚")
#define PR_Bg_DR printf("╝")
#define PR_Bg_X printf("═")
#define PR_Bg_Y printf("║")
#define PR_Blank printf(" ");
int Grade = 1, C_Gold = 0, C_Ag = 0, Score = 0, Delay_time = 1000, Max_blank = 9, Distance = 18;
typedef struct Birds {
int x, y;
int condition;
}Birds;
Birds * Bird;
typedef struct Bg {
int x, y;
int l_blank;
int reward[9];
struct Bg * pri;
struct Bg * next;
}Bg;
Bg * Bg1;
void Position(int x, int y) {
COORD pos = {
x - 1, y - 1
};
HANDLE Out = GetStdHandle(STD_OUTPUT_HANDLE);
SetConsoleCursorPosition(Out, pos);
}
void CreatBird() {
Bird -> x = 41;
Bird -> y = 10;
Bird -> condition = 0;
}
void CreatBg() {
Bg * Bg2 = (Bg * ) malloc(sizeof(Bg));
Bg1 -> x = 90;
Bg1 -> y = 8;
Bg2 -> x = Bg1 -> x + Distance;
Bg2 -> y = 9;
Bg1 -> l_blank = Max_blank - Grade;
Bg2 -> l_blank = Max_blank - Grade;
Bg1 -> next = Bg2;
Bg1 -> pri = Bg2;
Bg2 -> next = Bg1;
Bg2 -> pri = Bg1;
}
void InsertBg(Bg * p) {
int temp;
Bg * Bgs = (Bg * ) malloc(sizeof(Bg));
Bgs -> x = p -> pri -> x + Distance;
Bgs -> l_blank = Max_blank - Grade;
srand((int) time(0));
temp = rand();
if (temp % 2 == 0) //++
{
if ((temp % 4 + p -> pri -> y + Max_blank - Grade) < 21)
Bgs -> y = p -> pri -> y + temp % 4;
else
Bgs -> y = p -> pri -> y;
} else {
if ((p -> pri -> y - temp % 4) > 2)
Bgs -> y = p -> pri -> y - temp % 4;
else
Bgs -> y = p -> pri -> y;
}
Bgs -> pri = p -> pri;
Bgs -> next = p;
p -> pri -> next = Bgs;
p -> pri = Bgs;
}
void Check_Bg(Bg * q) {
Bg * p = q;
int i = 0, temp;
while (++i <= 5) {
if (p -> x > -4)
p = p -> next;
else {
srand((int) time(0));
temp = rand();
if (temp % 2 == 0) //++
{
if ((temp % 4 + p -> y + Max_blank - Grade) < 21)
p -> y = p -> y + temp % 4;
else
p -> y = p -> y;
p -> x = p -> pri -> x + Distance;
p -> l_blank = Max_blank - Grade;
} else {
if ((p -> y - temp % 4) > 2)
p -> y = p -> y - temp % 4;
else
p -> y = p -> y;
p -> x = p -> pri -> x + Distance;
p -> l_blank = Max_blank - Grade;
}
}
}
}
void Loop_Bg(Bg * q) {
Bg * p = q;
int i = 0;
while (++i <= 5) {
p -> x = p -> x - 1;
p = p -> next;
if (Bird -> x == p -> x) {
Score += 1;
if (Score % 4 == 0 && Grade < 4)
Grade++;
}
}
}
void Prt_Bg(Bg * q) {
Bg * p = q;
int i = 0, k, j;
while (++i <= 5) {
if (p -> x > 0 && p -> x <= 78) {
for (k = 2; k < p -> y; k++) {
Position(p -> x + 1, k);
PR_Box;
PR_Box;
PR_Blank
}
Position(p -> x, p -> y);
PR_Box;
PR_Box;
PR_Box;
PR_Blank;
Position(p -> x, p -> y + p -> l_blank);
PR_Box;
PR_Box;
PR_Box;
PR_Blank;
k = k + p -> l_blank + 1;
for (k; k <= 22; k++) {
Position(p -> x + 1, k);
PR_Box;
PR_Box;
PR_Blank;
}
Position(p -> x, 23);
for (k = 1; k < Distance / 3 - 2; k++)
PR_Land;
}
p = p -> next;
if (p -> x == 0) {
for (j = 2; j < p -> y; j++) {
Position(p -> x + 1, j);
PR_Blank;
PR_Blank;
}
Position(p -> x + 1, p -> y);
PR_Blank;
PR_Blank;
PR_Blank;
Position(p -> x + 1, p -> y + Max_blank - Grade);
PR_Blank;
PR_Blank;
PR_Blank;
j = j + Max_blank - Grade + 1;
for (j; j <= 22; j++) {
Position(p -> x + 1, j);
PR_Blank;
PR_Blank;
}
}
}
}
void PrtBg() {
int i;
Position(1, 1);
PR_Bg_TL;
Position(79, 1);
PR_Bg_TR;
Position(1, 24);
PR_Bg_DL;
Position(79, 24);
PR_Bg_DR;
for (i = 3; i <= 78; i += 2) {
Position(i, 1);
PR_Bg_X;
Position(i, 24);
PR_Bg_X;
}
}
void PrtBird() {
Position(Bird -> x, Bird -> y - 1);
PR_Blank;
Position(Bird -> x, Bird -> y);
PR_FBird;
Position(38, 2);
printf("Score:%d", Score);
}
int CheckYN(Bg * q) {
Bg * p = q;
int i = 0;
while (++i <= 5) {
if (Bird -> y > 23)
return 0;
if (Bird -> x == p -> x && Bird -> y <= p -> y)
return 0;
if ((Bird -> x == p -> x || Bird -> x == p -> x + 1 || Bird -> x == p -> x + 2) && Bird -> y == p -> y)
return 0;
if (Bird -> x == p -> x && Bird -> y > p -> y + p -> l_blank)
return 0;
if ((Bird -> x == p -> x || Bird -> x == p -> x + 1 || Bird -> x == p -> x + 2) && Bird -> y == p -> y +
p -> l_blank)
return 0;
p = p -> next;
}
return 1;
}
void Prtfirst() {
printf("══════════════════════════════════════\n");
printf(" ■■ ■■\n");
printf(" ■■ ■■\n");
printf(" ■■ ■■ C语言版 Flappy Bird\n");
printf(" ■■ ■■ 瞎搞人:yyposs\n");
printf(" ■■ ■■ 瞎搞日期:2014.2\n");
printf(" ■■ ■■ 耗时:4小时\n");
printf(" ■■■ ■■ 游戏说明:\n");
printf(" ■■ 1-按上箭头使鸟起飞\n");
printf(" ■■ 2-等级越高,难度越大!\n");
printf(" Ю ■■■\n");
printf("\n");
printf(" ■■■ 欢迎各路大神一起探讨\n");
printf(" ■■\n");
printf(" ■■\n");
printf(" ■■ ■■■ 【无版权,随意修改】\n");
printf(" ■■ ■■\n");
printf(" ■■ Ф ■■\n");
printf(" ■■ ■■\n");
printf(" ■■ ■■\n");
printf(" ■■ ■■\n");
printf(" ■■ ■■\n");
printf(" ┳┳┯┳┳┯┳┳┯┳┳┯┳┳┯┳┳┯┳┳┯┳┳┯┳┳┯┳┳┯┳┳┯┳┳┯┳\n");
system("pause");
Position(1, 1);
int i = 0;
while (i++ < 40 * 25)
PR_Blank;
}
void main() {
int i = 0;
Bird = (Birds * ) malloc(sizeof(Birds));
Bg1 = (Bg * ) malloc(sizeof(Bg));
Prtfirst();
PrtBg();
CreatBg();
InsertBg(Bg1);
InsertBg(Bg1);
InsertBg(Bg1);
CreatBird();
while (1) {
if (!CheckYN(Bg1))
break;
Check_Bg(Bg1);
Prt_Bg(Bg1);
PrtBird();
Loop_Bg(Bg1);
Bird -> y = Bird -> y + 1;
if (GetAsyncKeyState(VK_UP)) {
Position(Bird -> x, Bird -> y - 1);
PR_Blank;
Bird -> y = Bird -> y - 4;
}
while (i++ < 500); {
Sleep(100);
}
i = 0;
}
Position(38, 10);
printf("You Lost!");
Position(1, 25);
system("pause");
}
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持我们。
c语言flappy bird编程,C语言实现Flappy Bird小游戏相关推荐
- c语言扔骰子随机数的相加,C语言编程学习:制作掷骰子小游戏
C语言是面向过程的,而C++是面向对象的 C和C++的区别: C是一个结构化语言,它的重点在于算法和数据结构.C程序的设计首要考虑的是如何通过一个过程,对输入(或环境条件)进行运算处理得到输出(或实现 ...
- C语言编程学习:制作掷骰子小游戏!超适合新手的练手项目!
C语言是面向过程的,而C++是面向对象的 C和C++的区别: C是一个结构化语言,它的重点在于算法和数据结构.C程序的设计首要考虑的是如何通过一个过程,对输入(或环境条件)进行运算处理得到输出(或实现 ...
- 基于C语言Ncurse库和链表的简单贪吃蛇小游戏
参考:基于C语言Ncurse库和链表的简单贪吃蛇小游戏 作者:三速何时sub20 发布时间:2020-09-29 10:23:51 网址:https://blog.csdn.net/weixin_44 ...
- c语言 源程序代码,编程(C语言源程序代码)
编程(C语言源程序代码) 已知 S=1+1/(1+2)+1/(1+2+3)+-+1/(1+2+3+-+N) ,当N的值为50时,求S的值. 要求:按四舍五入的方式精确到小数点后第四位. #includ ...
- jdy40程序C语言,lr脚本编程C语言.docx
lr脚本编程C语言.docx 1.define COUNT 100define SALARY 4000Actionint total;totalCOUNT*SALARY;lr_output_messa ...
- C语言、C++与Java分别实现猜数字小游戏
系统自动生成一个随机整数(1-100), 然后由用户输入一个猜测的数字. 如果输入的数字比该随机数小, 提示 "Too small!!!", 如果输入的数字比该随机数大, 提示 & ...
- 3d游戏编程大师技巧 源代码_C/C++编程入门基础系列:俄罗斯方块小游戏制作,直接源代码分享...
这篇文章主要为大家详细介绍了C语言实现俄罗斯方块小游戏,具有一定的参考价值,感兴趣的小伙伴们可以参考一下 1.要先下载一个 graphics.h 的头文件来绘图. 2.初始化窗口:initgraph( ...
- c语言i o编程,C 语言输入输出 (I/O)
C 语言输入输出 (I/O) 在本教程中,您将学习如何使用scanf()函数从用户处获取输入,并使用printf()函数向用户显示输出. C 语言输出 在C语言编程中,printf()是主要的输出函数 ...
- python语言支持函数式编程_Python语言之Pyhton入门笔记函数式编程
本文主要向大家介绍了Python语言之Pyhton入门笔记函数式编程,通过具体的内容向大家展示,希望对大家学习Python语言有所帮助. 一,匿名函数 def add(x,y) return x+y ...
- c 语言 结构体 编程,C语言:结构体的编程问题(很简单)
C语言:结构体的编程问题(很简单) 答案:2 信息版本:手机版 解决时间 2020-07-25 02:18 已解决 2020-07-24 02:27 先定义一个结构体Student,它包含四个成员: ...
最新文章
- 网管应当如何管理Windows操作系统
- dedecms织梦系统后台验证码图片不显示的解决方法
- 从零开始搭建Android框架系列
- 高通 MSM8K bootloader : SBL1 .
- Arithmetic图像处理halcon算子持续更新
- 终端mysql Operation not permitted错误解决方案
- 【干货】全球大数据领域顶级开源工具汇总
- 在ie6下remove包含iframe的table所在的容器,会导致页面控件的焦点诡异丢失。
- 20145321 《Java程序设计》第4周学习总结
- 佳能hdr_多方位升级 佳能发布数码单反相机新品EOS 850D
- java 对象深拷贝_java深入理解浅拷贝和深拷贝
- ChartControl控件
- 机器学习中的数学(八):卡方分布(Chi-squared Distribution) t分布(T Distribution)F分布(T Distribution)
- YY语音CTO赵斌的技术创业
- h5游戏抽奖游戏源码_抽奖扑克游戏
- XPAND恩帝泵800克健美补充剂,脂肪燃烧,激素原
- 在Ubuntu上安装和使用miniconda
- git 上传出现“ ! [rejected] master -> master (non-fast-forward)”
- USB-PD快充和QC快充的区别
- 不用分片也能扩展 10 倍性能?简单了解以太坊 Turbo-Geth 客户端