当前位置:网站首页>C语言手写魂斗罗(一)
C语言手写魂斗罗(一)
2022-08-11 10:51:00 【程序员Rock】
目录
1. 项目介绍
使用C语言,手写魂斗罗经典游戏场景。
配套视频教程
视频讲解整个开发过程。
2. 游戏效果演示
为了避免违规,这里不做演示,可以直接在视频教程中查看完整效果。
3. 项目准备
VS2019+EasyX图形库
Easyx直接在easyx官网下载,然后双击安装。
4. 创建项目
使用vs2019创建一个空项目,并导入项目素材资源(留言邮箱地址获取)
素材目录res:

修改项目属性,把字符集修改为多字节字符集:

5. 实现游戏的启动界面
先导入工具文件tools.h和tools.cpp 。
#include <stdio.h>
#include <graphics.h>
#include "tools.h"
#define WIN_WIDTH 1400
#define WIN_HEIGHT 600
IMAGE imgWelcome;
IMAGE imgStartNormal;
IMAGE imgStartPress;
IMAGE imgBg;
void loadResources() {
char name[128];
initgraph(WIN_WIDTH, WIN_HEIGHT);
loadimage(&imgBg, "res/bg.png");
loadimage(&imgWelcome, "res/welcome.png");
loadimage(&imgStartNormal, "res/start_normal.png");
loadimage(&imgStartPress, "res/start_press.png");
}
void updateWindow() {
putimage(0, 0, &imgBg);
}
void welcome() {
mciSendString("play res/welcome.mp3", 0, 0, 0);
putimage(0, 0, &imgWelcome);
int x = 192;
int y = 452 - 5 - 12;
putimagePNG(x, y, &imgStartNormal);
MOUSEMSG msg;
while (1) {
msg = GetMouseMsg();
if (msg.uMsg == WM_MOUSEMOVE || msg.uMsg == WM_LBUTTONDOWN || msg.uMsg == WM_LBUTTONUP) {
if (msg.x > x && msg.x < x + imgStartNormal.getwidth() &&
msg.y > y && msg.y < y + imgStartNormal.getheight()) {
if (msg.uMsg == WM_LBUTTONUP) {
break;
}
putimagePNG(x, y, &imgStartPress);
}
else {
putimagePNG(x, y, &imgStartNormal);
}
}
}
}
int main(void) {
loadResources();
welcome();
while (1) {
updateWindow();
// to do
}
system("pause");
return 0;
}启动按钮的点击原理,非常简单。直接根据鼠标消息的位置来判断,如果在按钮区域之内,就高亮显示,如果在按钮区域之外,按钮就显示正常状态,如果鼠标位置落在按钮区域之内,同时点击了鼠标左键,就认为是按钮的单击事件,然后跳转到游戏场景。
下一节,实现玩家Hero的走动。
边栏推荐
- mySQL事务及其特性分析
- 阿里二面:JVM调优你会吗?
- 困扰所有SAP顾问多年的问题终于解决了
- 天花板级微服务大佬总结出这份451页笔记告诉你微服务就该这么学
- chrome插件开发入门-保姆级攻略
- 【无标题】(完美解决)uni-app 小程序下拉刷新后刷新图标无法正常恢复的问题
- LeetCode 剑指 Offer 35. 复杂链表的复制
- Incredible, thanks to this Android interview question, I have won offers from many Internet companies
- 你觉得程序员是一个需要天赋的职业吗?
- 27岁了,目前从事软件测试,听些老一辈的人说测试前途是IT里最差的,是这样吗?
猜你喜欢

SDS观察站

How to explain to my girlfriend what is cache penetration, cache breakdown, cache avalanche?
![Use Function Compute to package and download OSS files [Encounter Pit Collection]](/img/07/b5f9dc7272e12dbd07d559e79157f9.png)
Use Function Compute to package and download OSS files [Encounter Pit Collection]

I got the P8 "top" distributed architecture manual that went viral on Ali's intranet

The ceiling-level microservice boss summed up this 451-page note to tell you that microservices should be learned this way

宝塔一键部署WordPress(含宝塔添加站点、阿里云安全组配置、阿里云子域名解析)

openresty概述及Lua语言的嵌入

4. 继承

LeetCode·每日一题·1417.重新格式化字符串·模拟

PerfView project (first) : how to find hot spots function
随机推荐
放苹果
I got the P8 "top" distributed architecture manual that went viral on Ali's intranet
你觉得程序员是一个需要天赋的职业吗?
论文笔记:《Time Series Generative Adversrial Networks》(TimeGAN,时间序列GAN)
logstash/filebeat only receives data from the most recent period
ASP.NET Core 6框架揭秘实例演示[32]:错误页面的集中呈现方式
当科学家决定搞点“花里胡哨”的东西
和为s的连续正数序列
Gold Transfer(树上倍增)
How to explain to my girlfriend what is cache penetration, cache breakdown, cache avalanche?
MongoDB 非关系型数据库
php获取微信小程序码并存储到oss
5. 内部类
mySQL transaction and its characteristic analysis
Use Function Compute to package and download OSS files [Encounter Pit Collection]
如何解决 “主节点故障恢复的自动化” 问题?
27岁了,目前从事软件测试,听些老一辈的人说测试前途是IT里最差的,是这样吗?
[Study Notes] Maximum matching of general graphs
算法---跳跃游戏(Kotlin)
【UOJ 454】打雪仗(通信题)(分块)