An article teaches you python alien invasion (game development)

Sophomore Elementary School on "" python from entry to practice "," alien invasion saw a small part of the project that greatly increased interest, he decided to write one himself.
python alien invasion (game development)

Add alien spaceship game to move up and down function:

Function source code:

The above code is to monitor click events in game_functions.py keyboard, the keystrokes and mouse events and respond by check_events.

The initial preparation of the spacecraft position and movement flag ship.py adjust the position of the spacecraft core functions:

Then call in the main file alien_invation.py the main game loop:

1.2

Add a background sound effects for the game, explosive sound and shooting sound:

Create a new folder, and then call in the main file alien_invation.py of run_game () in.

1.3

The player scoring the highest score before adding the player level "Score", "High Score", "Level" label :( three types of conversion to string through the digital display on the graphical interface)

Function source code:

The score is converted into a rendered image will score in the top right corner of the screen;

Positioning the string: in which: the actual value added high_score, score, level, and

The rating on the scores below:

1.4

Add game pause function, such as pressing a button, to realize the game is paused:

Function source code:

Create a pause button in the main file alien_invasion.py in:

Initialization pause button,

To pause the game by listening to mouse movement coordinates (x, y) click event.

1.5

The highest score permanent storage, re-open the game when, still can normally read and display;

Function source code:

High.json create a file, save the use of json achieve the highest score of the show in game_stats.py.

1.6

Only when the end of the game, only the highest scoring game of comparisons and updates;

1.7

Add a button to start the play of the game, the game ends when the player did not hit the target three times and re-display the Play button, allowing the player to by clicking the button again to start the game;

Function source code:

Create a play button alien_invasion.py in the master file, the class initialization button

Are check_play_button monitor play button is clicked events to restart the game

1.8

Advanced inserted in the fixing alien alien queue level (image different from ordinary alien, although higher Points, faster), and displays the blood boos.

Function source code:

At the same time imitate the bullet class write BossBullet categories:

Write checkpoint boos object stream events game_functions file

Project Resource Download: https://download.csdn.net/download/h471507602/11228787

Author E-mail: [email protected]

Author: This programmer is not too cold
Source: CSDN
Original: https://blog.csdn.net/h471507602/article/details/91042425
Copyright: This article is a blogger original article, reproduced, please attach Bowen link!

Guess you like

Origin blog.csdn.net/PyhtonChen/article/details/94619920