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: