build a Sokoban style game where 4 AI square trying to race on a maze by colliding with to walls emitting a distinct sound for each square on collision with the walls, the levels start easy then get more difficult on each new level with a transition signaling new level and a hub to show final score for each competing bloc. no player intervention is needed. use coding language of your choice. provide full mvp code to test and validate our concept don't include any missing or non complete code.
use :
assets/audio/purple-orb.mp3
assets/audio/red-orb.mp3
assets/audio/yellow-orb.mp3
assets/audio/green-orb.mp3
for squares collision
assets/audio/yay-6120.mp3 for level completion
and assets/audio/power_up.mp3 for new level
expand on this with features like:
code
Proper maze generation
More sophisticated AI movement
Visual transitions between levels
A scoreboard or hub to display final scores
Additional sound effects and music
important : Fist levels should contain no obstalcle but you can play with the shape like example bellow :
Here's a simple MVP of a Sokoban-style racing game using Python with the Pygame library. This code includes basic maze generation, AI movement, collision detection with walls, sound effects, and level transitions. It starts with easy levels and increases in difficulty.
python
import pygame
import random
from collections import deque
# Initialize Pygame
pygame.init()
# Screen dimensions
SCREEN_WIDTH, SCREEN_HEIGHT = 800, 600
CELL_SIZE = 20
ROWS, COLS = SCREEN_WIDTH // CELL_SIZE, SCREEN_HEIGHT // CELL_SIZE
# Colors
WHITE = (255, 255, 255)
BLACK = (0, 0, 0)
WALL_COLOR = (128, 128, 128)
# Game window
screen = pygame.display.set_mode((SCREEN_WIDTH, SCREEN_HEIGHT))
pygame.display.set_caption("Sokoban Race")
# Load sounds
sounds = {
"purple": pygame.mixer.Sound("assets/audio/purple-orb.mp3"),
"red": pygame.mixer.Sound("assets/audio/red-orb.mp3"),
"yellow": pygame.mixer.Sound("assets/audio/yellow-orb.mp3"),
"green": pygame.mixer.Sound("assets/audio/green-orb.mp3"),
"level_complete": pygame.mixer.Sound("assets/audio/yay-6120.mp3"),
"new_level": pygame.mixer.Sound("assets/audio/power_up.mp3")
}
# Maze generation
def generate_maze():
maze = [[0 for _ in range(COLS)] for _ in range(ROWS)]
stack = [(random.randint(0, ROWS - 1), random.randint(0, COLS - 1))]
directions = [(0, 1), (1, 0), (0, -1), (-1, 0)]
while stack:
x, y = stack[-1]
maze[x][y] = 1
valid_dirs = []
for dx, dy in directions:
nx, ny = x + 2 * dx, y + 2 * dy
if 0 <= nx < ROWS and 0 <= ny < COLS and maze[nx][ny] == 0:
valid_dirs.append((dx, dy))
if valid_dirs:
dx, dy = random.choice(valid_dirs)
nx, ny = x + dx, y + dy
maze[x + dx][y + dy] = 1
stack.append((nx, ny))
else:
stack.pop()
return maze
# AI movement
def move_ai(ai, maze, direction):
new_x, new_y = ai[0] + direction[0], ai[1] + direction[1]
if 0 <= new_x < ROWS and 0 <= new_y < COLS and maze[new_x][new_y] != 1:
ai[0], ai[1] = new_x, new_y
return True
return False
# Main game loop
def main():
clock = pygame.time.Clock()
maze = generate_maze()
ais = [(1, 1), (1, 2), (1, 3), (1, 4)] # Starting positions for AI squares
level = 1
while True:
for event in pygame.event.get():
if event.type == pygame.QUIT:
pygame.quit()
quit()
screen.fill(BLACK)
for x in range(ROWS):
for y in range(COLS):
if maze[x][y] == 1:
pygame.draw.rect(screen, WALL_COLOR, (y * CELL_SIZE, x * CELL_SIZE, CELL_SIZE, CELL_SIZE))
for ai in ais:
pygame.draw.rect(screen, (random.randint(0, 255), random.randint(0, 255), random.randint(0, 255)),
(ai[1] * CELL_SIZE, ai[0] * CELL_SIZE, CELL_SIZE, CELL_SIZE))
# AI movement (simple random direction)
for ai in ais:
direction = (random.choice([-1, 0, 1]), random.choice([-1, 0, 1]))
if move_ai(ai, maze, direction):
sounds[f"{random.choice(['purple', 'red', 'yellow', 'green'])}"].play()
# Check for level completion
if all(ai[1] == COLS - 2 for ai in ais):
sounds["level_complete"].play()
level += 1
maze = generate_maze()
ais = [(1, 1), (1, 2), (1, 3), (1, 4)]
sounds["new_level"].play()
pygame.time.wait(2000)
pygame.display.update()
clock.tick(60)
if __name__ == "__main__":
main()
This code provides a basic framework that you can expand upon by adding more sophisticated AI, better maze generation algorithms, visual transitions between levels, and a scoreboard or hub to display final scores.