当前位置:网站首页>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
边栏推荐
- 爬虫(14) - Scrapy-Redis分布式爬虫(1) | 详解
- Error analysis ~csdn rebound shell error
- Oceanbase Community Edition OBD mode deployment mode stand-alone installation
- SSH connection denied
- Zoom with unity mouse wheel: zoom the camera closer or farther
- 【每周一坑】计算100以内质数之和 +【解答】输出三角形
- 报错分析~csdn反弹shell报错
- 新一代垃圾回收器—ZGC
- Ideas and methods of system and application monitoring
- 02 基础入门-数据包拓展
猜你喜欢
What programming do children learn?
Cesium 点击绘制圆形(动态绘制圆形)
How does kubernetes support stateful applications through statefulset? (07)
5. 無線體內納米網:十大“可行嗎?”問題
5. Nano - Net in wireless body: Top 10 "is it possible?" Questions
【每周一坑】输出三角形
Event center parameter transfer, peer component value transfer method, brother component value transfer
New generation garbage collector ZGC
Why do novices often fail to answer questions in the programming community, and even get ridiculed?
02 basic introduction - data package expansion
随机推荐
Tencent architects first, 2022 Android interview written examination summary
Case ① | host security construction: best practice of 3 levels and 11 capabilities
How to select several hard coded SQL rows- How to select several hardcoded SQL rows?
BeagleBoneBlack 上手记
Notes on beagleboneblack
[network planning] Chapter 3 data link layer (4) LAN, Ethernet, WLAN, VLAN
为什么新手在编程社区提问经常得不到回答,甚至还会被嘲讽?
【云原生与5G】微服务加持5G核心网
Review questions of anatomy and physiology · VIII blood system
HMS core machine learning service creates a new "sound" state of simultaneous interpreting translation, and AI makes international exchanges smoother
Wonderful coding [hexadecimal conversion]
22-07-05 upload of qiniu cloud storage pictures and user avatars
A5000 vgpu display mode switching
Poj3617 best cow line
Synchronization of data create trigger synchronization table for each site
永磁同步电机转子位置估算专题 —— 基波模型与转子位置角
夏志刚介绍
使用ssh连接被拒
SSH connection denied
How to handle the timeout of golang