Super magic modified alien invasion games - 01

catalogue

1, Reproduction of original version

The source code of the original version 1.0 is available for free at:

2, Magic change ideas

1. Eye catching UI interface

2. Realize the diversification of maps, monsters and blood volume

3. Realize the game mall and enrich the financial system

III. to be continued

Many friends are from python Programming: learning python from introduction to practice. This book is more suitable for beginners.

In this book, there is a pygame game project, alien invasion.

For beginners, it is a good choice to learn python from a small game. However, I think the alien invasion game in this book is too monotonous and rough, so I decided to upgrade it to super magic revision.

This paper first gives the complete code of the original 1.0 version and the original 1.0 version of the game according to this book, and then gradually analyzes and changes its magic to a new version.

Compared with the monotonous and boring original version, the magic modified version is still a shooting game in addition to the basic playing method, and it can hardly be seen that it has anything to do with the original version.

1, Reproduction of original version

Original version 1.0:

The original version 1.0 has the following features:

1. Players can control the muzzle at the bottom of the screen (the book says it's a spaceship) to move left and right and shoot zombies

2. The zombie group is fixed in 3 rows, with a fixed number and a fixed spacing. It will not change with the upgrade of the level

3. The player has 3 lives, and the upper left corner represents the remaining life. If the zombie group encounters or the zombie group reaches the bottom of the screen, life - 1

4. Players should press the shooting key every time they shoot (here is a space), and they can't shoot continuously

5. The corpse group as a whole moves left and right and goes further when it meets the edge of the screen. If the zombies at the edge of the corpse group cannot be eliminated in time, the corpse group will move very fast

6. There is only one kind of monster, and the monster has no set blood volume. The level upgrade is just that the monster moves from left to right faster

7. Monotonous playing method, no special effects, no skills, no props, no maps

8. Score storage cannot be realized, and the highest score record during each program run will not be saved

It can only be said that the original version 1.0 implements the basic framework of a small game, as shown in the following figure:

At this time, there are three cannon icons in the upper left corner, which means I still have three lives.

The top center of the screen is the highest score, and the top right corner of the screen is the current score. Since this is the first game after running the program, the current score is the highest score.

The number below the current score in the top right corner of the screen is the current level. Eliminate all zombies and enter the next level. With the upgrading of the level, the movement speed of the corpse group will be faster and faster.

If the zombie group encounters or the zombie group reaches the bottom of the screen, the life will be reduced by one. In the above figure, there are only two lives left.

The files used in the original version 1.0 are as follows:

Among them, there are categories, and each document has its own clear division of labor. Alien is specially written by alien, alien_invasion is the main program, bullet is to control bullets and related parameters, button is to control the start game button, game_stats are some initialization settings of the game, scoreboard is the control score panel, settings are used for game parameter settings, and ship specifically controls the spacecraft.

The pictures used in the original version 1.0 are also very simple. There are only one alien and one spaceship in images. Here I use a zombie and a cannon. You can also choose your favorite image to replace.

The source code of the original version 1.0 is available for free at:

https://download.csdn.net/download/x978404178/20299596?spm=1001.2014.3001.5501 

2, Magic change ideas

This article will initially launch the version after magic change, which may be recorded as magic change version 2.0.

1. Eye catching UI interface

Through the carefully designed login cover, the game is named starfront, and the following effects are achieved:

This login interface supports clicking the start game button to start the game. Click the mouse or press the s key on the keyboard to enter / exit the points mall. Click the mouse to contact us to see the author information.

Part code:

        self.color=(230,230,230)
        self.fm = pygame.image.load('images/fm.png').convert_alpha()
        self.title = pygame.image.load('images/title.png').convert_alpha()
        self.titlerect = pygame.Rect(-190, -60, 1920, 1000)  # Rectangle (x,y,width,height)
        self.play = pygame.image.load('images/play.png').convert_alpha()
        self.playrect = pygame.Rect(645,300, 280, 280)#Rectangle (x,y,width,height)
        self.shop = pygame.image.load('images/shop.png').convert_alpha()
        self.shoprect = pygame.Rect(0, 700, 330, 158)  # Rectangle (x,y,width,height)
        self.lianxi1 = pygame.image.load('images/lianxi1.png').convert_alpha()
        self.lianxi1rect = pygame.Rect(1330, 780, 187, 80)  # Rectangle (x,y,width,height)

        self.shop2 = pygame.image.load('images/shop2.png').convert_alpha()
        self.shop2rect = pygame.Rect(1395, 735, 140, 126)  # Rectangle (x,y,width,height)

2. Realize the diversification of maps, monsters and blood volume

The generation quantity of all monsters is related to the level. The generation quantity is random within a certain limit, but the higher the level, the more the generation quantity tends to be.

The monster generation range is also generated randomly within a certain limit.

The movement speed of the monster is related to the level. The higher the level, the faster the forward speed, but a speed limit is set.

The monster moves in a position with a certain probability and can dodge the bullets of the ship.

The first level is a lovely little robot, with 1 HP. In the third level, there is a robot with a shield, with 3 HP.

The BOSS appeared in the 5th level, with its red blood bar on the top, which is very long.

BOSS, how can you be the BOSS if you don't resist beating?

I set up rich maps in the game and switch one scene every 10 levels.

The boss arrangement follows the law of one small boss every 5 levels and one big boss every 10 levels, so that players can enjoy the fierce battle.

Part code:

    def _create_fleet(self):
        "Create monster group 1"
        self.alien_bloodmax=1
        self.alien_blood=1
        if self.stats.level>=5:
            self.alien_bloodmax =2
            self.alien_blood = 2
            if self.stats.level >=10:
                self.alien_bloodmax = 3
                self.alien_blood = 3

                if self.stats.level >=15:
                    self.settings.guainum = 2
                    self.alien_bloodmax =5
                    self.alien_blood =5
                    if self.stats.level >=25:
                        self.alien_bloodmax =10
                        self.alien_blood =10
                        if self.stats.level >= 30:
                            self.alien_bloodmax = 20
                            self.alien_blood = 20

                            if self.stats.level >= 40:
                                self.settings.guainum = 3
                                self.alien_bloodmax = 50
                                self.alien_blood = 50
                                if self.stats.level >= 45:
                                    self.alien_bloodmax = 100
                                    self.alien_blood = 100
                                    if self.stats.level >= 50:
                                        self.alien_bloodmax = 150
                                        self.alien_blood = 150
        number_alien=random.randint(5+self.stats.level*1,15+self.stats.level*2)
        for row_number in range(number_alien):
            alien = Alien(self)
            self.aliens.add(alien)

3. Realize the game mall and enrich the financial system

How about the game mall made by Xiaobai himself? Can you see it?

The upper left corner is a gold coin, which is linked to the points obtained by killing monsters in the game.

The diamond in the upper right corner, as the name suggests, is a scarce resource belonging to krypton gold bosses and a few elite players.

Moving the mouse over the corresponding product will display translucent introduction, name, price, category and function.

Load picture and location:

self.gaosi1 = pygame.image.load('images/gaosi1.png').convert_alpha()
self.gaosi1rect = pygame.Rect(230, 480, 751, 240)  # Rectangle (x,y,width,height)

Whether to display the product introduction is determined by the mouse position:

button3_clicked = self.gaosirect.collidepoint(mouse_pos)
if button3_clicked:
    self.screen.blit(self.gaosi1, self.gaosi1rect)

As for more explanation and source code of magic revision, we'll leave it for later explanation.

III. to be continued

This issue of the super magic modified alien invasion game-01 is here. Interested friends can pay attention to me. In the later stage, a series of articles such as fantasy-02-03 will be launched accordingly.

Friends who have better ideas about this game can also put forward your magic change ideas to make the game more interesting and fun, and let everyone collide with the sparks of innovative thinking. If you want your magic reform scheme to be implemented in the game, you can leave a message in the comment area below or send a private letter to the author. You are also welcome to add the author's wechat: Communist_ Belief learns to communicate.

 

Keywords: Python Game Development

Added by jwb666 on Wed, 19 Jan 2022 13:29:41 +0200