add right click to delete function wowwwwwwwwwwwwww
This commit is contained in:
parent
160ba18e83
commit
1fa8181713
1 changed files with 18 additions and 3 deletions
21
main.py
21
main.py
|
|
@ -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:
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue