school-horror-game/polygon.py

52 lines
1.4 KiB
Python
Raw Normal View History

2026-08-26 16:35:06 +00:00
# Example file showing a basic pygame "game loop"
import pygame
import math
# pygame setup
pygame.init()
screen = pygame.display.set_mode((1280, 720))
clock = pygame.time.Clock()
running = True
def calculate_flashlight_radiate(degrees: int, start_pos: tuple[int, int] | list[int, int] | pygame.Vector2, length: int) -> tuple[int, int]:
angle_deg = degrees # Angle in degrees
# Convert degrees to radians for math functions
angle_rad = math.radians(angle_deg)
end_x = start_pos[0] + length * math.cos(angle_rad)
end_y = start_pos[1] - length * math.sin(angle_rad) # Minus because y increases downward in Pygame
end_pos = (int(end_x), int(end_y))
return end_pos
points = []
while running:
# poll for events
# pygame.QUIT event means the user clicked X to close your window
for event in pygame.event.get():
if event.type == pygame.QUIT:
running = False
# fill the screen with a color to wipe away anything from last frame
screen.fill("purple")
# RENDER YOUR GAME HERE
for i in range(360):
point = calculate_flashlight_radiate(i, (640, 360), 50)
points.append(point)
pygame.draw.polygon(screen, (27, 134, 3), points)
points = []
# flip() the display to put your work on screen
pygame.display.flip()
clock.tick(60) # limits FPS to 60
pygame.quit()