add remove button and circle to go with it
Signed-off-by: casualhonk <casualhonk@Tomoe.nya>
This commit is contained in:
parent
1fa8181713
commit
e2ffea00e0
1 changed files with 39 additions and 11 deletions
50
main.py
50
main.py
|
|
@ -105,18 +105,35 @@ while running:
|
||||||
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
|
if event.type == pygame.MOUSEBUTTONDOWN:
|
||||||
mx, my = pygame.mouse.get_pos()
|
mx, my = pygame.mouse.get_pos()
|
||||||
if event.button == 3: # right mouse
|
|
||||||
if placing_mode == "intersection":
|
if placing_mode == "remove" and event.button == 3:
|
||||||
#remove within 20px
|
|
||||||
intersections = [
|
DEL_RADIUS = 25
|
||||||
(x, y) for (x, y) in intersections if not (abs(mx - x) < 20 and abs(my - y) < 20)
|
|
||||||
]
|
intersections = [
|
||||||
if placing_mode == "light":
|
(x, y) for (x, y) in intersections
|
||||||
lights = [
|
if (mx - x) ** 2 + (my - y) ** 2 > DEL_RADIUS ** 2
|
||||||
light for light in lights if not (abs(mx - light.x) < 20 and abs(my - light.y) < 20)
|
]
|
||||||
]
|
|
||||||
|
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
|
#switch placing mode
|
||||||
|
|
@ -125,6 +142,11 @@ while running:
|
||||||
placing_mode = "intersection"
|
placing_mode = "intersection"
|
||||||
if event.key == pygame.K_2:
|
if event.key == pygame.K_2:
|
||||||
placing_mode = "light"
|
placing_mode = "light"
|
||||||
|
if event.key == pygame.K_3:
|
||||||
|
placing_mode = "remove"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#roads
|
#roads
|
||||||
|
|
@ -154,12 +176,18 @@ while running:
|
||||||
pygame.draw.rect(screen, UI_BG, (800, 0, 200, HEIGHT))
|
pygame.draw.rect(screen, UI_BG, (800, 0, 200, HEIGHT))
|
||||||
font = pygame.font.SysFont(None, 28)
|
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 = [
|
ui_text = [
|
||||||
"Placement Mode:",
|
"Placement Mode:",
|
||||||
f"{placing_mode.upper()}",
|
f"{placing_mode.upper()}",
|
||||||
"",
|
"",
|
||||||
"Press 1: Intersection",
|
"Press 1: Intersection",
|
||||||
"Press 2: Traffic Light",
|
"Press 2: Traffic Light",
|
||||||
|
"Press 3: Remove Tool",
|
||||||
"",
|
"",
|
||||||
f"Cars: {len(vehicles)}",
|
f"Cars: {len(vehicles)}",
|
||||||
f"Lights: {len(lights)}",
|
f"Lights: {len(lights)}",
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue