c语言愤怒的小鸟,C语言小游戏---画面愤怒的小鸟

这是一个使用C语言编写的飞行小鸟游戏的初始化和基本更新逻辑。代码中包含了游戏屏幕尺寸设置、图像加载、小鸟和栏杆的位置控制、游戏分数计算等功能。游戏循环中,小鸟会根据用户输入进行上飞,并自动下落,栏杆会不断移动以增加游戏难度。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

#include#include#include#include#include#include

#pragma comment(lib,"Winmm.lib")

int width, high; //screen dimention

IMAGE img_bk,img_bird,img_bird_1,img_bar_up,img_bar_up_1,img_bar_down,img_bar_down_1; //define image name

int bird_x, bird_y; //bird position

int bar_x, bar_up_y, bar_down_y; //bar position

int bird_fly_step,bird_down_step; //control step

intscore;void startup() { //init data

width = 432;

high= 675;

initgraph(width,high);//draw screen//load images

loadimage(&img_bk,"E:\\C程序练习\\project\\flightwar\\flappybird\\picture\\bk.jpeg");

loadimage(&img_bird,"E:\\C程序练习\\project\\flightwar\\flappybird\\picture\\bird.jpg");

loadimage(&img_bird_1,"E:\\C程序练习\\project\\flightwar\\flappybird\\picture\\bird_1.jpg");

loadimage(&img_bar_up,"E:\\C程序练习\\project\\flightwar\\flappybird\\picture\\bar_up2.gif");

loadimage(&img_bar_up_1,"E:\\C程序练习\\project\\flightwar\\flappybird\\picture\\bar_up1.gif");

loadimage(&img_bar_down,"E:\\C程序练习\\project\\flightwar\\flappybird\\picture\\bar_down2.gif");

loadimage(&img_bar_down_1,"E:\\C程序练习\\project\\flightwar\\flappybird\\picture\\bar_down1.gif");//bird position

bird_x = 100;

bird_y= 200;//bar position

bar_x = 250;

bar_up_y= -380;

bar_down_y= 350;//control bird step

bird_fly_step = 40;

bird_down_step= 13;

BeginBatchDraw();//play background music - repeat

mciSendString("open E:\\C程序练习\\project\\flightwar\\flappybird\\picture\\background.mp3 alias bkmusic",NULL,0,NULL);

mciSendString("play bkmusic repeat", NULL,0,NULL);

score= 0;

}void show() { //show windows

putimage(0,0,&img_bk); //show background picture

putimage(bird_x,bird_y,&img_bird_1,NOTSRCERASE); //show bird

putimage(bird_x,bird_y,&img_bird,SRCINVERT);

putimage(bar_x,bar_up_y,&img_bar_up_1,NOTSRCERASE); //show bar up

putimage(bar_x,bar_up_y,&img_bar_up,SRCINVERT);

putimage(bar_x,bar_down_y,&img_bar_down_1,NOTSRCERASE); //show bar down

putimage(bar_x,bar_down_y,&img_bar_down,SRCINVERT);

FlushBatchDraw();

}voidupdateWithoutInput() {if(bird_y

bird_y+=bird_down_step;if(bird_x==bar_x) {if(bird_y>bar_down_y-140 && bird_y

score++;else exit(0);

}if(bar_x>0) //move bar

bar_x-=13;else{

bar_x= width; //new bar

int randPosition = rand() % (high-50);

bar_up_y= randPosition - 670;

bar_down_y= randPosition + 70;

}

Sleep(150);

}voidupdateWithInput() {charinput;if(kbhit()) { //runing while user push keyboard

input =getch();if(input == ' ' && bird_y>20) //control bird move up

{

bird_y= bird_y -bird_fly_step;//bird fly with music

mciSendString("close jpmusic",NULL,0,NULL);

mciSendString("open E:\\C程序练习\\project\\flightwar\\flappybird\\picture\\Jump.mp3 alias jpmusic",NULL,0,NULL);

mciSendString("play jpmusic",NULL,0,NULL);

}

}

}voidgameover()

{

EndBatchDraw();//end batch picture

getch();

closegraph();//close graph

}intmain() {

startup();//init data

while(1) { //game loop run

show(); //show windows

updateWithoutInput(); //update don't need user

updateWithInput(); //update need user

}

gameover();return 0;

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值