add right click to delete function wowwwwwwwwwwwwww

This commit is contained in:
casualhonk 2026-02-20 21:36:32 +11:00
parent 160ba18e83
commit 1fa8181713

21
main.py
View file

@ -96,14 +96,29 @@ while running:
if event.type == pygame.MOUSEBUTTONDOWN: if event.type == pygame.MOUSEBUTTONDOWN:
mx, my = pygame.mouse.get_pos() 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)) intersections.append((mx, my))
elif placing_mode == "light": elif placing_mode == "light":
lights.append(TrafficLight(mx, my)) 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 #switch placing mode
if event.type == pygame.KEYDOWN: if event.type == pygame.KEYDOWN:
if event.key == pygame.K_1: if event.key == pygame.K_1: