Compare commits

..

19 commits

Author SHA1 Message Date
binaerverkehr
dbe1ca4a2d Clean up 2026-09-26 15:00:21 +02:00
binaerverkehr
926092fe11 Kollisionslogik angepasst:
- Für Item und Lichtkegel wird jeweils eine Maske erstellt.
- Bei Überschneidung der Masken findet die Kollision statt.
- Ursprüngliche Kollisionsmethode entfernt
2026-09-26 14:54:41 +02:00
binaerverkehr
bb1a796c1c item rect durch Objekt ersetzt 2026-09-26 14:12:25 +02:00
binaerverkehr
bfe8427392 self.display entfernt 2026-09-26 14:10:49 +02:00
binaerverkehr
2be51cb32e Item Klasse erstellt und getestet 2026-09-26 14:02:33 +02:00
binaerverkehr
6e8a94f37f Reihenfolge der Game Methoden geändert.
Erst die eigenen Methoden, danach:
- update
- render
- run
2026-09-26 13:48:52 +02:00
binaerverkehr
1c457f6c9d Player.update: Kommentar entfernt 2026-09-26 13:47:34 +02:00
binaerverkehr
820ba42213 Methode calculate_collisions geleert + Lichtpunkte-Erstellung etwas umstrukturiert.
Tipp für die Zukunft:
Bevor du eine Instanzvariable (wie z. B. self.light_points" erstellst, überlege dir zuerst, ob es sich um Daten handelt, die du an verschiedenen Stellen erreichen musst. Denn nur dafür sollten Instanzvariablen angelegt werden.
2026-09-26 13:46:45 +02:00
binaerverkehr
2b31c1de54 Logik für Erstellung der Lichtpunkte (Raycasting) aus Game.render in eigene Methode "Game.create_light_points()" ausgelagert, da Game.render sich nur ums Zeichnen kümmern sollte, nicht um etwas zu erstellen oder berechnen. 2026-09-26 13:35:55 +02:00
binaerverkehr
85ec7c61e7 Render-Befehle
- self.screen.blit()
- pygame.display.update()
in Game.render() verschoben.
2026-09-26 13:30:30 +02:00
binaerverkehr
3ea58cff33 Unnötige Leerzeilen + Kommentare entfernt 2026-09-26 13:29:00 +02:00
binaerverkehr
67457a79fb if-Anweisung mit Ruff optimiert. 2026-09-26 13:27:37 +02:00
binaerverkehr
14848609f6 Unnötiger if-Block entfernt 2026-09-26 13:27:03 +02:00
binaerverkehr
10df1d884a overlaps_rect-Methode entfernt 2026-09-26 13:26:39 +02:00
binaerverkehr
8bc852c29d Unnötige Game.flashlight Variable gelöscht 2026-09-26 13:26:15 +02:00
binaerverkehr
48cda170dd Game.light_radius durch Konstante LIGHT_RADIUS ersetzt. 2026-09-26 13:25:13 +02:00
binaerverkehr
fd9018d0f1 Unnötige Instanzvariablen durch Konstante PLAYER_SIZE ersetzt. 2026-09-26 13:22:28 +02:00
binaerverkehr
e3c70182fb Game.__init__ aufgeräumt und kommentiert. 2026-09-26 13:20:38 +02:00
binaerverkehr
e17c55fbcf Mit Ruff formatiert 2026-09-26 13:19:09 +02:00
1265 changed files with 221 additions and 1157 deletions

1
.gitignore vendored
View file

@ -221,3 +221,4 @@ __marimo__/
rechner.py rechner.py
data/

Binary file not shown.

BIN
ZIPTE.png

Binary file not shown.

Before

Width:  |  Height:  |  Size: 398 KiB

View file

@ -1,131 +0,0 @@
import pygame
from scripts.constants import *
from scripts.flashlight import Flashlight
from scripts.level import Level
from scripts.player import Player
from scripts.utils import load_image
from scripts.wall import Wall
class Game:
def __init__(self):
# Pygame setup
pygame.init()
pygame.display.set_caption("School Game")
self.clock = pygame.Clock()
# Surfaces
self.screen: pygame.Surface = pygame.display.set_mode(
(SCREEN_WIDTH, SCREEN_HEIGHT)
)
# Pygame-Variablen
self.running: bool = True
self.dt: int = 0
# Spieler
self.player_pos = pygame.Vector2(
self.screen.get_width() / 2, self.screen.get_height() / 2
)
# Assets
self.assets = {
"floor_01": load_image("level/ground/floor_1.png"),
"plant_01": load_image("items/furniture/plants/plant.png"),
"wall": load_image("level/walls/wall_0.png"),
"player": load_image("entity/player/player.png"),
}
self.player = Player(self.player_pos, width=PLAYER_SIZE, height=PLAYER_SIZE, image=self.assets["player"])
self.flashlight_player = Flashlight(self, self.player)
self.level = Level(
game=self,
items=[],
walls=[
Wall(self, 0, 0, SCREEN_WIDTH//TILE_SIZE, 1),
Wall(self, 0, TILE_SIZE, 1, SCREEN_HEIGHT//TILE_SIZE),
Wall(
self, TILE_SIZE, SCREEN_HEIGHT - TILE_SIZE, SCREEN_WIDTH//TILE_SIZE, 1
),
Wall(self, SCREEN_WIDTH - TILE_SIZE, 0, 1, SCREEN_HEIGHT//TILE_SIZE),
Wall(self, 500, 500, 2, 2)
],
)
self.level_zustand: int = 0
@property
def walls(self):
return self.level.walls
@property
def items(self):
return self.level.items
def update(self) -> None:
# Ereignisse
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
if event.key == pygame.K_q:
self.flashlight_player.light_state = (
not self.flashlight_player.light_state
)
if event.type == pygame.KEYUP and event.key == pygame.K_LSHIFT:
self.player.speed = 150
# Spielzustände aktualisieren
self.player.update(walls=self.walls, dt=self.dt)
self.flashlight_player.update()
for item in self.items:
item.update()
def render(self) -> None:
# Hintergrund
self.screen.fill((0, 0, 0, 0))
self.level.render(self.screen)
# 1. Zeichne 1 Tile -> []
# 2. Zeichne eine Reihe von Tiles -> [][][][][][]
# 3. Zeichne mehrere Reihen von Tiles
# -> [][][][][][]
# -> [][][][][][]
# -> [][][][][][]
# Licht
self.flashlight_player.render(self.screen)
for item in self.items:
item.render(self.screen)
# Spieler
self.player.render(self.screen)
# Surfaces aktualisieren
pygame.display.update()
def run(self) -> None:
while self.running:
self.dt: float = self.clock.tick(60) / 1000.0
self.update()
self.render()
game = Game()
game.run()
"""
Wie funktioniert Kollision mit Bildern?????????????????????????!!!!!!!!!!!!!!!!!!!!!!!!!!!
(Günter hat ein Tutorial)
"""

View file

@ -1,76 +0,0 @@
import pygame
from pygame.math import Vector2
from scripts.constants import *
class Player:
def __init__(self, pos: pygame.Vector2, width, height, image: pygame.Surface=None):
self.pos: Vector2 = pos
self.width: float = width
self.height: float = height
self.speed = 150
self.image = image
self.mask = pygame.mask.from_surface(image)
self.rect = image.get_frect(center=(64, 64))
# self.rect = pygame.Rect(
# self.pos[0] - self.width / 2, self.pos[1] - self.height / 2, width, height
# )
def update(self, walls, dt):
keys = pygame.key.get_pressed()
direction = pygame.Vector2(
keys[pygame.K_d] - keys[pygame.K_a], keys[pygame.K_s] - keys[pygame.K_w]
)
if direction.length_squared() > 0:
direction = direction.normalize()
movement: pygame.Vector2 = direction * self.speed * dt
self.pos.x += movement.x
if self.pos.x - self.width / 2 < 0:
self.pos.x = self.width / 2
if self.pos.x + self.width / 2 > SCREEN_WIDTH:
self.pos.x = SCREEN_WIDTH - self.width / 2
self.rect.centerx = round(self.pos.x)
for wall in walls:
wall_rect = wall.get_rect()
if self.mask.overlap(pygame.mask.from_surface(wall.image), (0, 0)):
if movement.x > 0:
self.rect.right = wall_rect.left
elif movement.x < 0:
self.rect.left = wall_rect.right
self.pos.x = self.rect.centerx
self.pos.y += movement.y
if self.pos.y - self.height / 2 < 0:
self.pos.y = self.height / 2
if self.pos.y + self.height / 2 > SCREEN_HEIGHT:
self.pos.y = SCREEN_HEIGHT - self.height / 2
self.rect.centery = round(self.pos.y)
for wall in walls:
wall_rect = wall.get_rect()
offset = (int(self.rect.x) - wall_rect.x, int(self.rect.y) - wall_rect.y)
if self.mask.overlap(pygame.mask.from_surface(wall.image), offset):
if movement.y > 0:
self.rect.bottom = wall_rect.top
elif movement.y < 0:
self.rect.top = wall_rect.bottom
self.pos.y = self.rect.centery
def render(self, surface: pygame.Surface):
if not self.image:
pygame.draw.rect(surface, self.color, self.rect)
else:
surface.blit(
self.image,
(self.pos[0]-TILE_SIZE/2, self.pos[1]-TILE_SIZE/2-10, self.image.get_width(), self.image.get_height()),
)

View file

@ -1,35 +0,0 @@
import pygame
from scripts.constants import *
class Wall:
def __init__(self, game, x: float, y: float, cols: int, rows: int):
self.game = game
self.x = x
self.y = y
self.cols = cols
self.rows = rows
self.rect = pygame.Rect(x, y, cols*TILE_SIZE, rows*TILE_SIZE)
self.drawed_rect = None
self.grid: list[list[pygame.Rect]] = []
self.image = self.game.assets["wall"]
for row in range(self.rows): # rows
current_row = []
for col in range(self.cols): # cols
current_row.append(pygame.Rect(self.x+col*TILE_SIZE, self.y+row*TILE_SIZE, col*TILE_SIZE, row*TILE_SIZE))
self.grid.append(current_row)
def update(self):
pass
def render(self, surface: pygame.Surface):
for row in self.grid:
for wall_rect in row:
surface.blit(self.image, wall_rect)
def get_rect(self) -> pygame.Rect:
return self.rect

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.1 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 53 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 135 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 144 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.5 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.8 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.9 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.6 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.9 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.7 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.6 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.5 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.3 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.5 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.3 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.2 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.3 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.1 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.7 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.5 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.5 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.8 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.9 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.8 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.8 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.7 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.3 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.6 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.6 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.4 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.4 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.4 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.8 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.8 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.8 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.7 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.7 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.6 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.6 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.6 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.3 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.3 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.2 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.3 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.1 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.2 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.8 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.6 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.9 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.8 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.9 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.8 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.8 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.3 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.1 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.7 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.5 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.8 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.7 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.7 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.3 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.3 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.9 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.2 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.8 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.5 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.5 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.7 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.8 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.3 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.9 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.7 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.6 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.6 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.5 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.9 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.2 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.8 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.6 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.8 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.8 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.7 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.1 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.3 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.2 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.2 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.5 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.4 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.4 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.2 KiB

Some files were not shown because too many files have changed in this diff Show more