当前位置:网站首页>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;
}
边栏推荐
- TYUT太原理工大学往年数据库简述题
- Inheritance and polymorphism (Part 2)
- 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
- Implement queue with stack
- 用栈实现队列
- 4.分支语句和循环语句
- 魏牌:产品叫好声一片,但为何销量还是受挫
- 3.输入和输出函数(printf、scanf、getchar和putchar)
- (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+ds18b20 temperature sensor (buzzer alarm) +lcd1602 display (IIC drive)
猜你喜欢
Inheritance and polymorphism (Part 2)
1.初识C语言(1)
View UI Plus 发布 1.2.0 版本,新增 Image、Skeleton、Typography组件
Summary of multiple choice questions in the 2022 database of tyut Taiyuan University of Technology
Redis介绍与使用
阿里云微服务(三)Sentinel开源流控熔断降级组件
String类
TYUT太原理工大学2022软工导论大题汇总
Introduction and use of redis
最新坦克大战2022-全程开发笔记-1
随机推荐
Tyut Taiyuan University of technology 2022 "Mao Gai" must be recited
TYUT太原理工大学2022软工导论大题汇总
系统设计学习(二)Design a key-value cache to save the results of the most recent web server queries
MySQL 30000 word essence summary + 100 interview questions, hanging the interviewer is more than enough (Collection Series
Comparison between FileInputStream and bufferedinputstream
【九阳神功】2022复旦大学应用统计真题+解析
7. Relationship between array, pointer and array
Alibaba cloud microservices (II) distributed service configuration center and Nacos usage scenarios and implementation introduction
Aurora system model of learning database
最新坦克大战2022-全程开发笔记-1
Atomic and nonatomic
Introduction and use of redis
Alibaba cloud microservices (IV) service mesh overview and instance istio
167. Sum of two numbers II - input ordered array - Double pointers
(super detailed II) detailed visualization of onenet data, how to plot with intercepted data flow
图书管理系统小练习
View UI Plus 发布 1.1.0 版本,支持 SSR、支持 Nuxt、增加 TS 声明文件
Common method signatures and meanings of Iterable, collection and list
6.函数的递归
8.C语言——位操作符与位移操作符