C语言实现Flappy Bird小游戏
作者:一个全栈游戏开发者 发布时间:2022-03-13 13:56:24
标签:C语言,Flappy,Bird
本文实例为大家分享了C语言实现Flappy Bird小游戏的具体代码,供大家参考,具体内容如下
#include<stdio.h>
#include<stdlib.h>
#include<conio.h>
#include<time.h>
#include<Windows.h>
/********函数变量声明********/
#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");
}
来源:https://blog.csdn.net/themagickeyjianan/article/details/39935095


猜你喜欢
- static和@Component遇到的bug今天在编写util的时候,发现不能调用到工具类里面的方法,转眼一看,原来不是工具类里面的方法是
- 一、SpringBoot 指定配置文件路径:在 SpringBoot 中,可以将配置文件放在 jar 包外面,这样可以方便地修改配置而不需要
- 本文项目为大家分享了C#实现点餐系统,供大家参考,具体内容如下项目介绍:一家店铺使用的外卖点餐系统本项目分三大模块:登录注册模块,用户模块,
- 其实很简单,就是把我们的数据库文件放到我们的手机里,所以不必局限在哪个地方写这个代码,在第一次创建数据库的时候可以,我觉得在软件起动页里效果
- 我个人是比较喜欢逛贴吧的,贴吧里总是会有很多搞笑的动态图片,经常看一看就会感觉欢乐很多,可以释放掉不少平时的压力。确实,比起一张单调的图片,
- 网络通信协议中的UDP通信是无连接通信,客户端在发送数据前无需与服务器端建立连接,即使服务器端不在线也可以发送,但是不能保证服务器端可以收到
- 简单版/** * 产生4位随机数(0000-9999) * * @return 4位随机数 &nb
- 环境变量这个概念不陌生, 就是操作系统的环境变量。系统变量就是java本身维护的变量。 通过 System.getProperty 的方式获
- spring-AOP 及 AOP获取request各项参数AOP称为面向切面编程,在程序开发中主要用来解决一些系统层面上的问题,比如日志,事
- java 高并发中volatile的实现原理摘要: 在多线程并发编程中synchronized和Volatile都扮演着重要的角色,Vola
- 本篇分析ArrayList的源码,在分析之前先跟大家谈一谈数组。数组可能是我们最早接触到的数据结构之一,它是在内存中划分出一块连续的地址空间
- 前言SSL Socket通讯是对socket的扩展,增加Socket通讯的数据安全性,SSL认证分为单向和双向认证。单向认证只认证服务器端的
- Java包装类基本类型大小包装器类型boolean/Booleanchar16bitBooleanbyte8bitByteshort/16b
- C#生成指定范围内的不重复随机数// Number随机数个数// minNum随机数下限// maxNum随机数上限public int[]
- 目录一 、EasyExcel简介二、常用注解三、依赖四、监听五、接口导入Excel六、接口 导出Excel (HttpServletResp
- 在讲述这个模式之前,我们先看一个案例:游戏回档游戏的某个场景,一游戏角色有生命力、攻击力、防御力等数据,在打Boss前和后会不一样,我们允许
- 最近在开发中遇到了这样一个问题,在下拉刷新组件中包含了一个轮播图组件,当左右滑动的图片时很容易触发下拉刷新,如下图所示:如图中红色箭头所示方
- 1.字符串值中包含E等科学计数法,比如12E-2,需要进行转化为普通数值0.12,2.转化函数如下: private Decima
- 快速排序是应用最广泛的排序算法,流行的原因是它实现简单,适用于各种不同情况的输入数据且在一般情况下比其他排序都快得多。快速排序是原地排序(只
- java异常分为两大类,Checked异常和Runtime异常,Checked异常都是在编译阶段可以被处理的异常。Checked异常和Run