From 1fa818171356945728837bd29f0a158449b747d0 Mon Sep 17 00:00:00 2001 From: casualhonk Date: Fri, 20 Feb 2026 21:36:32 +1100 Subject: [PATCH] add right click to delete function wowwwwwwwwwwwwww --- main.py | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/main.py b/main.py index dc354ba..1b07617 100644 --- a/main.py +++ b/main.py @@ -96,14 +96,29 @@ while running: if event.type == pygame.MOUSEBUTTONDOWN: mx, my = pygame.mouse.get_pos() + if event.button == 1: - if mx < 800: #sim area + if mx < 800: #sim area - if placing_mode == "intersection": + if placing_mode == "intersection": intersections.append((mx, my)) - elif placing_mode == "light": + elif placing_mode == "light": lights.append(TrafficLight(mx, my)) + 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 if event.type == pygame.KEYDOWN: if event.key == pygame.K_1: