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 minimal prototype in Pygame that demonstrates:
An isometric diamond‐tile map
A player (blue circle) and a couple of monsters (red circles)
Arrow‐key movement, spacebar “attack”
Normal time when you move or attack, 10× slower when idle
python
import pygame, sys, math, random
# --- CONFIG ---
SCREEN_W, SCREEN_H = 800, 600
TILE_W, TILE_H = 64, 32
MAP_W, MAP_H = 10, 10
PLAYER_SPEED = 4.0 # tiles per second
MONSTER_SPEED = 2.0 # tiles per second
ATTACK_RANGE = 1.2 # tiles
# --- HELPERS ---
def world_to_iso(x, y):
"""Convert map coords->screen iso coords."""
iso_x = (x - y) * TILE_W/2 + SCREEN_W//2
iso_y = (x + y) * TILE_H/2 + SCREEN_H//4
return iso_x, iso_y
def draw_tile(surf, gx, gy):
"""Draw a single diamond tile at grid pos (gx,gy)."""
cx, cy = world_to_iso(gx, gy)
# diamond corners
pts = [
(cx, cy + TILE_H/2),
(cx + TILE_W/2, cy),
(cx + TILE_W, cy + TILE_H/2),
(cx + TILE_W/2, cy + TILE_H)
]
pygame.draw.polygon(surf, (50,50,50), pts, 1)
# --- ENTITIES ---
class Entity:
def __init__(self, x, y, speed, color):
self.x = x; self.y = y
self.speed = speed
self.color = color
def iso_pos(self):
return world_to_iso(self.x, self.y)
def draw(self, surf):
cx, cy = self.iso_pos()
pygame.draw.circle(surf, self.color, (int(cx+TILE_W/2), int(cy+TILE_H/2)), 10)
# --- INIT ---
pygame.init()
screen = pygame.display.set_mode((SCREEN_W, SCREEN_H))
clock = pygame.time.Clock()
player = Entity(5.0, 5.0, PLAYER_SPEED, (50,150,255))
# spawn some monsters
monsters = [Entity(random.randint(0,MAP_W-1), random.randint(0,MAP_H-1),
MONSTER_SPEED, (200,50,50))
for _ in range(4)]
running = True
while running:
# 1) INPUT
keys = pygame.key.get_pressed()
moving = False
dx = dy = 0
if keys[pygame.K_LEFT]:
dx = -1; moving = True
if keys[pygame.K_RIGHT]:
dx = +1; moving = True
if keys[pygame.K_UP]:
dy = -1; moving = True
if keys[pygame.K_DOWN]:
dy = +1; moving = True
attacking = keys[pygame.K_SPACE]
if attacking:
moving = True
# 2) TIME SCALE
timescale = 1.0 if moving else 0.1
dt = clock.tick(60) / 1000.0 * timescale
# 3) UPDATE PLAYER
if dx or dy:
# normalize diagonals so speed is consistent
mag = math.hypot(dx, dy)
player.x += (dx/mag) * player.speed * dt
player.y += (dy/mag) * player.speed * dt
# clamp to map
player.x = max(0, min(MAP_W-1, player.x))
player.y = max(0, min(MAP_H-1, player.y))
# attack: remove any monster in range
if attacking:
hit_list = []
for m in monsters:
dist = abs(player.x - m.x) + abs(player.y - m.y)
if dist < ATTACK_RANGE:
hit_list.append(m)
for m in hit_list:
monsters.remove(m)
# 4) UPDATE MONSTERS (basic chase AI)
for m in monsters:
# vector towards player
vx = player.x - m.x
vy = player.y - m.y
if (vx,vy) != (0,0):
mag = math.hypot(vx, vy)
m.x += (vx/mag) * m.speed * dt
m.y += (vy/mag) * m.speed * dt
# 5) DRAW
screen.fill((30,30,30))
# draw tile map
for gx in range(MAP_W):
for gy in range(MAP_H):
draw_tile(screen, gx, gy)
# draw entities sorted by y for proper overlap
all_sprites = monsters + [player]
for ent in sorted(all_sprites, key=lambda e: e.x+e.y):
ent.draw(screen)
# optional: draw status
fps = clock.get_fps()
pygame.display.set_caption(f"Iso‐Demo FPS: {fps:.1f} TimeScale: {timescale}")
pygame.display.flip()
# EXIT
for ev in pygame.event.get():
if ev.type == pygame.QUIT:
running = False
pygame.quit()
sys.exit()
Explanation of key bits:
Isometric grid
We draw each tile as a “diamond” with draw_tile(), converting grid coords (gx,gy) to screen via iso_x = (gx - gy)*TILE_W/2 iso_y = (gx + gy)*TILE_H/2.
Entities
Both player and monsters store floating x,y in tile‐space. We move them by speed * dt.
Time scaling
We check if the player is pressing any arrow key or spacebar. If yes, timescale=1; otherwise 0.1.
Then dt = clock.tick(60)/1000 * timescale.
All movement/AI is frame‐timescale‐aware, so everything slows when idle.
Attack
On K_SPACE, we iterate monsters and remove any whose Manhattan‐distance to player is < ATTACK_RANGE.
You can expand this into full animations, real sprites, more advanced AI or combat, but this should give you a solid starting prototype. Enjoy! 😊