当前位置:网站首页>Core principles of video games
Core principles of video games
2022-07-06 20:23:00 【Crossin's programming classroom】
Zero basis python Introductory tutorial :python666.cn
Hello everyone , Welcome to Crossin Programming classroom of !
Have you ever played with such a toy when you were a child : A piece of hard paper , One side is painted with a bird , A cage is painted on one side . Stick a thin stick under the hard paper . Use your hand to rotate the thin rod , Let the two sides of the hard paper alternate quickly , You will see the bird being caged .

This phenomenon is called Visual persistence , also called afterglow effect . The nature of the human eye makes the light signal after entering , It will last for a short time , This period of time is about 0.1~0.4 second . The movie 、 Animation is achieved by using this phenomenon , Play static pictures quickly and continuously , Form a moving picture that looks continuous . Games are no exception .
Take a look at a passage Python Famous game library in pygame( To be installed ) Write a “ Empty game ” Code :

Although this code only shows a background image , There is no game function at all , But this is already a basic game code framework .
Notice one in the code while True The cycle of , The note is “ The main cycle of the game ”. This is the main part of the game . Each cycle is equivalent to a static picture , The program is running , Just modify this picture , There is a dynamic effect .
Different from animation , In the game, you should not only play pictures , It also needs to deal with the interaction between the player's operation and the content in the game . So here while In circulation , I have to receive the input of players , And deal with various logical judgments in the game 、 motion 、 Collision and so on .
In the main loop of the above code , Made a response to the exit event :
for event in pygame.event.get():
if event.type == pygame.QUIT:
# Exit the program after receiving the exit event
pygame.quit()
exit()Then draw the image into the window :
screen.blit(background, (0,0))Last , Update the whole window :
pygame.display.update()If you've seen it “ Clay animation ”, Then you can imagine the whole game process as the process of shooting clay animation :
every time ,screen.blit() It's equivalent to putting a doll 、 The set moves a little bit
pygame.display.update() Press the shutter to take a new picture
and if event.type == pygame.QUIT: Is judging , Did the director call it quits
All this is handled by the computer in a very short time , So that players feel coherent .
Although this is a very simple game logic , But in terms of core principles , Most games are interlinked . Even cool 3D Games or large-scale online games , They also pass through a main game loop , Update various game logic and display effects in the cycle to operate .
Some large 3D The game needs to do many things in one cycle , Complex physical operations are required 、 Calculate the illumination effect of light 、 Intelligence to handle a large number of computer characters 、 Network information communication, etc . On computers with low configuration , These calculations take more time , The game refreshes the screen more slowly . This is what we often hear “ The frame rate of a game is low ” Why , At this time, you will feel that the game is not smooth .
The above is a brief introduction to the core principles of video games . If you are a novice interested in game development , You can see what I wrote before pygame Series of tutorials :
Pygame introduction - Imitate wechat to play airplane Games
Although not as popular as the game engine now “ Foolishness ” operation , But implementing the game through code can make you have a deeper understanding of the underlying logic of the game .
thank forward and give the thumbs-up The fellow ~
_ Previous articles are recommended _
How do I teach myself programming 9 I found a job in three months
If you need to know Paid premium courses And Teaching Q & a service
Please be there. Crossin Programming classroom of Internal reply : 666

边栏推荐
- Node.js: express + MySQL实现注册登录,身份认证
- 腾讯云数据库公有云市场稳居TOP 2!
- Groovy basic syntax collation
- Recyclerview not call any Adapter method :onCreateViewHolder,onBindViewHolder,
- In unity space, an object moves around a fixed point on the sphere at a fixed speed
- Deep learning classification network -- zfnet
- [weekly pit] information encryption + [answer] positive integer factorization prime factor
- 5. 無線體內納米網:十大“可行嗎?”問題
- Tencent T3 Daniel will teach you hand-in-hand, the internal information of the factory
- 5. Wireless in vivo nano network: top ten "feasible?" problem
猜你喜欢

【计网】第三章 数据链路层(4)局域网、以太网、无线局域网、VLAN

JMeter server resource indicator monitoring (CPU, memory, etc.)

【DSP】【第二篇】了解C6678和创建工程
Tencent byte and other big companies interview real questions summary, Netease architects in-depth explanation of Android Development

Oceanbase Community Edition OBD mode deployment mode stand-alone installation

为什么新手在编程社区提问经常得不到回答,甚至还会被嘲讽?

B-杰哥的树(状压树形dp)

Node. Js: express + MySQL realizes registration, login and identity authentication

Discussion on beegfs high availability mode

Force deduction brush question - 98 Validate binary search tree
随机推荐
Guangzhou's first data security summit will open in Baiyun District
Jupyter launch didn't respond after Anaconda was installed & the web page was opened and ran without execution
5. Wireless in vivo nano network: top ten "feasible?" problem
Appx code signing Guide
String长度限制?
JS implementation force deduction 71 question simplified path
数字三角形模型 AcWing 1018. 最低通行费
Redisson bug analysis
看过很多教程,却依然写不好一个程序,怎么破?
Monthly report of speech synthesis (TTS) and speech recognition (ASR) papers in June 2022
What happened to the kernel after malloc() was transferred? Attached malloc () and free () implementation source
Database specific interpretation of paradigm
Extraction rules and test objectives of performance test points
rt-thread i2c 使用教程
Detailed introduction of distributed pressure measurement system VIII: basic introduction of akka actor model
Period compression filter
腾讯架构师首发,2022Android面试笔试总结
Anaconda安装后Jupyter launch 没反应&网页打开运行没执行
8086 instruction code summary (table)
Qinglong panel white screen one key repair