当前位置:网站首页>最新坦克大战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;
}
边栏推荐
- TYUT太原理工大学2022数据库大题之分解关系模式
- Share a website to improve your Aesthetics
- Fgui project packaging and Publishing & importing unity & the way to display the UI
- Counter attack of flour dregs: redis series 52 questions, 30000 words + 80 pictures in detail.
- 西安电子科技大学22学年上学期《基础实验》试题及答案
- Chromatic judgement bipartite graph
- Wechat applet development experience
- [GNSS] robust estimation (robust estimation) principle and program implementation
- [GNSS data processing] Helmert variance component estimation analysis and code implementation
- arduino+水位传感器+led显示+蜂鸣器报警
猜你喜欢
抽象类和接口
(超详细二)onenet数据可视化详解,如何用截取数据流绘图
Small exercise of library management system
Design a key value cache to save the results of the most recent Web server queries
Wechat applet development experience
RTKLIB: demo5 b34f. 1 vs b33
What are the advantages of using SQL in Excel VBA
How do architects draw system architecture blueprints?
C code implementation of robust estimation in rtklib's pntpos function (standard single point positioning spp)
(超详细onenet TCP协议接入)arduino+esp8266-01s接入物联网平台,上传实时采集数据/TCP透传(以及lua脚本如何获取和编写)
随机推荐
错误:排序与角标越界
用栈实现队列
TYUT太原理工大学2022数据库大题之概念模型设计
XV Function definition and call
Record: Navicat premium can't connect to MySQL for the first time
121道分布式面试题和答案
系统设计学习(一)Design Pastebin.com (or Bit.ly)
[rtklib 2.4.3 B34] version update introduction I
System design learning (III) design Amazon's sales rank by category feature
Alibaba cloud side: underlying details in concurrent scenarios - pseudo sharing
六种集合的遍历方式总结(List Set Map Queue Deque Stack)
十分鐘徹底掌握緩存擊穿、緩存穿透、緩存雪崩
Shortest Hamilton path (pressure DP)
Record: I accidentally wrote a recursion next time
167. Sum of two numbers II - input ordered array - Double pointers
Record: the solution of MySQL denial of access when CMD starts for the first time
架构师怎样绘制系统架构蓝图?
MySQL 三万字精华总结 + 面试100 问,吊打面试官绰绰有余(收藏系列
Novatel board oem617d configuration step record
12 excel charts and arrays