import pygame # pygame setup pygame.init() screen = pygame.display.set_mode((1280, 720)) clock = pygame.time.Clock() running = True dt = 0 force_coef = 10 player_applied_force = pygame.Vector2(0, 0) player_mass = 1 player_pos = pygame.Vector2(screen.get_width() / 2, screen.get_height() / 2) player_speed = pygame.Vector2(0, 0) def draw_arrow(surface, color, start, end, width=3): pygame.draw.line(surface, color, start, end, width) direction = (end - start).normalize() arrow_size = 10 perpendicular = pygame.Vector2(-direction.y, direction.x) point1 = end - direction * arrow_size + perpendicular * arrow_size / 2 point2 = end - direction * arrow_size - perpendicular * arrow_size / 2 pygame.draw.polygon(surface, color, [end, point1, point2]) while running: for event in pygame.event.get(): if event.type == pygame.QUIT: running = False screen.fill("purple") pygame.draw.circle(screen, "red", player_pos, 40) player_applied_force = pygame.Vector2(0, 0) keys = pygame.key.get_pressed() if keys[pygame.K_w]: player_applied_force.y -= force_coef if keys[pygame.K_s]: player_applied_force.y += force_coef if keys[pygame.K_a]: player_applied_force.x -= force_coef if keys[pygame.K_d]: player_applied_force.x += force_coef acceleration = player_applied_force / player_mass player_speed += acceleration * dt player_pos += player_speed * dt # Draw force arrow if player_applied_force.length() > 0: arrow_end = player_pos + player_applied_force * 2 draw_arrow(screen, "yellow", player_pos, arrow_end) # Draw speed arrow if player_speed.length() > 0: arrow_end = player_pos + player_speed * 2 draw_arrow(screen, "cyan", player_pos, arrow_end) pygame.display.flip() dt = clock.tick(60) / 1000 pygame.quit()