Код: Выделить всё
import pygame
import sys
import random
import time
import math
pygame.init()
screen_width, screen_height = 1200, 800
screen = pygame.display.set_mode((screen_width, screen_height))
pygame.display.set_caption("Traffic Intersection Simulation")
white, black, red, asphalt_grey, green, yellow = (255, 255, 255), (0, 0, 0), (255, 0, 0), (99, 102, 102), (1, 50, 32), (255, 255, 0)
class LeftTurn:
def __init__(self):
self.radius_lt = 15.5
self.speed = 5
def left_turn_i(self, point_x, point_y, angle, dot_x, dot_y):
if dot_x < point_x and dot_y > point_y:
dot_x += self.speed
pygame.draw.circle(screen, red, (int(dot_x), int(dot_y)), 4)
elif dot_x >= point_x and dot_y > point_y and angle >= 0:
dot_y = point_y + math.cos(angle) * self.radius_lt
dot_x = point_x - math.sin(angle) * self.radius_lt
angle -= 0.05 # Adjust the angle for a left turn
pygame.draw.circle(screen, red, (int(dot_x), int(dot_y)), 4)
else:
dot_y -= self.speed
pygame.draw.circle(screen, red, (int(dot_x), int(dot_y)), 4)
return angle, dot_x, dot_y
def left_turn_j(self, point_x, point_y, angle, dot_x, dot_y):
if dot_y < point_y and dot_x < point_x:
dot_y += self.speed
pygame.draw.circle(screen, red, (int(dot_x), int(dot_y)), 4)
elif dot_y >= point_y and dot_x < point_x:
dot_y = point_y + math.cos(angle) * self.radius_lt
dot_x = point_x - math.sin(angle) * self.radius_lt
angle -= 0.1
pygame.draw.circle(screen, red, (int(dot_x), int(dot_y)), 4)
elif dot_y > point_y and dot_x >= point_x:
dot_x += self.speed
pygame.draw.circle(screen, red, (int(dot_x), int(dot_y)), 4)
return angle, dot_x, dot_y
def left_turn_k(self, point_x, angle, point_y, dot_x, dot_y):
if dot_x > point_x and dot_y < point_y:
dot_x -= self.speed
pygame.draw.circle(screen, red, (int(dot_x), int(dot_y)), 4)
elif dot_x = point_y:
dot_y += self.speed
pygame.draw.circle(screen, red, (int(dot_x), int(dot_y)), 4)
return angle, dot_x, dot_y
def left_turn_l(self, point_x, point_y, angle, dot_x, dot_y):
if dot_y > point_y and dot_x > point_x:
dot_y -= self.speed
pygame.draw.circle(screen, red, (int(dot_x), int(dot_y)), 4)
elif dot_y point_x:
dot_y = point_y - math.cos(angle) * self.radius_lt
dot_x = point_x + math.sin(angle) * self.radius_lt
angle -= 0.1
pygame.draw.circle(screen, red, (int(dot_x), int(dot_y)), 4)
elif dot_y < point_y and dot_x
Подробнее здесь: [url]https://stackoverflow.com/questions/78297268/dots-are-moving-undesirably-in-oscillation-in-py-game[/url]