当前位置:网站首页>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的走动。
边栏推荐
猜你喜欢
1.TCP/IP基础知识
LeetCode · Question of the Day · 1417. Reformatting String · Simulation
Revelations!The former Huawei microservice expert wrote 500 pages of practical notes on the landing architecture, which has been open sourced
宝塔一键部署WordPress(含宝塔添加站点、阿里云安全组配置、阿里云子域名解析)
TIOBE - 2022年8月编程语言排行
人是怎么废掉的?人是怎么变强的?
放苹果
爆料!前华为微服务专家纯手打500页落地架构实战笔记,已开源
Convolutional Neural Network Gradient Vanishing, The Concept of Gradient in Neural Networks
齐话存储未来,诠释分布式缘起
随机推荐
Analyzes how Flink task than YARN container memory limit
What areas of the deep neural network are related to the human brain neural network?
如何给女朋友解释什么是缓存穿透、缓存击穿、缓存雪崩?
【阿克曼运动控制】
数据库内核面试中我不会的问题(4)
The ceiling-level microservice boss summed up this 451-page note to tell you that microservices should be learned this way
阿里内网疯传的P8“顶级”分布式架构手册被我拿到了
LeetCode 剑指 Offer 35. 复杂链表的复制
【Mysql系列】03_系统设计
困扰所有SAP顾问多年的问题终于解决了
go基础之并发
中小企业如何实施MES管理系统
Cholesterol-PEG-FITC,Fluorescein-PEG-CLS,胆固醇-聚乙二醇-荧光素水溶性
03列中新增子行
Use Function Compute to package and download OSS files [Encounter Pit Collection]
dreamweaver网页设计作业制作 学生个人网页猫眼电影 WEB静态网页作业模板 大学生个人主页博客网页代码 dw个人网页作
论文笔记:《Time Series Generative Adversrial Networks》(TimeGAN,时间序列GAN)
虚拟机使用 WinSCP & Putty
AcWing 273. 分级(线性DP+结论)
mySQL事务及其特性分析