2026-08-26 16:35:06 +00:00
|
|
|
import pygame
|
|
|
|
|
|
2026-10-16 16:31:55 +00:00
|
|
|
from scripts.constants import *
|
|
|
|
|
from scripts.flashlight import Flashlight
|
|
|
|
|
from scripts.level import Level
|
|
|
|
|
from scripts.player import Player
|
2026-10-02 16:28:01 +00:00
|
|
|
from scripts.utils import load_image
|
2026-10-23 14:14:13 +00:00
|
|
|
from scripts.wall import Wall
|
2026-10-02 16:28:01 +00:00
|
|
|
|
2026-10-07 13:49:15 +00:00
|
|
|
|
2026-07-17 15:45:18 +00:00
|
|
|
class Game:
|
|
|
|
|
def __init__(self):
|
2026-10-02 15:22:08 +00:00
|
|
|
# Pygame setup
|
2026-07-17 15:45:18 +00:00
|
|
|
pygame.init()
|
|
|
|
|
pygame.display.set_caption("School Game")
|
|
|
|
|
self.clock = pygame.Clock()
|
2026-10-02 15:22:08 +00:00
|
|
|
# Surfaces
|
2026-10-07 13:49:15 +00:00
|
|
|
self.screen: pygame.Surface = pygame.display.set_mode(
|
|
|
|
|
(SCREEN_WIDTH, SCREEN_HEIGHT)
|
|
|
|
|
)
|
2026-10-02 15:22:08 +00:00
|
|
|
# Pygame-Variablen
|
2026-07-17 15:45:18 +00:00
|
|
|
self.running: bool = True
|
2026-07-24 15:50:34 +00:00
|
|
|
self.dt: int = 0
|
2026-10-02 15:22:08 +00:00
|
|
|
# Spieler
|
2026-10-07 13:49:15 +00:00
|
|
|
self.player_pos = pygame.Vector2(
|
|
|
|
|
self.screen.get_width() / 2, self.screen.get_height() / 2
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
2026-10-09 16:32:12 +00:00
|
|
|
# Assets
|
|
|
|
|
self.assets = {
|
|
|
|
|
"floor_01": load_image("level/ground/floor_1.png"),
|
2026-10-16 16:31:55 +00:00
|
|
|
"plant_01": load_image("items/furniture/plants/plant.png"),
|
|
|
|
|
"wall": load_image("level/walls/wall_0.png"),
|
2026-10-23 16:24:51 +00:00
|
|
|
|
|
|
|
|
"player": load_image("entity/player/player.png"),
|
2026-10-09 16:32:12 +00:00
|
|
|
}
|
2026-10-23 16:24:51 +00:00
|
|
|
self.player = Player(self.player_pos, width=PLAYER_SIZE, height=PLAYER_SIZE, image=self.assets["player"])
|
|
|
|
|
self.flashlight_player = Flashlight(self, self.player)
|
2026-10-09 16:32:12 +00:00
|
|
|
|
2026-10-16 16:31:55 +00:00
|
|
|
self.level = Level(
|
|
|
|
|
game=self,
|
|
|
|
|
items=[],
|
|
|
|
|
walls=[
|
2026-10-23 15:43:02 +00:00
|
|
|
Wall(self, 0, 0, SCREEN_WIDTH//TILE_SIZE, 1),
|
|
|
|
|
Wall(self, 0, TILE_SIZE, 1, SCREEN_HEIGHT//TILE_SIZE),
|
2026-10-23 14:14:13 +00:00
|
|
|
Wall(
|
2026-10-23 15:43:02 +00:00
|
|
|
self, TILE_SIZE, SCREEN_HEIGHT - TILE_SIZE, SCREEN_WIDTH//TILE_SIZE, 1
|
2026-10-16 16:31:55 +00:00
|
|
|
),
|
2026-10-23 15:58:20 +00:00
|
|
|
Wall(self, SCREEN_WIDTH - TILE_SIZE, 0, 1, SCREEN_HEIGHT//TILE_SIZE),
|
2026-10-23 15:43:02 +00:00
|
|
|
Wall(self, 500, 500, 2, 2)
|
2026-10-16 16:31:55 +00:00
|
|
|
],
|
|
|
|
|
)
|
2026-10-09 16:32:12 +00:00
|
|
|
|
2026-10-16 16:31:55 +00:00
|
|
|
self.level_zustand: int = 0
|
2026-10-02 15:22:08 +00:00
|
|
|
|
2026-10-16 16:31:55 +00:00
|
|
|
@property
|
|
|
|
|
def walls(self):
|
|
|
|
|
return self.level.walls
|
2026-10-09 16:32:12 +00:00
|
|
|
|
2026-10-16 16:31:55 +00:00
|
|
|
@property
|
|
|
|
|
def items(self):
|
|
|
|
|
return self.level.items
|
2026-08-28 16:46:44 +00:00
|
|
|
|
2026-09-18 15:29:30 +00:00
|
|
|
def update(self) -> None:
|
2026-10-02 15:22:08 +00:00
|
|
|
# Ereignisse
|
2026-09-18 15:29:30 +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
|
|
|
|
|
if event.key == pygame.K_LSHIFT:
|
|
|
|
|
self.player.speed = 300
|
2026-10-02 16:32:13 +00:00
|
|
|
if event.key == pygame.K_q:
|
2026-10-16 16:31:55 +00:00
|
|
|
self.flashlight_player.light_state = (
|
|
|
|
|
not self.flashlight_player.light_state
|
|
|
|
|
)
|
2026-10-02 16:32:13 +00:00
|
|
|
|
2026-10-02 15:22:08 +00:00
|
|
|
if event.type == pygame.KEYUP and event.key == pygame.K_LSHIFT:
|
|
|
|
|
self.player.speed = 150
|
2026-10-02 16:32:13 +00:00
|
|
|
|
2026-10-02 15:22:08 +00:00
|
|
|
# Spielzustände aktualisieren
|
2026-09-18 15:29:30 +00:00
|
|
|
self.player.update(walls=self.walls, dt=self.dt)
|
2026-10-09 15:25:19 +00:00
|
|
|
self.flashlight_player.update()
|
2026-10-09 16:32:12 +00:00
|
|
|
|
|
|
|
|
for item in self.items:
|
|
|
|
|
item.update()
|
2026-08-26 16:35:06 +00:00
|
|
|
|
2026-09-18 15:29:30 +00:00
|
|
|
def render(self) -> None:
|
2026-10-02 15:22:08 +00:00
|
|
|
# Hintergrund
|
|
|
|
|
self.screen.fill((0, 0, 0, 0))
|
|
|
|
|
|
2026-10-16 16:31:55 +00:00
|
|
|
self.level.render(self.screen)
|
2026-10-02 16:28:01 +00:00
|
|
|
|
|
|
|
|
# 1. Zeichne 1 Tile -> []
|
|
|
|
|
|
|
|
|
|
# 2. Zeichne eine Reihe von Tiles -> [][][][][][]
|
|
|
|
|
|
|
|
|
|
# 3. Zeichne mehrere Reihen von Tiles
|
|
|
|
|
# -> [][][][][][]
|
|
|
|
|
# -> [][][][][][]
|
|
|
|
|
# -> [][][][][][]
|
|
|
|
|
|
2026-10-02 15:22:08 +00:00
|
|
|
# Licht
|
2026-10-09 15:25:19 +00:00
|
|
|
self.flashlight_player.render(self.screen)
|
2026-10-09 16:32:12 +00:00
|
|
|
|
|
|
|
|
for item in self.items:
|
|
|
|
|
item.render(self.screen)
|
2026-10-02 15:22:08 +00:00
|
|
|
|
|
|
|
|
# Spieler
|
|
|
|
|
self.player.render(self.screen)
|
2026-09-25 16:22:33 +00:00
|
|
|
|
2026-10-02 15:22:08 +00:00
|
|
|
# Surfaces aktualisieren
|
|
|
|
|
pygame.display.update()
|
2026-09-25 16:22:33 +00:00
|
|
|
|
2026-10-02 15:22:08 +00:00
|
|
|
def run(self) -> None:
|
|
|
|
|
while self.running:
|
|
|
|
|
self.dt: float = self.clock.tick(60) / 1000.0
|
|
|
|
|
self.update()
|
|
|
|
|
self.render()
|
2026-09-08 13:27:52 +00:00
|
|
|
|
|
|
|
|
|
2026-07-17 15:45:18 +00:00
|
|
|
game = Game()
|
2026-07-24 15:50:34 +00:00
|
|
|
game.run()
|
2026-10-16 10:40:12 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
"""
|
2026-10-23 16:33:03 +00:00
|
|
|
Wie funktioniert Kollision mit Bildern?????????????????????????!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
|
|
|
|
(Günter hat ein Tutorial)
|
2026-10-16 16:31:55 +00:00
|
|
|
"""
|