1 Star 0 Fork 0

Plan-B/我的仓库

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
feijidazhan2.0.cpp 1.88 KB
一键复制 编辑 原始数据 按行查看 历史
Plan-B 提交于 2019-06-20 16:10 . 飞机大战2.0
#include <graphics.h>
#include <conio.h>
// 引用 Windows Multimedia API
#pragma comment(lib,"Winmm.lib")
#define High 864 // 游戏画面尺寸
#define Width 591
IMAGE img_bk; // 背景图片
int position_x,position_y; // 飞机位置
int bullet_x,bullet_y; // 子弹位置
IMAGE img_planeNormal1,img_planeNormal2; // 正常飞机图片
IMAGE img_bullet1,img_bullet2; // 子弹图片
void startup()
{
initgraph(Width,High);
loadimage(&img_bk, "D:\\background.jpg");
loadimage(&img_planeNormal1, "D:\\planeNormal_1.jpg");
loadimage(&img_planeNormal2, "D:\\planeNormal_2.jpg");
loadimage(&img_bullet1, "D:\\bullet1.jpg");
loadimage(&img_bullet2, "D:\\bullet2.jpg");
position_x = Width*0.5;
position_y = High*0.7;
bullet_x = position_x;
bullet_y = -85;
BeginBatchDraw();
}
void show()
{
putimage(0, 0, &img_bk); // 显示背景
putimage(position_x-50, position_y-60, &img_planeNormal1,NOTSRCERASE); // 显示正常飞机
putimage(position_x-50, position_y-60, &img_planeNormal2,SRCINVERT);
putimage(bullet_x-7, bullet_y, &img_bullet1,NOTSRCERASE); // 显示子弹
putimage(bullet_x-7, bullet_y, &img_bullet2,SRCINVERT);
Sleep(2);
}
void updateWithoutInput()
{
if (bullet_y>-25)
bullet_y = bullet_y-3;
}
void updateWithInput()
{
MOUSEMSG m; // 定义鼠标消息
while (MouseHit()) //这个函数用于检测当前是否有鼠标消息
{
m = GetMouseMsg();
if(m.uMsg == WM_MOUSEMOVE)
{
// 飞机的位置等于鼠标所在的位置
position_x = m.x;
position_y = m.y;
}
else if (m.uMsg == WM_LBUTTONDOWN)
{
// 按下鼠标左键,发射子弹
bullet_x = position_x;
bullet_y = position_y-85;
}
}
}
void gameover()
{
EndBatchDraw();
getch();
closegraph();
}
int main()
{
startup(); // 数据初始化
while (1) // 游戏循环执行
{
show(); // 显示画面
updateWithoutInput(); // 与用户输入无关的更新
updateWithInput(); // 与用户输入有关的更新
}
gameover(); // 游戏结束、后续处理
return 0;
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
C
1
https://gitee.com/songguanhao/laozis_warehouse.git
git@gitee.com:songguanhao/laozis_warehouse.git
songguanhao
laozis_warehouse
我的仓库
master

搜索帮助

Cb406eda 1850385 E526c682 1850385