当前位置:网站首页>The latest tank battle 2022 - full development notes-3
The latest tank battle 2022 - full development notes-3
2022-07-06 13:27:00 【Programmer rock】
8、 ... and 、 Create a tour loop
8.1 Create the main loop of the game
int main(void) {
init();
createMyTank();
createEnemyTank();
while (1) {
updataMap();
updataAllTanks();
}
system("pause");
return 0;
}
8.2 Use time counting to optimize the loop
The cycle structure of the previous step , Keep refreshing , It seriously consumes the performance of the system , It must be improved . The easiest way , Use time counting to process . Be careful , Use it directly Sleep It will affect the timely response of the game .
bool updata; // Whether to update , And in init Function is initialized to true
int main(void) {
init();
createMyTank();
createEnemyTank();
int time = 0;
while (1) {
time += getDelay();
if (time >= 20) {
updata = true;
time = 0;
}
if (updata) {
updata = false;
BeginBatchDraw();
updataMap();
updataAllTanks();
EndBatchDraw();
}
}
system("pause");
return 0;
}
边栏推荐
- View UI Plus 發布 1.3.1 版本,增强 TypeScript 使用體驗
- 凡人修仙学指针-2
- JS interview questions (I)
- Alibaba cloud side: underlying details in concurrent scenarios - pseudo sharing
- 【毕业季·进击的技术er】再见了,我的学生时代
- 4.30动态内存分配笔记
- 12 excel charts and arrays
- Data manipulation language (DML)
- View UI plus released version 1.3.1 to enhance the experience of typescript
- Inheritance and polymorphism (Part 2)
猜你喜欢
TYUT太原理工大学2022数据库题库选择题总结
Alibaba cloud microservices (IV) service mesh overview and instance istio
1.初识C语言(1)
Alibaba cloud microservices (III) sentinel open source flow control fuse degradation component
MySQL Database Constraints
最新坦克大战2022-全程开发笔记-2
Pit avoidance Guide: Thirteen characteristics of garbage NFT project
One article to get UDP and TCP high-frequency interview questions!
Abstract classes and interfaces
系统设计学习(三)Design Amazon‘s sales rank by category feature
随机推荐
Floating point comparison, CMP, tabulation ideas
There is always one of the eight computer operations that you can't learn programming
3.C语言用代数余子式计算行列式
12 excel charts and arrays
2-year experience summary, tell you how to do a good job in project management
View UI plus releases version 1.1.0, supports SSR, supports nuxt, and adds TS declaration files
TYUT太原理工大学2022数据库之关系代数小题
Inheritance and polymorphism (I)
165. Compare version number - string
1.初识C语言(1)
阿里云微服务(三)Sentinel开源流控熔断降级组件
Relational algebra of tyut Taiyuan University of technology 2022 database
A brief introduction to the database of tyut Taiyuan University of technology in previous years
string
CorelDRAW plug-in -- GMS plug-in development -- Introduction to VBA -- GMS plug-in installation -- Security -- macro Manager -- CDR plug-in (I)
Application architecture of large live broadcast platform
Arduino+ds18b20 temperature sensor (buzzer alarm) +lcd1602 display (IIC drive)
Questions and answers of "basic experiment" in the first semester of the 22nd academic year of Xi'an University of Electronic Science and technology
[中国近代史] 第九章测验
Comparison between FileInputStream and bufferedinputstream