Create an ghost-themed arcade game in a coding language of your choosing. Do not rely on external file uploads and instead create your own assets and designs.
Assistant
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.
In Ghostly Gauntlet, you play as a brave adventurer seeking to capture mischievous ghosts in a haunted mansion. The game is a classic arcade-style shooter where you must navigate through a maze of rooms, avoiding ghostly obstacles and collecting power-ups to aid in your quest.
Gameplay Features:
Player movement and shooting mechanics
Ghostly enemies with varying behaviors and difficulties
Power-ups for increased firepower and protection
A scoring system with increasing difficulty levels
Code Implementation:
I will implement the game using Python with the Pygame library.
Installation
To run the game, ensure you have Python and Pygame installed. You can install Pygame using pip:
bash
pip install pygame
Game Code
python
import pygame
import sys
import random
# Initialize Pygame
pygame.init()
# Set up some constants
WIDTH, HEIGHT = 800, 600
PLAYER_SIZE = 50
GHOST_SIZE = 30
POWER_UP_SIZE = 20
# Set up some colors
WHITE = (255, 255, 255)
RED = (255, 0, 0)
GREEN = (0, 255, 0)
BLUE = (0, 0, 255)
# Set up the display
screen = pygame.display.set_mode((WIDTH, HEIGHT))
# Set up the fonts
font = pygame.font.Font(None, 36)
# Set up the player
player_pos = [WIDTH / 2, HEIGHT / 2]
player_vel = [0, 0]
player_speed = 5
player_health = 100
# Set up the ghosts
ghosts = []
for _ in range(10):
ghost_pos = [random.randint(0, WIDTH), random.randint(0, HEIGHT)]
ghost_vel = [random.randint(-2, 2), random.randint(-2, 2)]
ghosts.append({"pos": ghost_pos, "vel": ghost_vel})
# Set up the power-ups
power_ups = []
for _ in range(5):
power_up_pos = [random.randint(0, WIDTH), random.randint(0, HEIGHT)]
power_ups.append({"pos": power_up_pos, "type": random.choice(["ammo", "shield"])})
# Set up the bullets
bullets = []
# Set up the score
score = 0
# Game loop
while True:
for event in pygame.event.get():
if event.type == pygame.QUIT:
pygame.quit()
sys.exit()
elif event.type == pygame.KEYDOWN:
if event.key == pygame.K_SPACE:
bullets.append({"pos": [player_pos[0], player_pos[1]], "vel": [0, -10]})
keys = pygame.key.get_pressed()
if keys[pygame.K_UP]:
player_vel[1] = -player_speed
elif keys[pygame.K_DOWN]:
player_vel[1] = player_speed
else:
player_vel[1] = 0
if keys[pygame.K_LEFT]:
player_vel[0] = -player_speed
elif keys[pygame.K_RIGHT]:
player_vel[0] = player_speed
else:
player_vel[0] = 0
player_pos[0] += player_vel[0]
player_pos[1] += player_vel[1]
# Ensure player stays on screen
if player_pos[0] < 0:
player_pos[0] = 0
elif player_pos[0] > WIDTH - PLAYER_SIZE:
player_pos[0] = WIDTH - PLAYER_SIZE
if player_pos[1] < 0:
player_pos[1] = 0
elif player_pos[1] > HEIGHT - PLAYER_SIZE:
player_pos[1] = HEIGHT - PLAYER_SIZE
# Move ghosts
for ghost in ghosts:
ghost["pos"][0] += ghost["vel"][0]
ghost["pos"][1] += ghost["vel"][1]
# Bounce ghosts off edges
if ghost["pos"][0] < 0 or ghost["pos"][0] > WIDTH - GHOST_SIZE:
ghost["vel"][0] *= -1
if ghost["pos"][1] < 0 or ghost["pos"][1] > HEIGHT - GHOST_SIZE:
ghost["vel"][1] *= -1
# Check collision with player
if (ghost["pos"][0] < player_pos[0] + PLAYER_SIZE and
ghost["pos"][0] + GHOST_SIZE > player_pos[0] and
ghost["pos"][1] < player_pos[1] + PLAYER_SIZE and
ghost["pos"][1] + GHOST_SIZE > player_pos[1]):
player_health -= 10
ghosts.remove(ghost)
# Move bullets
for bullet in bullets:
bullet["pos"][1] += bullet["vel"][1]
# Check collision with ghosts
for ghost in ghosts:
if (bullet["pos"][0] < ghost["pos"][0] + GHOST_SIZE and
bullet["pos"][0] > ghost["pos"][0] and
bullet["pos"][1] < ghost["pos"][1] + GHOST_SIZE and
bullet["pos"][1] > ghost["pos"][1]):
score += 10
ghosts.remove(ghost)
bullets.remove(bullet)
break
# Check if bullet is off screen
if bullet["pos"][1] < 0:
bullets.remove(bullet)
# Move power-ups
for power_up in power_ups:
# Check collision with player
if (power_up["pos"][0] < player_pos[0] + PLAYER_SIZE and
power_up["pos"][0] + POWER_UP_SIZE > player_pos[0] and
power_up["pos"][1] < player_pos[1] + PLAYER_SIZE and
power_up["pos"][1] + POWER_UP_SIZE > player_pos[1]):
if power_up["type"] == "ammo":
score += 50
elif power_up["type"] == "shield":
player_health += 20
power_ups.remove(power_up)
# Draw everything
screen.fill((0, 0, 0))
pygame.draw.rect(screen, WHITE, (player_pos[0], player_pos[1], PLAYER_SIZE, PLAYER_SIZE))
for ghost in ghosts:
pygame.draw.rect(screen, RED, (ghost["pos"][0], ghost["pos"][1], GHOST_SIZE, GHOST_SIZE))
for bullet in bullets:
pygame.draw.rect(screen, GREEN, (bullet["pos"][0], bullet["pos"][1], 5, 10))
for power_up in power_ups:
if power_up["type"] == "ammo":
pygame.draw.rect(screen, BLUE, (power_up["pos"][0], power_up["pos"][1], POWER_UP_SIZE, POWER_UP_SIZE))
elif power_up["type"] == "shield":
pygame.draw.rect(screen, (255, 255, 0), (power_up["pos"][0], power_up["pos"][1], POWER_UP_SIZE, POWER_UP_SIZE))
# Draw score and health
score_text = font.render(f"Score: {score}", True, WHITE)
screen.blit(score_text, (10, 10))
health_text = font.render(f"Health: {player_health}", True, WHITE)
screen.blit(health_text, (10, 50))
# Update display
pygame.display.flip()
# Cap framerate
pygame.time.Clock().tick(60)
# Check game over
if player_health <= 0:
print("Game Over!")
pygame.quit()
sys.exit()
How to Play:
Run the code to start the game.
Use the arrow keys to move the player.
Press the space bar to shoot bullets.
Collect power-ups to increase your score and health.
Avoid ghosts and try to capture them by shooting them.
Tips and Variations:
Increase the difficulty by adding more ghosts or decreasing the player's health.
Add different types of power-ups, such as increased speed or invincibility.
Create a level system with increasing difficulty and rewards.
Implement a high score system to track player progress.