代码拉取完成,页面将自动刷新
#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;
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。