World War II aircraft to achieve python source code + materials + Project Analysis

A. Project Analysis

Python programming projects

World War II aircraft topic
Department of Information Science and Technology
Professional Computer Science and Technology
Name Star
class school No. 37
instructors xxx

Two O December Jiunian

One. Background and significance of the research system

Today's society is an information society and a knowledge-based economy era. Since the world's first computer, ENIAC came in 1946 to the present, the rapid development of the computer industry. With the era of global information networks and universal global information sharing as a symbol of the "global information network revolution" booming, the world is already entered in the field of computer information management of fierce competition, computer, naturally becomes indispensable in people's lives part small.
In the past, one need only by means of film, television, music, fashion and entertainment. Today, to the game as the representative of the electronic entertainment is becoming a mainstream entertainment. Since the rapid development of CPU and graphics cards and other devices, offers the possibility for people to develop a more dazzling and colorful game. Development and social progress of the times, / science and technology growing at rapid pace forward rapidly. Development of computer technology more rapidly and widely. We can say that the vast majority of modern computers has been involved in the industry. At present the complicated game software abound, both online and network games or table games, a two-dimensional or three-dimensional space, and more from the stand-alone version of the game bred from. Learn to make simple stand-alone version of the game, help beginners learn the concept of game production. At present, whether in the domestic or world-wide, bamboo shoots after the rain game industry are booming, more and more and more entertaining games to be developed.

two. Development status at home and abroad

96, 97 years of domestic game products are stand-alone version of the game, at the time of the market, although not as good as the quality and level of foreign products, but also occupy a certain market, such as "Paladin", "Three Kingdoms" series with a distinctive Chinese characteristics and atmosphere of the game in the market set off a wave of climax. Launched in 1998 Lianzhong and China and other old game center gaming platform marks the pioneers of computer games and take root in China. But in 1999, in the absence of the formation of mainstream products, policy uncertainty, including the development of financial problems and other reasons the domestic game began to decline. Until 2000, the advent of online games and quickly caught our game industry has only gradually recover, but due to the large gap between investment, started late and other reasons the foreign game and relatively uncompetitive.
Today, the online games into the Golden Age, the behavior of some people has become the main entertainment. China Netease, Tencent, Ninetowns, perfect and other companies flourishing domestic online games gradually into the international market, but also on the development of a network of truly global network, but also online games around the world, playing a game with global signs are everywhere . A large number of overseas game into the Chinese market, computer games flowers scene, along with economic progress, the development of computer technology, this phenomenon will be intensified.

three. Feasibility Analysis

(1) technical feasibility
analyzes the technical possibilities of the technical requirements to complete development tasks, hardware and software to meet the needs of developers. JetBrains is a powerful software development tools used.
PyCharm 2019.1.3 x64, strong expansion capability is a characteristic of the software, the software written for aircraft war game and have a good sound effect support, but also many Pythoner favorite compiler. With the rapid development of the Internet industry, software development platform and hardware technology while constantly updated progress. High-capacity, improve reliability, low price also makes software development is feasible. Compile the needs of the game can be completely borne by the Pycharm compiler.
Based on the above situation and consider the development of this game is technically feasible.
(2) economic feasibility
Because this game is more compact, lightweight, lower development costs. In addition, the software is stable, post-maintenance simple, practical, long-term use can be developed once. When a user has a new demand, only on demand, changes in the original code base, lower maintenance costs.
Based on the above situation and backrest, this game is economically perfectly acceptable.
(3) social feasibility
legal considerations: This game is in my interests, independently developed. Python-based game to complete, drawing functions similar software on the market, collect and summarize user requirements, develop design ideas, combined with the actual game entities exist, innovation and development.
User Feasibility: This game requires the user, there is no complex and cumbersome to operate, easy to use. Administrators use the software in a simple understanding of the process can be carried out after the back-office management, no extra learning to use part of cost savings.
From the above analysis, the feasibility of this game in terms of society is entirely feasible.

four. Overall design principles

The overall proposed design principle is to ensure the success of the system construction, and to plan for the sustainable development of the system. Therefore, system design, adhere to the following principles:
Simplicity: the premise of the game needs to achieve, as far as possible to ensure the game is simple and easy to operate. On the one hand, a simple operation will enhance the gaming experience, on the other hand when the operation is too complex, the introduction of the game to achieve more problems and vulnerabilities.
Relevance: This project is chosen as the programming language Python airplane war game, with clear objectives for the project requirements, the specific requirements of a particular implementation, and rightly so.
Practicality: World War II aircraft is an excellent leisure and entertainment software, game in the series since the birth of the popular favorite players, entertaining and mind, relax and reduce stress. And because the game is more popular, most of the players are familiar with the game mode of operation, more willing to use this game, so the game has a strong practical.
Consistency: The game of the aircraft used is the same style of aircraft and various aircraft classes by inheriting the base class aircraft come with high visual consistency. Sign tkinter interface module uses the master interface module using pygame be written, on the main interface elements of the system using the label insertion, with high functional consistency.

Fives. demand analysis

The basic set of game
user registration and login
1. Login to registered users interface:
Here Insert Picture Description
Here Insert Picture Description
2. registration if the user already exists, a warning will pop up the interface:

Here Insert Picture Description
3. If the login user does not exist, a warning will pop up the interface:
Here Insert Picture Description

Click Yes it will enter the registration interface.
4. If the user name or password is empty, a warning screen will pop up:

Here Insert Picture Description
Start of the game interface:

Here Insert Picture Description
Game Help: focuses on game play, built-in return key.

About: Description of the declaration and simple games, built-in return key.
Here Insert Picture Description

1, a total of medium and small 3 enemy aircraft models, namely low junior in high velocity.
2, destroy aircraft requires 1 rounds of ammunition, the aircraft requires 8 rounds of ammunition, 20 rounds of ammunition require large aircraft;
3, load background images and background music loaded into it, in which the background music for a loop.
Loop only need to set pygame.mixer.music.play (-1)
. 4, each have a plane eradication 1000 points, 4000 points in the plane, planes 10,000 points;
5, every 30 seconds a random prop supply, divided into two props, full-screen bombs and double bullets;
6, full-screen bomb can only store a maximum of three, double bullet can be maintained time of 18 seconds;
7, to gradually increase the difficulty of the game according to the score. Difficulty of improving performance to speed up the increase in the number of aircraft as well as speed.
8, real-time display Score: real-time display players score, rules are as follows:
to shoot down enemy aircraft Small Medium Large points, respectively, can be obtained 1000,6000,10000
we now add a score variable main function in the user's score statistics, scores and set the display font, we have placed the library of the font folder.
(It should be noted here is that the file path to your fonts are put in Chinese can not appear !!!
then add 10,000 points before the big crash to rebuild enemy, the enemy of small and medium empathy.
Then draw our aircraft when the fraction drawn to the interface.
9, (1) we plane
creating module named myplane, and then all the properties and methods defined in the inside of our aircraft.
main module in response to user operation of the keyboard, in response to user keyboard there are two ways:
[1], by detecting an event message is detected or if there is KEYDOWN KEYUP event, we know that the user presses a keyboard key. (This is our previous common method)
[2], calling key module in the get_pressed () method returns a sequence that contains the Boolean value of all the keys on the keyboard, if this value is True, It indicates that the button is pressed.
Here we have a suggestion: For the keyboard event detection accidentally triggered, we recommend using Method 1, for example, the game will set up a full-screen bomb, press the space bar when the explosion, which was triggered by accident, not always trigger, then use the first method is better; frequent trigger for keyboard events, we recommend using the second method, for example, to control the aircraft movement in the four arrow keys, we use the method.
(2) We airplane movement into unidirectional movement of the two-way movement, if the two players simultaneously pressing the arrow keys or the (A, S, W, E ) key will simultaneously move in the direction of synthesis, the method is implemented as our pLANE moving method is provided in eight directions, corresponding to the key according to the call.
(3) In order to increase the dynamic effects of our aircraft, we can achieve the effect of jet aircraft by two pictures (me1, png and me2.png) switch. Cadogan An image-in myplane.py in.

(4) create enemy:
the enemy is divided into three small medium large size, their speed is fast in a slow (the smaller the faster), at the top of the page, we need to create some random enemy, by page a randomly generated within the aircraft and the height above the outer screen 5 to ensure that the range of the aircraft and not to appear in a row.
Here Insert Picture Description

(3) enemy aircraft
enemy aircraft emerge from the top of the screen, moved downward to the top of the window, move around shooting, bullets shot number reaches a certain value, the downward movement is added.
10. The collision detection:
When our enemy aircraft and aircraft collision, the two sides should be total disaster, so that after the completion of the foundation before the operation, it is now increased tragic impact that occurs when the screen for each class. Import pictures tragic picture.
Collision detection using spritecollide () method:
collision and the crash is achieved, but we found that two aircraft had not really hit the contact, which is why?
This is because we use the ordinary spritecollide () method, which by default is the picture of the position of the rectangle area as a detection range, and rectangular area is much larger than our own aircraft, but we absolutely can do better we can do a perfect collision detection, how to achieve it?

sprite module There is a function called collide_mask can use this function required to detect objects have a mask attribute, which is used to specify the range of detection, about mask, Pygame also specifically wrote a mask module, which has called from_surface ( ) function, Surface objects Africa transparent portion may be labeled as mask and returns.
First, for each class of property plus mask.
self.mask = pygame.mask.from_sueface (self.image) # the non-transparent portion labeled as mask.
Then modify the collision detection code in the main function, the detection method is designated pygame.sprite.collide_mask.
But:
We have just actually exist obvious Bug, as part of the operation will lead to sound not playing correctly, you want to paint it crash picture, you need a lot of frames, but here you repeat it many times to play the sound of the crash a plane crash sound effects can only be played once, you want to play a lot of times, the result is that you have all the sound channels are filled, because Pygame default only eight sound channels. See detailed source code.
11, defined bullets:
Bullet There are two types: one is the only one to launch a A supply is granted super bullets, one can shoot two bullets. Bullet trajectory is straight up, slightly faster than the speed of the aircraft, if the bullet beyond the scope of the screen, then we will re-draw the bullets, airplanes where the bullet redrawn where, when hit enemy bullets also You need to be repainted. Therefore, we add a bullet to the active property, to determine whether the bullet needs to be redrawn, we define a single bullet module.
Transmitting a bullet is provided every 10 frames.
The next shot to detect whether the bullet hits the enemy, hit it, and enemy bullets active is set to False:
So far, so we basically invincible up. Whether large or medium-sized aircraft and enemy aircraft, we put it straight shot spike, which seems the enemy is weak now.
Therefore, give large and medium-sized aircraft and enemy aircraft add a property energy, show how much the value of life.
After that, we have to modify the main module, whenever the enemy was hit large bullet, we first subtract the value of its property enery 1, reduced to 0, only to crash into the enemy. We can also increase the display medium and large enemy blood groove, so that the child can be more intuitive to let players know how much health enemy left, which type of enemy aircraft and enemy aircraft was hit large bullet, but it will not fall when the machine, this time should be to have effects.
We are now enemy module add special effects picture, and add a hit for detecting whether the property was hit.
Then we hit mid-sized or large aircraft bullet, hit the value of the property to True
when then draw medium or large aircraft, we need to hit to make adjustments.
Here Insert Picture Description
12, pause function:
We add a pause in the upper right corner of the interface.
A total of four pictures, two pledged to suspend the two pledged to resume the game. Each group had a dark and light, when the mouse moves over an image (and not a mouse click), the picture will deepen, play a prompt effect.
We can know whether the user points the mouse, point the mouse at the moment, we have to get the position of the mouse, you can know whether the player points under the pause button response MOUSEBUTTONDOWN events. MOUSEMOTION by responding to events, we can change the style of the buttons.
In the main function Riga variable as a pause to suspend judgment sign.
Next we respond to events and MOUSEMOTION MOUSEBUTTONDOWN events:
have to move the mouse will be changed after clicking the pause button once, so that the mouse can change the icon immediately at the point of time.
Here Insert Picture Description
13, to enhance the degree of difficulty:
because the enemy slowly appear immutable, it is intolerable for the players, the player's gaming experience is to stimulate hope. We want the game difficulty increases as the player's score increases, there will be difficulty of the game is divided into five levels, each lift a level, it will increase the number of enemy or enemy movement speed increase.
But taking into account, if the time to level 5, the intensity will be great enemy, the player is very easy to fall into unfavorable situation, which requires players to provide large Sha Zhao: full-screen explosions.
This large Shazhao triggered by the spacebar to trigger the next initialization, we took three full-screen bombs, we can supply once every 30 seconds to get, but the most you can only load 3 aircraft.
As the trigger full-screen bombs belong to an accident, so we KEYDOWN incident response, and then detect whether event.key is K_SPACE it.
After the bomb run full-screen, we can get through a recharge every 30 seconds, recharge package has its own picture, also has its own running track (top to bottom), two new classes to implement, and instantiate the supply package only supply pack release timer, the timer is triggered once every 30 seconds.
Super bullets, when we receive supply of super bullets, bullets from the original single into a double, the bullet will increase the speed of the relative few. Length is 18 seconds super bullets, after this time, it automatically becomes a normal bullet. So we need a super bullet timer, in addition, we also need a variable to represent the type of bullet, and then generate super bullets.

14, the number of aircraft enemy players
who are not saints, practice makes no confusion. Play the game the same way, a person can not play a game to die once, to play to the end of time, even if there is, that is playing a game of genius, such a genius, Wan none, so we need to give the players the opportunity many times, even failed, eh, it does not matter, you still have the opportunity many times.
We define players have three chances, we need a variable in the main module in a life_num of Cadogan, indicates the number of lives. Here, then, there is a small detail, that is, after each of our aircraft sacrifice, you are born exactly one enemy position, it will be a direct result of our aircraft hang directly, so we need to set a time there was born 3 seconds of rhythm, in fact, the practice is not difficult.
We only need to add a class attribute in Myplane named invincible, first detected value of the property at the time of each collision.
15, the end of the game
over screen, the game over screen will show the history of the highest score and the score, and provide players two choices: Re-game or quit the game. A record of our players to pursue, the highest score history is stored in record.txt file.
The end of the game the decision:
game over judging is divided into two: the first is the user clicks the button to exit the game, exit the game will trigger the binding event, call the integration module integrates storage, then the program will force the end. The second is the number of attacks by the aircraft's own life is 0 (originally 3), the game interface is given prompt end of the game, then call the integral module and provides start again and quit the game, if you score more than the highest record, the system will It will record the user's account and achievements.

six. System test

(1) functional check: according to demand and achieve product, verify that the achievement of functional requirements, check if there are any omissions achieve deviation.
(2) checking the data: the main user, point information for inspections interaction between the database and the program portion.
(3) Performance tests: for airplanes in this war game, the main game is to check the frame rate, the existence of the phenomenon of Caton
(4) stability check: Because the event reading is obtained from the mouse and keyboard, which led to backstage higher frequency response, so check whether there is a program run terminated, restart and so on
summary and Outlook
the research is based on a practice hobbies, interests gave me a lot of power, which makes me in the face when various issues, total through various channels to find a solution. It was the first time you use Python to develop games, learning on one side, the side of game development and design process, encountered many problems, but also quite a few detours, but the ability to exercise self-solve problems. The research not only let me have a better understanding of Python, but also greatly enhance the programming capability, the ability to exercise their logical thinking and overall design, learned a lot. Through this research, I realized that a complete software development ideas is very important, it is crucial to our development process can be smoothly achieved. Before the project began, there must be systematic knowledge of software engineering, not only that, the location should include software architecture, coding and module division and the overall layout, only to finish these steps, in order to gradually develop a function that you want to achieve . Such will be able to achieve a multiplier effect.
According to the plan the entire software generally achieve a specific function of the game, although the game can run normally, but due to the limited knowledge and learning development cycle, there are many areas for improvement, to be further improved and perfected in the future.
After recommendations are summarized testers, this game should be fully functional as follows:
(1) BOSS is not set too much skill, there is no set pass animation.
Hope in the future, I can have the ability to improve the game, to optimize the system, improve the player experience, make the game more smooth appearance.

+ Source material:

https://github.com/jiahuantongxue/xinkong

It is determined to see the iron, and quickly focus on my public No. [programming] easy to play, receive learning resource (c, data structures, java, etc.) it!

Here Insert Picture Description

Published 50 original articles · won praise 8 · views 3056

Guess you like

Origin blog.csdn.net/jiahuan_/article/details/103987753