当前位置:网站首页>The latest tank battle 2022 full development notes-1
The latest tank battle 2022 full development notes-1
2022-07-06 13:26:00 【Programmer rock】
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
easyx Download link
After downloading , Double click Install directly to install .
easyx Quick start
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 .
边栏推荐
- One article to get UDP and TCP high-frequency interview questions!
- Implement queue with stack
- Application architecture of large live broadcast platform
- The overseas sales of Xiaomi mobile phones are nearly 140million, which may explain why Xiaomi ov doesn't need Hongmeng
- Inheritance and polymorphism (I)
- (ultra detailed onenet TCP protocol access) arduino+esp8266-01s access to the Internet of things platform, upload real-time data collection /tcp transparent transmission (and how to obtain and write L
- Arduino+ water level sensor +led display + buzzer alarm
- 9.指针(上)
- Wei Pai: the product is applauded, but why is the sales volume still frustrated
- 【话题终结者】
猜你喜欢
MPLS experiment
Alibaba cloud side: underlying details in concurrent scenarios - pseudo sharing
(super detailed II) detailed visualization of onenet data, how to plot with intercepted data flow
系统设计学习(一)Design Pastebin.com (or Bit.ly)
TYUT太原理工大学2022数据库大题之概念模型设计
12 excel charts and arrays
Application architecture of large live broadcast platform
最新坦克大战2022-全程开发笔记-1
魏牌:产品叫好声一片,但为何销量还是受挫
1. C language matrix addition and subtraction method
随机推荐
Questions and answers of "Fundamentals of RF circuits" in the first semester of the 22nd academic year of Xi'an University of Electronic Science and technology
10 minutes pour maîtriser complètement la rupture du cache, la pénétration du cache, l'avalanche du cache
Interview Essentials: talk about the various implementations of distributed locks!
2. Preliminary exercises of C language (2)
1.初识C语言(1)
(super detailed II) detailed visualization of onenet data, how to plot with intercepted data flow
View UI Plus 发布 1.3.1 版本,增强 TypeScript 使用体验
Differences and application scenarios between MySQL index clock B-tree, b+tree and hash indexes
View UI Plus 发布 1.1.0 版本,支持 SSR、支持 Nuxt、增加 TS 声明文件
Voir ui plus version 1.3.1 pour améliorer l'expérience Typescript
Design a key value cache to save the results of the most recent Web server queries
Aurora system model of learning database
(超详细二)onenet数据可视化详解,如何用截取数据流绘图
5.MSDN的下载和使用
[中国近代史] 第五章测验
Cloud native trend in 2022
Arduino+ water level sensor +led display + buzzer alarm
[中国近代史] 第六章测验
【九阳神功】2021复旦大学应用统计真题+解析
最新坦克大战2022-全程开发笔记-2