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

边栏推荐
- 02 basic introduction - data package expansion
- 5. Wireless in vivo nano network: top ten "feasible?" problem
- What happened to the kernel after malloc() was transferred? Attached malloc () and free () implementation source
- 小孩子學什麼編程?
- Tencent Android development interview, basic knowledge of Android Development
- Rhcsa Road
- 爬虫(14) - Scrapy-Redis分布式爬虫(1) | 详解
- 永磁同步电机转子位置估算专题 —— 基波模型类位置估算概要
- RT thread I2C tutorial
- Basic knowledge of lists
猜你喜欢

An East SMS login resurrection installation and deployment tutorial

RT thread I2C tutorial

【每周一坑】正整数分解质因数 +【解答】计算100以内质数之和

22-07-05 upload of qiniu cloud storage pictures and user avatars

Introduction of Xia Zhigang

逻辑是个好东西

A5000 vgpu display mode switching

Le lancement du jupyter ne répond pas après l'installation d'Anaconda

Detailed introduction of distributed pressure measurement system VIII: basic introduction of akka actor model

What programming do children learn?
随机推荐
01 basic introduction - concept nouns
Trends of "software" in robotics Engineering
JVM_常见【面试题】
How to select several hard coded SQL rows- How to select several hardcoded SQL rows?
Cesium 两点之间的直线距离
Rhcsa Road
Problems encountered in using RT thread component fish
[cloud lesson] EI lesson 47 Mrs offline data analysis - processing OBS data through Flink
【DSP】【第二篇】了解C6678和创建工程
[Yann Lecun likes the red stone neural network made by minecraft]
Continuous test (CT) practical experience sharing
Web security - payload
【每周一坑】计算100以内质数之和 +【解答】输出三角形
Number of schemes from the upper left corner to the lower right corner of the chessboard (2)
Force deduction brush question - 98 Validate binary search tree
Groovy basic syntax collation
mod_ WSGI + pymssql path SQL server seat
Cesium Click to draw a circle (dynamically draw a circle)
【云原生与5G】微服务加持5G核心网
Rhcsa Road