2026-07-17 15:45:18 +00:00
|
|
|
import pygame
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
SCREEN_WIDTH = 640
|
|
|
|
|
SCREEN_HEIGHT = 480
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class Game:
|
|
|
|
|
def __init__(self):
|
|
|
|
|
pygame.init()
|
|
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
|
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))
|
|
|
|
|
|
|
|
|
|
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:50:34 +00:00
|
|
|
pygame.draw.rect(self.display, (255, 0, 0), pygame.Rect(self.player_pos[0], self.player_pos[1], 20, 20))
|
2026-07-17 15:45:18 +00:00
|
|
|
|
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
|
|
|
|
|
|
|
|
|
|
|
|
|
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()
|