1 Star 0 Fork 0

李凌志 / llz

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
515.cpp 1.85 KB
一键复制 编辑 原始数据 按行查看 历史
李凌志 提交于 2019-06-12 22:27 . 515
#define _CRT_SECURE_NO_WARNINGS
#include <conio.h>
#include <graphics.h>
#include <conio.h>
//引用Windows Multimedia API
#pragma comment (lib,"Winmm.lib")
IMAGE img_bk, img_bd1, img_bd2, img_bar_up1, img_bar_up2, img_bar_down1, img_bar_down2;
int bird_x;
int bird_y;
void startup()
{
initgraph(350, 600);
loadimage(&img_bk, "D:\\background.jpg");
loadimage(&img_bd1, "D:\\bird1.jpg");
loadimage(&img_bd2, "D:\\bird2.jpg");
loadimage(&img_bar_up1, "D:\\bar_up1.gif");
loadimage(&img_bar_up2, "D:\\bar_up2.gif");
loadimage(&img_bar_down1, "D:\\bar_down1.gif");
loadimage(&img_bar_down2, "D:\\bar_down2.gif");
bird_x = 50;
bird_y = 200;
BeginBatchDraw();
mciSendString("open D:\\background.mp3 alias bkmusic", NULL, 0, NULL); //打开背景音乐
mciSendString("play bkmusic repeat", NULL, 0, NULL); //循环播放
}
void show()
{
putimage(0, 0, &img_bk); //显示背景
putimage(150, -300, &img_bar_up1, NOTSRCERASE); //显示上面一半的障碍物
putimage(150, -300, &img_bar_up2, SRCINVERT);
putimage(150, 400, &img_bar_down1, NOTSRCERASE); //显示下面一半的障碍物
putimage(150, 400, &img_bar_down2, SRCINVERT);
putimage(bird_x, bird_y, &img_bd1, NOTSRCERASE); //显示小鸟
putimage(bird_x, bird_y, &img_bd2, SRCINVERT);
FlushBatchDraw();
Sleep(50);
}
void updateWithoutInput()
{
if (bird_y < 500)
bird_y = bird_y + 3;
}
void updateWithInput()
{
char input;
if (kbhit())
{
input = getch();
if (input == ' ' && bird_y > 20)
{
bird_y = bird_y - 60;
mciSendString("close jpmusic", NULL, 0, NULL); //先把前面一次的音乐关闭
mciSendString("open D:\\Jump.mp3 alias jpmusic", NULL, 0, NULL); //打开音乐
mciSendString("play jpmusic", NULL, 0, NULL); //仅播放一次
}
}
}
void gameover()
{
EndBatchDraw();
getch();
closegraph();
}
int main()
{
startup()
while (1)
{
show();
updateWithoutInput();
updateWithInput();
}
gameover();
return 0;
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
C
1
https://gitee.com/sanctions/llz.git
git@gitee.com:sanctions/llz.git
sanctions
llz
llz
master

搜索帮助

344bd9b3 5694891 D2dac590 5694891