Game Development 12 min read

How to Supercharge a Python Alien Invasion Game into a Full‑Featured Shooter

This article walks readers through recreating the original Python alien‑invasion game, then details a step‑by‑step overhaul that adds a polished UI, scalable monster mechanics, multiple maps, and an in‑game shop, complete with code snippets and visual examples.

Python Crawling & Data Mining
Python Crawling & Data Mining
Python Crawling & Data Mining
How to Supercharge a Python Alien Invasion Game into a Full‑Featured Shooter

Introduction

The author introduces the second article in the "Python Crawlers and Data Mining" series, referencing the first article and inviting readers to follow the public account for more content.

Original Version Recreation

The original 1.0 version of the alien‑invasion game is presented with screenshots and a list of its basic features:

Player controls a ship (displayed as a cannon) at the bottom of the screen, moving left/right and shooting zombies.

Zombies are arranged in three fixed rows with constant spacing; their number does not change with level.

Player has three lives shown in the top‑left corner; contact with zombies or reaching the bottom reduces a life.

Shooting requires pressing the space key each time; continuous fire is not supported.

The zombie fleet moves horizontally and steps forward when hitting a screen edge; if not cleared quickly, the fleet speeds up.

Only one monster type exists, without health points; higher levels only increase movement speed.

The gameplay is simple, lacking effects, skills, items, or maps.

Score is not persisted between runs; the highest score is lost after the program exits.

Images illustrate the original interface, life icons, score display, level indicator, and the file structure (alien, alien_invasion, bullet, button, game_stats, scoreboard, settings, ship).

The source code for the original version can be downloaded from the provided link.

Modification Plan

1. Eye‑catching UI

The upgraded version, named "Interstellar Frontline," introduces a custom login screen with a start button, a shop toggle (key "s"), and a contact link. The UI uses several images for background, title, play button, shop button, and contact icons.

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. Diverse maps, monsters, and health

Monster count, health, and speed now scale with the current level. The number of aliens is chosen randomly within a range that grows with the level, and each alien’s health increases at specific thresholds (e.g., level 5, 10, 15, 25, 30, 40, 45, 50). Monsters can also teleport within a short distance to evade bullets. Different enemy types appear at higher levels, including a shielded robot (3 HP) and a boss with a long red health bar. Every ten levels the background map changes.

def _create_fleet(self):
    "创建怪物群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. In‑game shop and economy

The upgraded version adds a shop system. Gold (earned by killing enemies) appears in the top‑left corner, while diamonds (a premium currency) are shown in the top‑right. Hovering over items displays a semi‑transparent tooltip with name, price, category, and description.

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

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

Conclusion

The author wraps up the first part of the "Super‑Modified Alien Invasion" series, encouraging readers to follow the account for future installments and to share their own modification ideas in the comments or via private message.

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

PythontutorialUI designPygamecode-modificationAlien Invasiongame-development
Python Crawling & Data Mining
Written by

Python Crawling & Data Mining

Life's short, I code in Python. This channel shares Python web crawling, data mining, analysis, processing, visualization, automated testing, DevOps, big data, AI, cloud computing, machine learning tools, resources, news, technical articles, tutorial videos and learning materials. Join us!

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.