当前位置:网站首页>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
边栏推荐
- What programming do children learn?
- 为什么新手在编程社区提问经常得不到回答,甚至还会被嘲讽?
- “罚点球”小游戏
- Leetcode brush first_ Maximum Subarray
- Color is converted to tristimulus value (r/g/b) (dry stock)
- [network planning] Chapter 3 data link layer (4) LAN, Ethernet, WLAN, VLAN
- 【GET-4】
- Basic knowledge of lists
- Groovy basic syntax collation
- Deep learning classification network -- zfnet
猜你喜欢
持续测试(CT)实战经验分享
Speech recognition (ASR) paper selection: talcs: an open source Mandarin English code switching corps and a speech
Leetcode question 283 Move zero
【每周一坑】计算100以内质数之和 +【解答】输出三角形
系统与应用监控的思路和方法
某东短信登录复活 安装部署教程
5. 无线体内纳米网:十大“可行吗?”问题
Gui Gui programming (XIII) - event handling
【每周一坑】正整数分解质因数 +【解答】计算100以内质数之和
[weekly pit] information encryption + [answer] positive integer factorization prime factor
随机推荐
Is it difficult for small and micro enterprises to make accounts? Smart accounting gadget quick to use
Notes on beagleboneblack
【每周一坑】信息加密 +【解答】正整数分解质因数
Node.js: express + MySQL实现注册登录,身份认证
5. 無線體內納米網:十大“可行嗎?”問題
5. 无线体内纳米网:十大“可行吗?”问题
02 basic introduction - data package expansion
I've seen many tutorials, but I still can't write a program well. How can I break it?
【每周一坑】计算100以内质数之和 +【解答】输出三角形
[network planning] Chapter 3 data link layer (4) LAN, Ethernet, WLAN, VLAN
Gui Gui programming (XIII) - event handling
Unity load AB package
8086 instruction code summary (table)
Wonderful coding [hexadecimal conversion]
JMeter server resource indicator monitoring (CPU, memory, etc.)
[Yann Lecun likes the red stone neural network made by minecraft]
Tencent T3 teaches you hand in hand. It's really delicious
B-jiege's tree (pressed tree DP)
[weekly pit] positive integer factorization prime factor + [solution] calculate the sum of prime numbers within 100
Poj3617 best cow line