当前位置:网站首页>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

边栏推荐
- Tencent Android development interview, basic knowledge of Android Development
- How to select several hard coded SQL rows- How to select several hardcoded SQL rows?
- Boder radius has four values, and boder radius exceeds four values
- Initial experience of addresssanitizer Technology
- Web开发小妙招:巧用ThreadLocal规避层层传值
- Color is converted to tristimulus value (r/g/b) (dry stock)
- HMS Core 机器学习服务打造同传翻译新“声”态,AI让国际交流更顺畅
- js获取浏览器系统语言
- I've seen many tutorials, but I still can't write a program well. How can I break it?
- 【DSP】【第二篇】了解C6678和创建工程
猜你喜欢

Digital triangle model acwing 1018 Minimum toll

【DSP】【第二篇】了解C6678和创建工程

How does kubernetes support stateful applications through statefulset? (07)

Web security - payload
Tencent T4 architect, Android interview Foundation

Maximum likelihood estimation and cross entropy loss
![[weekly pit] positive integer factorization prime factor + [solution] calculate the sum of prime numbers within 100](/img/d8/a367c26b51d9dbaf53bf4fe2a13917.png)
[weekly pit] positive integer factorization prime factor + [solution] calculate the sum of prime numbers within 100
腾讯架构师首发,2022Android面试笔试总结

An East SMS login resurrection installation and deployment tutorial

Tencent T3 Daniel will teach you hand-in-hand, the internal information of the factory
随机推荐
Deep learning classification network -- zfnet
【每周一坑】正整数分解质因数 +【解答】计算100以内质数之和
腾讯云数据库公有云市场稳居TOP 2!
Oceanbase Community Edition OBD mode deployment mode stand-alone installation
Rhcsa Road
腾讯安卓开发面试,android开发的基础知识
Web开发小妙招:巧用ThreadLocal规避层层传值
8086指令码汇总表(表格)
设计你的安全架构OKR
22-07-05 upload of qiniu cloud storage pictures and user avatars
01 basic introduction - concept nouns
【DSP】【第二篇】了解C6678和创建工程
Maximum likelihood estimation and cross entropy loss
In unity space, an object moves around a fixed point on the sphere at a fixed speed
Poj1149 pigs [maximum flow]
【每周一坑】信息加密 +【解答】正整数分解质因数
Function optimization and arrow function of ES6
mod_ WSGI + pymssql path SQL server seat
Tencent T2 Daniel explained in person and doubled his job hopping salary
Tencent cloud database public cloud market ranks top 2!