当前位置:网站首页>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表sql语句增删查改_修改_删除
- 【分享】PPT还能做成这样?你一定没见过
- 和为s的连续正数序列
- Flexmonster 数据透视表和图表组件
- 解决 Pocess finished with exit code 1 Class not found 和 Command line is too long. Shorten the command
- 7 天找个 Go 工作,Gopher 要学的条件语句,循环语句 ,第3篇
- MySQL约束
- Jetpack Compose学习(9)——Compose中的列表控件(LazyRow和LazyColumn)
- 突破次元壁垒,让身边的玩偶手办在屏幕上动起来!
- 【Ackerman Motion Control】
猜你喜欢

SAP Product Enhancement Technology Review

安装nodejs

Jetpack Compose学习(9)——Compose中的列表控件(LazyRow和LazyColumn)

4. 继承

LeetCode 剑指 Offer 35. 复杂链表的复制

虚拟机使用 WinSCP & Putty

漫画手绘之临摹篇
![[Building a 2D rasterized map using SLAM technology]](/img/d3/2d5a7415cf3f9e965ef83fa90e6cc2.png)
[Building a 2D rasterized map using SLAM technology]

悠漓带你玩转C语言(详解操作符1)

I got the P8 "top" distributed architecture manual that went viral on Ali's intranet
随机推荐
2.MySQL ---- 修改数据库的字符集(日常小技巧)
MongoDB 非关系型数据库
Analyzes how Flink task than YARN container memory limit
【Prometheus】 Grafana数据与可视化
困扰所有SAP顾问多年的问题终于解决了
【Mysql系列】04_事务
和为s的连续正数序列
MySQL数据库基础_常用数据类型_表设计
mySQL事务及其特性分析
【Ackerman Motion Control】
突破次元壁垒,让身边的玩偶手办在屏幕上动起来!
09什么是继承
MySQL表sql语句增删查改_增加
【综合练习12】实现静态网页的相关功能
中小企业如何实施MES管理系统
阿里内网疯传的P8“顶级”分布式架构手册被我拿到了
PerfView project (first) : how to find hot spots function
【Mask2Former】 解决代码中一些问题
【学习笔记】一般图最大匹配
阿里云ssl证书申请,宝塔ssl证书部署