2026-07-17 15:45:18 +00:00
|
|
|
import pygame
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
SCREEN_WIDTH = 640
|
|
|
|
|
SCREEN_HEIGHT = 480
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class Game:
|
|
|
|
|
def __init__(self):
|
|
|
|
|
pygame.init()
|
2026-07-24 16:33:42 +00:00
|
|
|
|
2026-07-17 15:45:18 +00:00
|
|
|
pygame.display.set_caption("School Game")
|
|
|
|
|
|
|
|
|
|
self.clock = pygame.Clock()
|
|
|
|
|
self.screen: pygame.Surface = pygame.display.set_mode(
|
|
|
|
|
(SCREEN_WIDTH, SCREEN_HEIGHT)
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
self.display: pygame.Surface = pygame.Surface(
|
|
|
|
|
(self.screen.get_width() // 2, self.screen.get_height() // 2)
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
self.movement: list[bool] = [False, False, False, False]
|
|
|
|
|
|
|
|
|
|
self.running: bool = True
|
|
|
|
|
|
2026-07-24 15:50:34 +00:00
|
|
|
self.dt: int = 0
|
2026-07-17 15:45:18 +00:00
|
|
|
|
2026-07-24 15:50:34 +00:00
|
|
|
self.player_pos = pygame.Vector2(self.display.get_width() / 2, self.display.get_height() / 2)
|
2026-07-17 15:45:18 +00:00
|
|
|
|
2026-07-24 16:33:42 +00:00
|
|
|
self.item_rect = pygame.Rect(60, 40, 10, 10)
|
|
|
|
|
|
|
|
|
|
self.flashlight = 0
|
|
|
|
|
|
|
|
|
|
self.color_item = (0, 0, 0)
|
|
|
|
|
|
|
|
|
|
#self.circle = pygame.geometry.Circle(self.player_pos[0], self.player_pos[1], 30)
|
|
|
|
|
|
2026-07-17 15:45:18 +00:00
|
|
|
def run(self) -> None:
|
|
|
|
|
while self.running:
|
2026-07-24 15:50:34 +00:00
|
|
|
# Background
|
2026-07-17 15:45:18 +00:00
|
|
|
self.display.fill((0, 0, 0, 0))
|
|
|
|
|
|
2026-07-24 16:33:42 +00:00
|
|
|
self.player_rect = pygame.Rect(self.player_pos[0]-10, self.player_pos[1]-10, 20, 20)
|
|
|
|
|
|
|
|
|
|
|
2026-07-24 15:59:36 +00:00
|
|
|
# Event-Keys
|
2026-07-17 15:45:18 +00:00
|
|
|
for event in pygame.event.get():
|
|
|
|
|
if event.type == pygame.QUIT:
|
|
|
|
|
self.running = False
|
|
|
|
|
|
|
|
|
|
if event.type == pygame.KEYDOWN:
|
|
|
|
|
if event.key == pygame.K_ESCAPE:
|
|
|
|
|
self.running = False
|
|
|
|
|
|
2026-07-24 15:59:36 +00:00
|
|
|
# Player-Draw
|
2026-07-24 16:33:42 +00:00
|
|
|
self.flashlight = pygame.draw.circle(self.display, (255, 255, 255, 0), self.player_pos, 30)
|
2026-07-17 15:45:18 +00:00
|
|
|
|
2026-07-24 16:33:42 +00:00
|
|
|
pygame.draw.rect(self.display, self.color_item, self.item_rect)
|
|
|
|
|
|
|
|
|
|
pygame.draw.rect(self.display, (255, 0, 0), self.player_rect)
|
2026-07-24 15:59:36 +00:00
|
|
|
|
|
|
|
|
# Smooth Movement
|
2026-07-24 15:50:34 +00:00
|
|
|
keys = pygame.key.get_pressed()
|
|
|
|
|
if keys[pygame.K_w]:
|
|
|
|
|
self.player_pos.y -= 300 * self.dt
|
|
|
|
|
if keys[pygame.K_s]:
|
|
|
|
|
self.player_pos.y += 300 * self.dt
|
|
|
|
|
if keys[pygame.K_a]:
|
|
|
|
|
self.player_pos.x -= 300 * self.dt
|
|
|
|
|
if keys[pygame.K_d]:
|
|
|
|
|
self.player_pos.x += 300 * self.dt
|
2026-07-17 15:45:18 +00:00
|
|
|
|
2026-07-24 16:33:42 +00:00
|
|
|
if not self.flashlight.colliderect(self.item_rect):
|
|
|
|
|
self.color_item = (0,0,0)
|
|
|
|
|
else:
|
|
|
|
|
self.color_item = (0, 0, 255)
|
|
|
|
|
|
2026-07-17 15:45:18 +00:00
|
|
|
self.screen.blit(
|
|
|
|
|
pygame.transform.scale(self.display, self.screen.get_size())
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
pygame.display.update()
|
2026-07-24 15:50:34 +00:00
|
|
|
self.dt = self.clock.tick(60) / 3000
|
2026-07-17 15:45:18 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
game = Game()
|
2026-07-24 15:50:34 +00:00
|
|
|
game.run()
|