import pygame import pymunk import sys import random # ----------------- CONFIG ----------------- SCREEN_WIDTH = 1800 SCREEN_HEIGHT = 1000 APPLE_RADIUS = 30 APPLE_COUNT_PER_CLICK = 100 FLASH_TRIGGER_COUNT = 3000 # Change to 3000 apples # ------------------------------------------ def create_apple(space, pos): offset_x = random.randint(-20, 20) offset_y = random.randint(-20, 20) new_pos = (pos[0] + offset_x, pos[1] + offset_y) body = pymunk.Body(1, 100, body_type=pymunk.Body.DYNAMIC) body.position = new_pos shape = pymunk.Circle(body, APPLE_RADIUS) shape.elasticity = 0.6 shape.friction = 0.5 space.add(body, shape) return shape def draw_apples(apples): for apple in apples: pos_x, pos_y = apple.body.position apple_rect = apple_surface.get_rect(center=(int(pos_x), int(pos_y))) screen.blit(apple_surface, apple_rect) def static_ball(space): body = pymunk.Body(body_type=pymunk.Body.STATIC) body.position = (SCREEN_WIDTH // 2, SCREEN_HEIGHT // 2) shape = pymunk.Circle(body, 50) space.add(body, shape) return shape def draw_static_ball(balls): for ball in balls: pygame.draw.circle(screen, (0, 0, 0), (int(ball.body.position.x), int(ball.body.position.y)), 50) def add_walls(space, width, height, thickness=10): static_lines = [ pymunk.Segment(space.static_body, (0, height), (width, height), thickness), # Bottom pymunk.Segment(space.static_body, (0, 0), (width, 0), thickness), # Top pymunk.Segment(space.static_body, (0, 0), (0, height), thickness), # Left pymunk.Segment(space.static_body, (width, 0), (width, height), thickness) # Right ] for line in static_lines: line.elasticity = 0.8 line.friction = 1.0 space.add(*static_lines) # ----------- INITIAL SETUP ----------- pygame.init() screen = pygame.display.set_mode((SCREEN_WIDTH, SCREEN_HEIGHT)) clock = pygame.time.Clock() font = pygame.font.SysFont(None, 36) space = pymunk.Space() space.gravity = (0, 500) # Load apple image or fallback try: original_image = pygame.image.load("img/creedon.png").convert_alpha() apple_surface = pygame.transform.smoothscale(original_image, (APPLE_RADIUS * 2, APPLE_RADIUS * 2)) except: apple_surface = pygame.Surface((APPLE_RADIUS * 2, APPLE_RADIUS * 2), pygame.SRCALPHA) pygame.draw.circle(apple_surface, (255, 0, 0), (APPLE_RADIUS, APPLE_RADIUS), APPLE_RADIUS) # Create game objects apples = [] balls = [static_ball(space)] add_walls(space, SCREEN_WIDTH, SCREEN_HEIGHT) # Flash effect setup flash_mode = False frame_count = 0 # ----------- MAIN GAME LOOP ----------- while True: frame_count += 1 for event in pygame.event.get(): if event.type == pygame.QUIT: pygame.quit() sys.exit() if event.type == pygame.MOUSEBUTTONDOWN: for _ in range(APPLE_COUNT_PER_CLICK): apples.append(create_apple(space, event.pos)) # Check if flash mode should activate if len(apples) >= FLASH_TRIGGER_COUNT: flash_mode = True # Flash background if in flash mode if flash_mode: if frame_count % 2 == 0: screen.fill((0, 0, 0)) # Black else: screen.fill((255, 255, 255)) # White else: screen.fill((217, 217, 217)) # Normal background draw_apples(apples) draw_static_ball(balls) # Draw apple count color = (255, 0, 0) if flash_mode else (0, 0, 0) count_text = font.render(f"Apples: {len(apples)}", True, color) screen.blit(count_text, (10, 10)) space.step(1 / 50) pygame.display.update() clock.tick(120)