Hi, I'm trying to implement a polygonal boundary to stop the player from leaving the polygon. The player uses a circular collider. I've looked around online and haven't found anything that really helps. Below is a simple example of what I've got so far. If anyone can help explain an algorithm or at least provide a link to something that might help I would greatly appreciate it.
"""Circle with a polygonal boundary""" import pygame as pg pg.init() display = pg.display.set_mode((1024, 768)) edge_poly = [(10, 10), (400, 10), (350, 300), (150, 400)] player_pos = pg.Vector2(100, 50) player_radius = 15 player_speed = .2 running = True while running: # events for event in pg.event.get (): if event.type == pg.QUIT: running = False keys_down = pg.key.get_pressed() if keys_down[pg.K_w]: player_pos.y -= player_speed if keys_down[pg.K_s]: player_pos.y += player_speed if keys_down[pg.K_a]: player_pos.x -= player_speed if keys_down[pg.K_d]: player_pos.x += player_speed # updates # drawing display.fill((255, 255, 255)) pg.draw.polygon(display, (0, 0, 0), edge_poly, 1) pg.draw.circle(display, (0, 0, 0), player_pos, player_radius) pg.display.update() pg.quit() quit()Again thanks for taking the time to read, I appreciate any help you guys can offer.