add remove button and circle to go with it

Signed-off-by: casualhonk <casualhonk@Tomoe.nya>
This commit is contained in:
casualhonk 2026-02-20 21:55:11 +11:00 committed by casualhonk
parent 1fa8181713
commit e2ffea00e0

42
main.py
View file

@ -105,19 +105,36 @@ while running:
elif placing_mode == "light":
lights.append(TrafficLight(mx, my))
if event.type == pygame.MOUSEBUTTONDOWN: #delete things
if event.type == pygame.MOUSEBUTTONDOWN:
mx, my = pygame.mouse.get_pos()
if event.button == 3: # right mouse
if placing_mode == "intersection":
#remove within 20px
if placing_mode == "remove" and event.button == 3:
DEL_RADIUS = 25
intersections = [
(x, y) for (x, y) in intersections if not (abs(mx - x) < 20 and abs(my - y) < 20)
(x, y) for (x, y) in intersections
if (mx - x) ** 2 + (my - y) ** 2 > DEL_RADIUS ** 2
]
if placing_mode == "light":
lights = [
light for light in lights if not (abs(mx - light.x) < 20 and abs(my - light.y) < 20)
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
if event.type == pygame.KEYDOWN:
@ -125,6 +142,11 @@ while running:
placing_mode = "intersection"
if event.key == pygame.K_2:
placing_mode = "light"
if event.key == pygame.K_3:
placing_mode = "remove"
#roads
@ -154,12 +176,18 @@ while running:
pygame.draw.rect(screen, UI_BG, (800, 0, 200, HEIGHT))
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 = [
"Placement Mode:",
f"{placing_mode.upper()}",
"",
"Press 1: Intersection",
"Press 2: Traffic Light",
"Press 3: Remove Tool",
"",
f"Cars: {len(vehicles)}",
f"Lights: {len(lights)}",