import pygame, sys, pymunk def create_block(space, pos): body = pymunk.Body(1, 100, body_type = pymunk.Body.DYNAMIC) body.position = pos shape = pymunk.Circle(body, 45) space.add(body, shape) return shape def draw_blocks(blocks): for block in blocks: pos_x = int(block.body.position.x) pos_y = int(block.body.position.y) block_rect = block_surface.get_rect(center = (pos_x, pos_y)) screen.blit(block_surface, block_rect) def static_ball(space, pos): body = pymunk.Body(body_type = pymunk.Body.STATIC) body.position = pos shape = pymunk.Circle(body, 50) 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, Black, (pos_x, pos_y), 50) # Basic Setup pygame.init() clock = pygame.time.Clock() # Variables screen_width = 800 screen_height = 800 White = (217, 217, 217) Black = (0, 0, 0) # Display screen = pygame.display.set_mode((screen_width, screen_height)) block_surface = pygame.image.load("image.png") # Space space = pymunk.Space() space.gravity = (0, 100) blocks = [] balls = [] balls.append(static_ball(space, (500, 500))) balls.append(static_ball(space, (200, 400))) while True: for event in pygame.event.get(): if event.type == pygame.QUIT: pygame.quit() sys.exit() if event.type == pygame.MOUSEBUTTONDOWN: blocks.append(create_block(space, event.pos)) screen.fill(White) draw_blocks(blocks) draw_static_ball(balls) space.step(1/50) pygame.display.update() clock.tick(120)