diff --git a/main.py b/main.py index 1b07617..2952cd9 100644 --- a/main.py +++ b/main.py @@ -105,18 +105,35 @@ while running: elif placing_mode == "light": lights.append(TrafficLight(mx, my)) - if event.type == pygame.MOUSEBUTTONDOWN: #delete things + if event.type == pygame.MOUSEBUTTONDOWN: mx, my = pygame.mouse.get_pos() - if event.button == 3: # right mouse - if placing_mode == "intersection": - #remove within 20px - intersections = [ - (x, y) for (x, y) in intersections if not (abs(mx - x) < 20 and abs(my - y) < 20) - ] - if placing_mode == "light": - lights = [ - light for light in lights if not (abs(mx - light.x) < 20 and abs(my - light.y) < 20) - ] + + if placing_mode == "remove" and event.button == 3: + + DEL_RADIUS = 25 + + intersections = [ + (x, y) for (x, y) in intersections + if (mx - x) ** 2 + (my - y) ** 2 > DEL_RADIUS ** 2 + ] + + lights = [ + light for light in lights + if (mx - light.x) ** 2 + (my - light.y) ** 2 > DEL_RADIUS ** 2 + ] + + # if event.type == pygame.MOUSEBUTTONDOWN: #delete things + # mx, my = pygame.mouse.get_pos() + # if event.button == 3: # right mouse + # if placing_mode == "intersection": + # #remove within 20px + # intersections = [ + # (x, y) for (x, y) in intersections if not (abs(mx - x) < 20 and abs(my - y) < 20) + # ] + # if placing_mode == "light": + # lights = [ + # light for light in lights if not (abs(mx - light.x) < 20 and abs(my - light.y) < 20) + # ] #switch placing mode @@ -125,6 +142,11 @@ while running: placing_mode = "intersection" if event.key == pygame.K_2: placing_mode = "light" + if event.key == pygame.K_3: + placing_mode = "remove" + + + #roads @@ -154,12 +176,18 @@ while running: pygame.draw.rect(screen, UI_BG, (800, 0, 200, HEIGHT)) font = pygame.font.SysFont(None, 28) + # circle wowwwwww so prettyyy + if placing_mode == "remove": + mx, my = pygame.mouse.get_pos() + pygame.draw.circle(screen, RED, (mx, my), 25, 2, ) + ui_text = [ "Placement Mode:", f"{placing_mode.upper()}", "", "Press 1: Intersection", "Press 2: Traffic Light", + "Press 3: Remove Tool", "", f"Cars: {len(vehicles)}", f"Lights: {len(lights)}",