当前位置:网站首页>The latest tank battle 2022 full development notes-1
The latest tank battle 2022 full development notes-1
2022-07-29 05:20:00 【CPP programming】
One 、 Project introduction
Tanks war 1990 As a classic stand-alone game , yes 80 after 、90 Good memories after , It's also C/C++ A must for beginners .
But tanks 1990, The game screen is too simple . We are now on tanks 1990 Make a new upgrade , Use C Language , Build the latest tank 2022! The effect of the game is as follows :
The supporting video address of this project
Two 、 Project purpose
Whole project , Fully using the C Language , Starting from scratch , From game frame design to game rendering , Integrated C The main technical points of language , about C Language beginners , It helps a lot . It can be used as a quick improvement project for beginners , It can also be directly used as the curriculum of college students .
3、 ... and 、 Project preparation
1.Windows System , Apple computer is not suitable .
2. Mastered C The simple foundation of language , Like constants 、 Variable 、if-for-while Control statement .
3. install VS Any version , It is recommended to use VS2019 or VS2022.
VS2019 Installation instructions
4. install easyx Graphics library
Download the latest version directly on the official website easyx Graphics library
After downloading , Double click Install directly to install .
5. download “ Tanks war 2020” Game materials and sound files .
Send me a private message directly to get .
Four 、 Create project
Use VS2019, Or other versions VS, Create a new project , Select an empty project template .
5、 ... and 、 Realize the battlefield layout of tank war
5.1 Import game resources
Put resource directory res Import project directory .
5.2 Realize the game background
add to main.cpp
#include <stdio.h>
#include <graphics.h>
IMAGE imgBG;
void init() {
initgraph(1300, 900);
loadimage(&imgBG, "res/bg1.png");
}
void updataMap() {
putimage(0, 0, &imgBG); // Update the game background
}
int main(void) {
init();
updataMap();
system("pause");
return 0;
}
5.3 Realize game map
First add the most basic map elements , Add other elements later , Such as jungle cover 、 The river 、 Shields and other props .
Define enumeration types , To represent various map elements .
enum {
EMPTY, // clearing
TU_WALL, // The earth wall
GANG_WALL, // Steel wall
MY_HOME, // Our commander
ENEMY_HOME, // The opposing commander
UNIT_COUNT
};
Define the image array imgUnits To represent each map element
IMAGE imgUnits[UNIT_COUNT];
stay init In the initialization function , Load map elements .
imgUnits[EMPTY] = NULL;
loadimage(&imgUnits[TU_WALL], "res/wall1.png");
loadimage(&imgUnits[GANG_WALL], "res/wall2.png");
loadimage(&imgUnits[MY_HOME], "res/pj2.png");
loadimage(&imgUnits[ENEMY_HOME], "res/wukelan2.png");
Use a two-dimensional array to represent the map layout , The subsequent optimization is to use multiple files to represent the map data of each level .
int map[18][26] = {
{ 0,0,1,1,0,0,1,1,0,0,0,1,4,0,1,0,0,0,1,1,0,0,1,1,0,0 },
{ 0,0,1,1,0,0,1,1,0,0,0,1,0,0,1,0,0,0,1,1,0,0,1,1,0,0 },
{ 0,0,1,1,0,0,1,1,0,0,0,1,1,1,1,0,0,0,1,1,0,0,1,1,0,0 },
{ 0,0,0,0,0,0,0,0,0,0,1,1,0,0,1,1,0,0,0,0,0,0,0,0,0,0 },
{ 0,0,0,0,0,0,0,0,0,0,1,1,0,0,1,1,0,0,0,0,0,0,0,0,0,0 },
{ 1,1,0,0,1,1,1,1,0,0,0,0,0,0,0,0,0,0,1,1,1,1,0,0,1,1 },
{ 2,2,0,0,1,1,1,1,0,0,0,0,0,0,0,0,0,0,1,1,1,1,0,0,2,2 },
{ 0,0,0,0,0,0,0,0,0,0,1,1,0,0,1,1,0,0,0,0,0,0,0,0,0,0 },
{ 0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0 },
{ 0,0,1,1,0,0,1,1,0,0,1,1,1,1,1,1,0,0,1,1,0,0,1,1,0,0 },
{ 0,0,1,1,0,0,1,1,0,0,1,1,0,0,1,1,0,0,1,1,0,0,1,1,0,0 },
{ 0,0,1,1,0,0,1,1,0,0,1,1,0,0,1,1,0,0,1,1,0,0,1,1,0,0 },
{ 0,0,1,1,0,0,1,1,0,0,1,1,0,0,1,1,0,0,1,1,0,0,1,1,0,0 },
{ 0,0,1,1,0,0,1,1,0,0,0,0,0,0,0,0,0,0,1,1,0,0,1,1,0,0 },
{ 0,0,1,1,0,0,1,1,0,0,0,0,0,0,0,0,0,0,1,1,0,0,1,1,0,0 },
{ 0,0,1,1,0,0,1,1,0,0,0,1,1,1,1,0,0,0,1,1,0,0,1,1,0,0 },
{ 0,0,0,0,0,0,0,0,0,0,0,1,3,0,1,0,0,0,0,0,0,0,0,0,0,0 },
{ 0,0,0,0,0,0,0,0,0,0,0,1,0,0,1,0,0,0,0,0,0,0,0,0,0,0 }
};
According to the two-dimensional array map data , stay updataMap Function to update map data .
for (int i = 0; i < 18; i++) {
for (int j = 0; j < 26; j++) {
putimage(j * 50, i * 50, &imgUnits[map[i][j]]);
}
}
Run the program , View the game map effect :
5.4 Realize the transparent background of the command post and import customized tools.h and tools.cpp
1) Import custom tools.h and tools.cpp
2) stay main.cpp Add
#include "tools.h"
3) Modify the code
//putimage(j * 50, i * 50, &imgUnits[map[i][j]]);
putimagePNG(j * 50, i * 50, &imgUnits[map[i][j]]);
The test results are as follows :
next step , We will create tanks on both sides .
Today's sharing is here , Everyone should study hard C Language /C++ yo ~
For preparing to learn C/C++ Programming partners , If you want to better improve your core programming skills ( Internal skill ) From now on !
C Language C++ Programming learning communication circle ,QQ Group :763855696
【 Click to enter 】
Organize and share ( Years of learning source code 、 Project practice video 、 Project notes , Introduction to Basics )
Welcome to change careers and learn programming partners , Using more information to learn and grow faster than thinking about it yourself !
C Language from entry to mastery (C Introduction to language C Language course C Language zero basis C Language foundation C Language learning C
边栏推荐
- Use annotation test in idea
- 三层项目的架构分析及构造方法的参数名称注入
- 7.1-default-arguments
- sql日志
- Solve the warning prompt of MySQL mapping file
- JS (in ES6) sync & await understanding
- Apache POI实现Excel导入读取数据和写入数据并导出
- Legend how to configure multiple versions of wechat updates on one server
- ThreadPoolExecutor simple to use
- Deadlock analysis using jstack, jconsole, and jvisualvm
猜你喜欢
How to add traffic statistics codes to the legendary Development Zone website
ODOO开发教程之图表
【文件下载】Easyexcel快速上手
TCP three handshakes and four waves
力扣------对奇偶下标分别排序
What if the office prompts that the system configuration cannot run?
How does WPS take quick screenshots? WPS quick screenshot method
Apache POI implements excel import, read data, write data and export
Google GTEST event mechanism
About realizing page Jump of website in Servlet
随机推荐
Rolabelimg to data format data
那个准时上下班,从不愿意加班加点的人,在我前面升职了...
Pytorch learning notes
VirtualBox has expanded the capacity of virtual hard disk (without modifying the original data)
【2022新生学习】第三周要点
后置通知的流程分析与功能实现有哪些内容你还记得吗?
sql日志
ARFoundation从零开始9-AR锚点(AR Anchor)
TMUX essays
自贸经济中架起的“隐形桥梁”:国货精品与中国AI力量
Lenovo Savior r7000+ add ssd+ copy and partition the information of the original D disk to the new SSD
js(forEach)出现return无法结束函数的解决方法
Apache POI实现Excel导入读取数据和写入数据并导出
Arfoundation starts from scratch 8-geospatial API (geospatial) development
Getting started with arfoundation tutorial 10- plane detection and placement
Jackson parsing JSON detailed tutorial
Original code, inverse code, complement code
Sparksql inserts or updates in batches and saves data to MySQL
MySQL many to many relationship, grouping and splicing to query multiple data to one data
时间序列分析的表示学习时代来了?