代码拉取完成,页面将自动刷新
#include <graphics.h>
#include <conio.h>
#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, "C:\\fly bird\\background.jpg");
loadimage(&img_bd1, "C:\fly bird\\bird1.jpg");
loadimage(&img_bd2, "C:\\fly bird\\bird2.jpg");
loadimage(&img_bar_up1, "C:\\fly bird\\bar_up1.gif");
loadimage(&img_bar_up2, "C:\\fly bird\\bar_up2.gif");
loadimage(&img_bar_down1, "C:\\fly bird\\bar_down1.gif");
loadimage(&img_bar_down2, "C:\\fly bird\\bar_down2.gif");
bird_x = 50;
bird_y = 200;
BeginBatchDraw();
mciSendString("open C:\\fly bird\\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 C:\\fly bird\\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;
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。