top of page

Game Dev Log #2 –  I made a game: Attack of the Bacilli

  • Writer: Ian Vicino
    Ian Vicino
  • Jun 7
  • 5 min read

Updated: Jun 10

I finished making the game! Woo!!! It took me forever to create an executable version of the file. After wrestling unsuccessfully with the code to make a version I could upload to my site as an HTML-embedded game, I finally successfully managed to create an executable version of the game, at least. Before I put a link to the game, let me first describe a bit of the process.


To create this game, as mentioned in my last post, I used a tutorial to get my coding juices flowing once again. The specific tutorial I used can be found here: https://dev.to/lovelacecoding/how-to-build-your-first-python-game-a-step-by-step-guide-to-creating-a-simple-shooter-with-pygame-f0k. This tutorial was fantastic because it gave me the skeleton to expand upon to create my game, which I called the Attack of the Bacilli. (Bacteria come in two main shapes: cocci, spherical bacteria, and bacilli, rod-shaped bacteria. I chose to use the bacilli shape for my game, as common pathogenic bacteria take this shape.) The tutorial started out showing the basic skeleton for any Pygame-created game, which you can see below:

__________________________________________________________________________________

# Relearning pygame
# Ian Vicino

import pygame
import sys

# Initialize PyGame
pygame.init()

# Set up the game window
screen_width = 800
screen_height = 600
screen = pygame.display.set_mode((screen_width, screen_height))
pygame.display.set_caption("Simple Shooter Game - Trial game - Ian Vicino")

# Set the frame rate
clock = pygame.time.Clock()

# Main game loop
while True:
    for event in pygame.event.get():    # event handling loop
        if event.type == pygame.QUIT:   
            pygame.quit()
            sys.exit()

    # Fill the screen with a color (black in this case)
    screen.fill((0, 0, 0))

    # Update the display
    pygame.display.update()

    # Cap the frame rate at 60 frames per second
    clock.tick(60)

__________________________________________________________________________________


Then the tutorial began teaching how to add player and enemy type characters. I won’t show all of the code; you can follow the tutorial link if you are interested in following the path I took to learn to create a game using Python, but I will paste the final skeleton of code I used to create my game. You can find that below: (If you don't care much for the code, you can skip straight to the game information)

__________________________________________________________________________________


# Relearning pygame
# Ian Vicino

import pygame, sys, random


# Initialize PyGame
pygame.init()

# Set up the game window
screen_width = 800
screen_height = 600
screen = pygame.display.set_mode((screen_width, screen_height))
pygame.display.set_caption("Simple Shooter Game - Trial game - Ian Vicino")

# Set the frame rate
clock = pygame.time.Clock()

# Player settings
player_width = 50
player_height = 60
player_x = screen_width // 2 - player_width // 2
player_y = screen_height - player_height - 10
player_speed = 5

# Bullet settings
bullet_width = 5
bullet_height = 10
bullet_speed = 7
bullets = []

# Enemy settings
enemy_width = 50
enemy_height = 60
enemy_speed = 2
enemies = []

# Spawn an enemy every 2 seconds
enemy_timer = 0
enemy_spawn_time = 2000

# Collision detection function
def check_collision(rect1, rect2):
    return rect1.colliderect(rect2)     #Function of pygame where it finds out if rectangles are touching

# Main game loop
while True:
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            pygame.quit()
            sys.exit()
        if event.type == pygame.KEYDOWN:
            if event.key == pygame.K_SPACE:
                bullet_x = player_x + player_width // 2 - bullet_width // 2
                bullet_y = player_y
                bullets.append(pygame.Rect(bullet_x, bullet_y, bullet_width, bullet_height))

    # Handle player movement
    keys = pygame.key.get_pressed()             # Only good if keys will not be pressed in rapid succession
    if keys[pygame.K_LEFT] and player_x > 0:
        player_x -= player_speed
    if keys[pygame.K_RIGHT] and player_x < screen_width - player_width:
        player_x += player_speed

    # Update bullet positions
    for bullet in bullets:
        bullet.y -= bullet_speed
    bullets = [bullet for bullet in bullets if bullet.y > 0]

    # Update enemy positions and spawn new ones
    current_time = pygame.time.get_ticks()
    if current_time - enemy_timer > enemy_spawn_time:
        enemy_x = random.randint(0, screen_width - enemy_width)
        enemy_y = -enemy_height
        enemies.append(pygame.Rect(enemy_x, enemy_y, enemy_width, enemy_height))
        enemy_timer = current_time

    for enemy in enemies:
        enemy.y += enemy_speed

    # Check for collisions
    for bullet in bullets[:]:
        for enemy in enemies[:]:
            if check_collision(bullet, enemy):
                bullets.remove(bullet)
                enemies.remove(enemy)
                break

    # Remove enemies that are off the screen
    enemies = [enemy for enemy in enemies if enemy.y < screen_height]

    # Fill the screen with black
    screen.fill((0, 0, 0))

    # Draw the player
    pygame.draw.rect(screen, (0, 128, 255), (player_x, player_y, player_width, player_height))

    # Draw the bullets
    for bullet in bullets:
        pygame.draw.rect(screen, (255, 255, 255), bullet)

    # Draw the enemies
    for enemy in enemies:
        pygame.draw.rect(screen, (255, 0, 0), enemy)

    # Update the display
    pygame.display.flip()

    # Cap the frame rate at 60 FPS
    clock.tick(60)

__________________________________________________________________________________

As you can see, it gets more complicated very quickly as the code needs to read user input and react appropriately. Python is very readable, however, and if you want to figure out what a piece of code is doing, you can figure it out easily with enough time. If you are interested in getting an introduction to how to code using Python, feel free to reach out, and we can work something out so you can get coding in no time.


After finishing the tutorial, I decided to expand upon it, which ended up in this first version of my game. All the character images are made using either freely available images or AI-generated images. The sound effects are my creation, which you will hear when you download the game and check it out.


I may decide to expand upon the game further, with new enemies, some boss enemies, and new upgrades, but only if I get a good response from this go around. In either case, it is a good intro to Pygame, and I plan to make new games after this is up for a week. I also still need to restructure my code to be able to make my game playable online, which is my next immediate goal.


As promised, here is a link to my game (https://neurodude64.itch.io/attack-of-the-bacilli), which I hosted on Itch.io, where you can find a couple of other games I created using the Unity engine. Let me know what you think of my game, and leave a comment below so I can know how I am doing. If you like what I am doing, subscribe so you won’t miss out on my next post and share my site with your friends, or on social media. It helps more than you know! Thank you!


(Update: (BIG NEWS) I have made the game playable online. It can play without the sound effects. I will work on making the executable version of the game with sound effects soon, so stay tuned for that update in a new blog post.)


Description of game:


Attack of the Bacilli

You are a lone B-cell trying to protect your body from being killed by an onslaught of bacteria, bacilli by the looks of it, maybe E. coli. 

 

Controls:

  • left and right arrow keys to move,

  • Space bar to shoot antibodies (look like rectangles, my bad)

  • Use the arrow keys to upgrade

 

Try to succeed and defend your home!

 

 

 

 

 
 
 

Comments


bottom of page