当前位置:网站首页>最新坦克大战2022-全程开发笔记-3
最新坦克大战2022-全程开发笔记-3
2022-07-06 09:19:00 【程序员Rock】
八、创建游循环
8.1 创建游戏的主体循环
int main(void) {
init();
createMyTank();
createEnemyTank();
while (1) {
updataMap();
updataAllTanks();
}
system("pause");
return 0;
}
8.2 使用时间计数来优化循环
上一步的循环结构,不停的刷新,严重消耗系统的性能,必须要加以改进。最简单的方式,就使用时间计数来处理。注意,直接使用Sleep会影响到游戏的及时响应。
bool updata; // 是否更新, 并在init函数中初始化为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 使用体验
- Relational algebra of tyut Taiyuan University of technology 2022 database
- TYUT太原理工大学2022数据库大题之E-R图转关系模式
- Problems and solutions of robust estimation in rtklib single point location spp
- View UI plus released version 1.2.0 and added image, skeleton and typography components
- Fairygui bar subfamily (scroll bar, slider, progress bar)
- IPv6 experiment
- 错误:排序与角标越界
- MySQL 30000 word essence summary + 100 interview questions, hanging the interviewer is more than enough (Collection Series
- Code example of MATLAB reading GNSS observation value o file
猜你喜欢
Ten minutes to thoroughly master cache breakdown, cache penetration, cache avalanche
MySQL 30000 word essence summary + 100 interview questions, hanging the interviewer is more than enough (Collection Series
Implementation of Excel import and export functions
System design learning (III) design Amazon's sales rank by category feature
Abstract classes and interfaces
面渣逆袭:Redis连环五十二问,三万字+八十图详解。
阿里云微服务(三)Sentinel开源流控熔断降级组件
Data manipulation language (DML)
Edit distance (multi-source BFS)
Alibaba cloud microservices (I) service registry Nacos, rest template and feign client
随机推荐
Abstract classes and interfaces
用栈实现队列
图书管理系统小练习
4.30动态内存分配笔记
Experience summary of autumn recruitment of state-owned enterprises
Alibaba cloud microservices (I) service registry Nacos, rest template and feign client
十分鐘徹底掌握緩存擊穿、緩存穿透、緩存雪崩
[GNSS] robust estimation (robust estimation) principle and program implementation
Record: the solution of MySQL denial of access when CMD starts for the first time
初识指针笔记
Introduction and use of redis
13 power map
Summary of multiple choice questions in the 2022 database of tyut Taiyuan University of Technology
Smart classroom solution and mobile teaching concept description
(超详细二)onenet数据可视化详解,如何用截取数据流绘图
TYUT太原理工大学2022数据库之关系代数小题
Alibaba cloud microservices (IV) service mesh overview and instance istio
阿里云微服务(二) 分布式服务配置中心以及Nacos的使用场景及实现介绍
TYUT太原理工大学2022数据库大题之分解关系模式
4.30 dynamic memory allocation notes