In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly introduces how to use Python to achieve the relevant knowledge of skiing games, the content is detailed and easy to understand, the operation is simple and fast, has a certain reference value, I believe you will have something to gain after reading this article on how to use Python to achieve skiing games, let's take a look.
Development tools
Python version: 3.6.4
Related modules:
Pygame module
And some modules that come with Python.
Environment building
Install Python and add it to the environment variable, and pip installs the relevant modules you need.
Introduction of principle
Rules of the game:
Players use the "AD" button or "←→" to control skiers in advance, trying to avoid the trees on the road and try to pick up flags on the road.
If you encounter a tree, you will get a score minus 50, and if you pick up a small flag, the score will be increased by 10.
Step by step:
Step1: define sprite classes
Because the game involves collision detection (collisions between skiers and trees and flags), we define two elves to represent skiers and obstacles (that is, trees and flags):
Among them, the skier should have the ability to shift to the left and right during the advance, and it is more reasonable for the skier to slow down during the offset so that it can be operated by the player. At the same time, skiers should have different postures to show their state when they glide:
Straight line:
A little to the left:
A lot to the left:
A little to the right:
A lot to the right:
In addition, although the skiers move left and right by moving the skiers themselves, the skiers move forward by moving obstacles.
Step2: randomly create obstacles
Now we need to define a function that randomly creates obstacles to call in the game's main loop:
Step3: main cycle of the game
First, let's initialize some parameters:
The purpose of creating the obstacle twice is to facilitate the connection of the picture.
Then we can define the main loop:
The contents of the main loop include:
Event monitoring, obstacle updating, collision detection and score display are easy to achieve.
Step4: other
It's up to everyone to play the start and end interface, so I wrote a simple start interface:
Effect:
This is the end of the article on "how to use Python to realize skiing games". Thank you for reading! I believe that everyone has a certain understanding of "how to use Python to achieve ski games" knowledge, if you want to learn more knowledge, welcome to follow the industry information channel.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.