当前位置:网站首页>最新坦克大战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;
}边栏推荐
- 用栈实现队列
- Database operation of tyut Taiyuan University of technology 2022 database
- XV Function definition and call
- Usage differences between isempty and isblank
- 抽象类和接口
- 2-year experience summary, tell you how to do a good job in project management
- 面渣逆袭:Redis连环五十二问,三万字+八十图详解。
- [GNSS] robust estimation (robust estimation) principle and program implementation
- Design a key value cache to save the results of the most recent Web server queries
- [rtklib] preliminary practice of using robust adaptive Kalman filter under RTK
猜你喜欢

图书管理系统小练习

系统设计学习(一)Design Pastebin.com (or Bit.ly)

西安电子科技大学22学年上学期《基础实验》试题及答案

TYUT太原理工大学2022数据库大题之E-R图转关系模式

XV Function definition and call

Relational algebra of tyut Taiyuan University of technology 2022 database

Small exercise of library management system

Fgui project packaging and Publishing & importing unity & the way to display the UI

西安电子科技大学22学年上学期《射频电路基础》试题及答案

TYUT太原理工大学2022软工导论大题汇总
随机推荐
《软件测试》习题答案:第一章
Alibaba cloud microservices (IV) service mesh overview and instance istio
Atomic and nonatomic
121道分布式面试题和答案
Role movement in the first person perspective
How to ensure data consistency between MySQL and redis?
WSL common commands
记录:动态Web项目servlet访问数据库404错误之解决
Heap sort [handwritten small root heap]
[while your roommate plays games, let's see a problem]
MySQL backup -- common errors in xtrabackup backup
TYUT太原理工大学2022软工导论简答题
Common method signatures and meanings of Iterable, collection and list
IPv6 experiment
Application architecture of large live broadcast platform
ROS machine voice
Abstract classes and interfaces
Error: symbol not found
西安电子科技大学22学年上学期《射频电路基础》试题及答案
Relational algebra of tyut Taiyuan University of technology 2022 database