Skip to main content

Indie game storeFree gamesFun gamesHorror games
Game developmentAssetsComics
SalesBundles
Jobs
TagsGame Engines
A jam submission

Basic Space InvadersView game page

Submitted by Taptastico — 1 day, 20 minutes before the deadline
Add to collection

Play game

Basic Space Invaders's itch.io page

Large Language Model system
ChatGPT

Link to LLM
https://chat.openai.com/

Prompt
import pygame
import random

# Initialize Pygame
pygame.init()

# Set up the game window
window_width, window_height = 800, 600
window = pygame.display.set_mode((window_width, window_height))
pygame.display.set_caption("Space Invaders")

# Set up the player
player = [
" [] ",
" [][][] "
]

player_width = len(player[0]) * 10
player_height = len(player) * 10
player_x = window_width // 2 - player_width // 2
player_y = window_height - player_height - 10
player_speed = 5

# Set up the enemy
enemy_width, enemy_height = 50, 50
enemy_x = random.randint(0, window_width - enemy_width)
enemy_y = random.randint(50, 150)
enemy_speed = 2

# Set up the projectile
projectile_width, projectile_height = 5, 10
projectile_x, projectile_y = 0, 0
projectile_speed = 7
projectile_state = "ready"

# Game loop
running = True
clock = pygame.time.Clock()

def fire_projectile(x, y):
global projectile_state
projectile_state = "fire"
pygame.draw.rect(window, (255, 0, 0), (x, y, projectile_width, projectile_height))

while running:
clock.tick(60) # Set the frame rate

# Handle events
for event in pygame.event.get():
if event.type == pygame.QUIT:
running = False

# Handle player inputs
if event.type == pygame.KEYDOWN:
if event.key == pygame.K_SPACE:
if projectile_state == "ready":
projectile_x = player_x + player_width // 2 - projectile_width // 2 - 5 # Move left by 5 pixels
projectile_y = player_y
fire_projectile(projectile_x, projectile_y)

# Move the player
keys = pygame.key.get_pressed()
if keys[pygame.K_LEFT] and player_x > 0:
player_x -= player_speed
if keys[pygame.K_RIGHT] and player_x < window_width - player_width:
player_x += player_speed

# Move the enemy
enemy_x += enemy_speed
if enemy_x <= 0 or enemy_x >= window_width - enemy_width:
enemy_speed *= -1
enemy_y += enemy_height

# Move the projectile
if projectile_state == "fire":
projectile_y -= projectile_speed
if projectile_y <= 0:
projectile_state = "ready"

# Collision detection
if (player_x < enemy_x + enemy_width and
player_x + player_width > enemy_x and
player_y < enemy_y + enemy_height and
player_y + player_height > enemy_y):
running = False # Game over if player collides with enemy

# Projectile-enemy collision
if (projectile_x < enemy_x + enemy_width and
projectile_x + projectile_width > enemy_x and
projectile_y < enemy_y + enemy_height and
projectile_y + projectile_height > enemy_y):
enemy_x = random.randint(0, window_width - enemy_width)
enemy_y = random.randint(50, 150)
projectile_state = "ready"

# Draw the game objects
window.fill((0, 0, 0)) # Clear the window

# Draw the player
for i, row in enumerate(player):
for j, char in enumerate(row):
if char == "[":
pygame.draw.rect(window, (255, 255, 255), (player_x + j * 10, player_y + i * 10, 10, 10))

# Draw the enemy
pygame.draw.rect(window, (255, 255, 255), (enemy_x, enemy_y, enemy_width, enemy_height))

# Draw the projectile
if projectile_state == "fire":
pygame.draw.rect(window, (255, 0, 0), (projectile_x, projectile_y, projectile_width, projectile_height))

pygame.display.update() # Update the display

# Quit the game
pygame.quit()

Leave a comment

Log in with itch.io to leave a comment.

Comments

No one has posted a comment yet