当前位置:网站首页>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;
}
边栏推荐
猜你喜欢
Cloud native trend in 2022
(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
西安电子科技大学22学年上学期《基础实验》试题及答案
MySQL Database Constraints
Inheritance and polymorphism (Part 2)
arduino+水位传感器+led显示+蜂鸣器报警
1.初识C语言(1)
Wei Pai: the product is applauded, but why is the sales volume still frustrated
TYUT太原理工大学2022数据库题库选择题总结
5.函数递归练习
随机推荐
View UI Plus 发布 1.1.0 版本,支持 SSR、支持 Nuxt、增加 TS 声明文件
View UI Plus 发布 1.3.0 版本,新增 Space、$ImagePreview 组件
TYUT太原理工大学2022“mao gai”必背
继承和多态(下)
3.输入和输出函数(printf、scanf、getchar和putchar)
Quickly generate illustrations
View UI Plus 發布 1.3.1 版本,增强 TypeScript 使用體驗
图书管理系统小练习
Implement queue with stack
Conceptual model design of the 2022 database of tyut Taiyuan University of Technology
Design a key value cache to save the results of the most recent Web server queries
6. Function recursion
Alibaba cloud side: underlying details in concurrent scenarios - pseudo sharing
MySQL Database Constraints
TYUT太原理工大学2022数据库题库选择题总结
继承和多态(上)
魏牌:产品叫好声一片,但为何销量还是受挫
Cloud native trend in 2022
String类
Database operation of tyut Taiyuan University of technology 2022 database