gpt-4o-mini-2024-07-18· OpenAI
WildChat-4.8M (AI2)
Fix errors and bugs in the given code, without changing its intended functionality. ONLY…
- User
Fix errors and bugs in the given code, without changing its intended functionality. ONLY return the fixed code and nothing else. Enclose the entire code in a single code block.
- Assistant
import pygame import math # Constants SCREEN_WIDTH, SCREEN_HEIGHT = 800, 600 NUM_RAYS = 120 FOV = math.pi / 3 RAY_LENGTH = 300 # Initialize pygame pygame.init() screen = pygame.display.set_mode((SCREEN_WIDTH, SCREEN_HEIGHT)) clock = pygame.time.Clock() def cast_ray(angle, pos): x, y = pos ray_x = x + RAY_LENGTH * math.cos(angle) ray_y = y + RAY_LENGTH * math.sin(angle) return (ray_x, ray_y) def main(): running = True position = (SCREEN_WIDTH // 2, SCREEN_HEIGHT // 2) while running: for event in pygame.event.get(): if event.type == pygame.QUIT: running = False screen.fill((0, 0, 0)) for i in range(NUM_RAYS): angle = FOV * (i / NUM_RAYS) - (FOV / 2) ray_end = cast_ray(angle, position) pygame.draw.line(screen, (255, 255, 255), position, ray_end) pygame.display.flip() clock.tick(60) pygame.quit() if __name__ == "__main__": main()