import pygame, sys, pymunk def create_apple(space, pos): body = pymunk.Body(1, 100, body_type = pymunk.Body.DYNAMIC) body.position = pos shape = pymunk.Circle(body, 50) space.add(body, shape) return shape def draw_apples(apples): for apple in apples: pos_x = int(apple.body.position.x) pos_y = int(apple.body.position.y) pygame.draw.circle(screen, (250,250,250), (pos_x, pos_y), 50) def static_ball(space, pos): body = pymunk.Body(body_type = pymunk.Body.STATIC) body.position = pos shape = pymunk.Circle(body, 30) space.add(body, shape) return shape def draw_static_ball(balls): for ball in balls: pos_x = int(ball.body.position.x) pos_y = int(ball.body.position.y) pygame.draw.circle(screen, (0,0,0), (pos_x, pos_y), 30) def ghost(pos, surface): temp_surface = pygame.Surface((100, 100), pygame.SRCALPHA) pygame.draw.circle(temp_surface, (0, 0, 0, 128), (50, 50), 50) pygame.draw.circle(temp_surface, (0, 0, 0, 179), (50, 50), 30) screen.blit(temp_surface, (pos[0] - 50, pos[1] - 50)) pygame.init() screen = pygame.display.set_mode((800, 800)) surface = pygame.Surface((800, 800), pygame.SRCALPHA) clock = pygame.time.Clock() space = pymunk.Space() space.gravity = (0, 200) apples = [] balls = [] while True: for event in pygame.event.get(): if event.type == pygame.QUIT: pygame.quit() sys.exit() if event.type == pygame.MOUSEBUTTONDOWN and event.button == 1: apples.append(create_apple(space, event.pos)) if event.type == pygame.MOUSEBUTTONDOWN and event.button == 3: balls.append(static_ball(space, event.pos)) if event.type == pygame.MOUSEBUTTONDOWN and event.button == 2: # Remove apple objects from the space before clearing the list for apple in apples: space.remove(apple, apple.body) apples.clear() # Remove static ball objects from the space before clearing the list for ball in balls: space.remove(ball, ball.body) balls.clear() screen.fill((217, 217, 217)) draw_static_ball(balls) draw_apples(apples) ghost(pygame.mouse.get_pos(), surface) space.step(1/50) pygame.display.update() clock.tick(120)