Write a python pygame prototype game. Create an isometric grid that will be the map for player and monster to move on. Allow to move the player with arrow keys and attack with spacebar. Create a couple of monsters on the map. When player is moving or attacking make the time flow normally but when player is not giving any input make time slow down 10x
Assistant
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.
Here's a Python Pygame prototype for an isometric grid-based game with the features you requested. This code creates a basic game with player movement, attacks, monsters, and time manipulation:
python
import pygame
import math
import random
import time
# Initialize Pygame
pygame.init()
# Constants
SCREEN_WIDTH = 800
SCREEN_HEIGHT = 600
TILE_SIZE = 32
GRID_WIDTH = 10
GRID_HEIGHT = 10
FPS = 60
# Colors
WHITE = (255, 255, 255)
BLACK = (0, 0, 0)
RED = (255, 0, 0)
GREEN = (0, 255, 0)
BLUE = (0, 0, 255)
# Set up the display
screen = pygame.display.set_mode((SCREEN_WIDTH, SCREEN_HEIGHT))
pygame.display.set_caption("Isometric Grid Game Prototype")
clock = pygame.time.Clock()
class GameObject:
def __init__(self, grid_x, grid_y):
self.grid_x = grid_x
self.grid_y = grid_y
self.attack_cooldown = 0
def get_screen_pos(self):
# Convert grid coordinates to isometric screen coordinates
screen_x = (self.grid_x - self.grid_y) * (TILE_SIZE / 2)
screen_y = (self.grid_x + self.grid_y) * (TILE_SIZE / 4)
# Center the grid on screen
screen_x += SCREEN_WIDTH / 2 - (GRID_WIDTH * TILE_SIZE / 4)
screen_y += SCREEN_HEIGHT / 2 - (GRID_HEIGHT * TILE_SIZE / 4)
return screen_x, screen_y
class Player(GameObject):
def __init__(self, grid_x, grid_y):
super().__init__(grid_x, grid_y)
self.color = BLUE
self.attack_range = 1
self.is_attacking = False
def move(self, dx, dy, grid):
new_x = self.grid_x + dx
new_y = self.grid_y + dy
# Check boundaries and collisions
if (0 <= new_x < GRID_WIDTH and 0 <= new_y < GRID_HEIGHT and
not grid[new_y][new_x]):
self.grid_x = new_x
self.grid_y = new_y
return True
return False
def attack(self, monsters):
if self.attack_cooldown <= 0:
self.is_attacking = True
self.attack_cooldown = 30 # Frames of cooldown
# Check for monsters in range
attacked = False
for monster in monsters[:]: # Create a copy to modify original list
distance = max(abs(self.grid_x - monster.grid_x),
abs(self.grid_y - monster.grid_y))
if distance <= self.attack_range:
monsters.remove(monster)
attacked = True
return attacked
return False
def update(self):
if self.attack_cooldown > 0:
self.attack_cooldown -= 1
if self.is_attacking:
self.is_attacking = False
def draw(self, screen):
screen_x, screen_y = self.get_screen_pos()
# Draw attack effect if attacking
if self.is_attacking:
pygame.draw.circle(screen, WHITE, (int(screen_x), int(screen_y)),
TILE_SIZE, 2)
# Draw player
pygame.draw.circle(screen, self.color, (int(screen_x), int(screen_y)),
TILE_SIZE // 4)
class Monster(GameObject):
def __init__(self, grid_x, grid_y):
super().__init__(grid_x, grid_y)
self.color = RED
self.move_cooldown = 0
def update(self, player, grid, time_scale):
if self.move_cooldown <= 0:
# Simple AI: move toward player
dx = 0
dy = 0
if player.grid_x > self.grid_x:
dx = 1
elif player.grid_x < self.grid_x:
dx = -1
if player.grid_y > self.grid_y:
dy = 1
elif player.grid_y < self.grid_y:
dy = -1
# Try to move
new_x = self.grid_x + dx
new_y = self.grid_y + dy
if (0 <= new_x < GRID_WIDTH and 0 <= new_y < GRID_HEIGHT and
not grid[new_y][new_x]):
self.grid_x = new_x
self.grid_y = new_y
self.move_cooldown = int(60 * time_scale) # Adjust cooldown based on time scale
else:
self.move_cooldown -= 1
def draw(self, screen):
screen_x, screen_y = self.get_screen_pos()
pygame.draw.rect(screen, self.color,
(int(screen_x - TILE_SIZE/4), int(screen_y - TILE_SIZE/8),
TILE_SIZE/2, TILE_SIZE/4))
def draw_isometric_grid(screen):
# Draw grid
for y in range(GRID_HEIGHT + 1):
for x in range(GRID_WIDTH + 1):
screen_x, screen_y = GameObject(x, y).get_screen_pos()
# Draw grid points
pygame.draw.circle(screen, BLACK, (int(screen_x), int(screen_y)), 2)
# Draw grid lines
for y in range(GRID_HEIGHT):
for x in range(GRID_WIDTH):
start_x, start_y = GameObject(x, y).get_screen_pos()
# Draw right diagonal
if x < GRID_WIDTH - 1:
end_x, end_y = GameObject(x + 1, y).get_screen_pos()
pygame.draw.line(screen, BLACK, (start_x, start_y), (end_x, end_y))
# Draw left diagonal
if y < GRID_HEIGHT - 1:
end_x, end_y = GameObject(x, y + 1).get_screen_pos()
pygame.draw.line(screen, BLACK, (start_x, start_y), (end_x, end_y))
def main():
# Initialize game objects
grid = [[False for _ in range(GRID_WIDTH)] for _ in range(GRID_HEIGHT)]
player = Player(GRID_WIDTH//2, GRID_HEIGHT//2)
monsters = [
Monster(1, 1),
Monster(GRID_WIDTH-2, 1),
Monster(1, GRID_HEIGHT-2)
]
running = True
time_scale = 1.0 # Normal speed
last_input_time = time.time()
while running:
# Event handling
player_input = False
for event in pygame.event.get():
if event.type == pygame.QUIT:
running = False
elif event.type == pygame.KEYDOWN:
player_input = True
last_input_time = time.time()
if event.key == pygame.K_LEFT:
player.move(-1, 0, grid)
elif event.key == pygame.K_RIGHT:
player.move(1, 0, grid)
elif event.key == pygame.K_UP:
player.move(0, -1, grid)
elif event.key == pygame.K_DOWN:
player.move(0, 1, grid)
elif event.key == pygame.K_SPACE:
player.attack(monsters)
# Time scale management
current_time = time.time()
if current_time - last_input_time > 0.5: # 0.5 seconds of inactivity
time_scale = 0.1 # Slow down 10x
else:
time_scale = 1.0 # Normal speed
# Update game objects
player.update()
for monster in monsters:
monster.update(player, grid, time_scale)
# Draw
screen.fill(WHITE)
draw_isometric_grid(screen)
player.draw(screen)
for monster in monsters:
monster.draw(screen)
# Update display
pygame.display.flip()
clock.tick(FPS)
pygame.quit()
if __name__ == "__main__":
main()
This prototype includes:
An isometric grid system where:
The grid is drawn using isometric projection
Grid coordinates are converted to screen coordinates using isometric transformation
Player mechanics:
Blue circle represents the player
Move using arrow keys
Attack using spacebar (destroys monsters in range 1)
Attack has a cooldown
Shows a white circle effect when attacking
Monster mechanics:
Red rectangles represent monsters
Basic AI that moves toward the player
Three monsters spawn at the start
Time manipulation:
Normal speed when player is giving input
Slows down 10x after 0.5 seconds of inactivity
Affects monster movement speed
Collision system:
Prevents movement outside grid boundaries
Basic grid-based collision system (though currently only used for boundary checking)
To run this game, you'll need to have Pygame installed (pip install pygame).
Features you might want to add to enhance this prototype:
Health system for player and monsters
More sophisticated monster AI
Obstacles/walls on the grid
Better graphics/animations
Sound effects
Different types of attacks
Status effects
Score system
Multiple levels
The current implementation is a basic framework that you can build upon based on your specific game design needs.