import pygame import sys import random pygame.init() # Game window WIDTH, HEIGHT = 1000, 700 screen = pygame.display.set_mode((WIDTH, HEIGHT)) pygame.display.set_caption("Dandy's World - Play as Dandy!") # Colors (faithful to Dandy) WHITE = (255, 255, 255) OFF_WHITE = (248, 248, 248) MINT_GREEN = (144, 238, 144) PETAL_COLORS = [ (255, 0, 0), # Red (255, 165, 0), # Orange (255, 255, 0), # Yellow (0, 255, 0), # Green (0, 191, 255), # Deep Sky Blue (148, 0, 211) # Dark Violet ] BLACK = (20, 20, 20) BLUSH = (0, 190, 120) class Dandy: def __init__(self): self.reset_position() self.speed = 7 self.size = 48 self.angle = 0 self.score = 0 self.facing_right = True def reset_position(self): self.x = WIDTH // 2 self.y = HEIGHT // 2 def handle_input(self, keys): if keys[pygame.K_LEFT] or keys[pygame.K_a]: self.x -= self.speed self.facing_right = False if keys[pygame.K_RIGHT] or keys[pygame.K_d]: self.x += self.speed self.facing_right = True if keys[pygame.K_UP] or keys[pygame.K_w]: self.y -= self.speed if keys[pygame.K_DOWN] or keys[pygame.K_s]: self.y += self.speed # Screen bounds self.x = max(self.size, min(WIDTH - self.size, self.x)) self.y = max(self.size, min(HEIGHT - 100, self.y)) def update(self): self.angle += 4 # Petal sway + bob def draw(self, surface): cx, cy = int(self.x), int(self.y) # Rainbow petals for i in range(6): rot = self.angle + i * 60 rad = rot * 3.14159 / 180 offset_x = 38 * pygame.math.Vector2(1, 0).rotate(rot).x offset_y = 38 * pygame.math.Vector2(1, 0).rotate(rot).y - 8 px = cx + offset_x py = cy + offset_y pygame.draw.ellipse(surface, PETAL_COLORS[i], (px-19, py-14, 38, 27), border_radius=10) # Head (off-white) pygame.draw.circle(surface, OFF_WHITE, (cx, cy), self.size) # Eyes eye_x_offset = 13 pygame.draw.circle(surface, BLACK, (cx - eye_x_offset, cy - 10), 8) pygame.draw.circle(surface, BLACK, (cx + eye_x_offset, cy - 10), 8) # Highlights pygame.draw.circle(surface, WHITE, (cx - eye_x_offset - 3, cy - 13), 3) pygame.draw.circle(surface, WHITE, (cx + eye_x_offset - 3, cy - 13), 3) # Signature wide grin pygame.draw.arc(surface, BLACK, (cx-19, cy+4, 38, 20), 0.4, 2.7, 4) # Blush stickers pygame.draw.ellipse(surface, BLUSH, (cx-26, cy+6, 13, 9)) pygame.draw.ellipse(surface, BLUSH, (cx+13, cy+6, 13, 9)) # Stem + limbs stem_y = cy + self.size - 4 pygame.draw.line(surface, MINT_GREEN, (cx, stem_y), (cx, stem_y + 38), 16) # Arms with swing swing = 8 * (self.angle % 30 - 15) / 15 arm_dir = 1 if self.facing_right else -1 pygame.draw.line(surface, MINT_GREEN, (cx - 22, cy + 12), (cx - 48 * arm_dir + swing, cy + 28), 10) pygame.draw.line(surface, MINT_GREEN, (cx + 22, cy +