diff --git a/game.py b/game.py index 05645a7..7a010c3 100644 --- a/game.py +++ b/game.py @@ -5,6 +5,7 @@ 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: @@ -40,12 +41,13 @@ class Game: game=self, items=[], walls=[ - pygame.Rect(0, 0, SCREEN_WIDTH, TILE_SIZE), - pygame.Rect(0, TILE_SIZE, TILE_SIZE, SCREEN_HEIGHT), - pygame.Rect( - TILE_SIZE, SCREEN_HEIGHT - TILE_SIZE, SCREEN_WIDTH, TILE_SIZE + Wall(self, 0, 0, SCREEN_WIDTH, TILE_SIZE), + Wall(self, 0, TILE_SIZE, TILE_SIZE, SCREEN_HEIGHT), + Wall( + self, TILE_SIZE, SCREEN_HEIGHT - TILE_SIZE, SCREEN_WIDTH, TILE_SIZE ), - pygame.Rect(SCREEN_WIDTH - TILE_SIZE, 0, SCREEN_WIDTH, SCREEN_HEIGHT), + Wall(self, SCREEN_WIDTH - TILE_SIZE, 0, SCREEN_WIDTH, SCREEN_HEIGHT), + Wall(self, 500, 500, 128, 128) ], ) @@ -118,28 +120,11 @@ class Game: self.render() - - - -class Wall: - def __init__(self, game, x: float, y: float, width: float, height: float): - self.game = game - self.x = x - self.y = y - self.width = width - self.height = height - - def update(self): - pass - - def render(self, surface): - pass - - game = Game() game.run() """ -Ein paar Assets schonmal zurechtschneiden. +Fertigen Raum machen. +Immer alles strukturieren """ diff --git a/scripts/flashlight.py b/scripts/flashlight.py index d4658fe..1ab91e9 100644 --- a/scripts/flashlight.py +++ b/scripts/flashlight.py @@ -23,7 +23,7 @@ class Flashlight: for angle in range(360): ray_end = origin + base_ray.rotate(angle) for wall in self.game.walls: - intersection = wall.clipline(origin, ray_end) + intersection = wall.get_rect().clipline(origin, ray_end) if intersection: ray_end = pygame.Vector2(intersection[0]) points.append(ray_end) @@ -53,7 +53,7 @@ class Flashlight: # Überschneidung mit den Wänden prüfen for wall in self.game.walls: # Überschneidung - intersection = wall.clipline(origin, ray_end) + intersection = wall.get_rect().clipline(origin, ray_end) if intersection: ray_end = pygame.Vector2(intersection[0]) points.append(ray_end) diff --git a/scripts/level.py b/scripts/level.py index 1fa95c3..6986722 100644 --- a/scripts/level.py +++ b/scripts/level.py @@ -2,10 +2,11 @@ import pygame from scripts.constants import * from scripts.item import Item +from scripts.wall import Wall class Level: - def __init__(self, game, items: list[Item], walls: list[pygame.Rect]): + def __init__(self, game, items: list[Item], walls: list[Wall]): self.game = game # Items @@ -24,7 +25,5 @@ class Level: # Wände for wall in self.walls: - surface.blit(self.game.assets["wall"], wall) - - def draw_walls(self, surface: pygame.Surface): - pass + wall.render(surface) + \ No newline at end of file diff --git a/scripts/player.py b/scripts/player.py index 8468ebc..1e9d1a0 100644 --- a/scripts/player.py +++ b/scripts/player.py @@ -34,6 +34,7 @@ class Player: self.rect.centerx = round(self.pos.x) for wall in walls: + wall = wall.get_rect() if self.rect.colliderect(wall): if movement.x > 0: self.rect.right = wall.left @@ -50,6 +51,7 @@ class Player: self.rect.centery = round(self.pos.y) for wall in walls: + wall = wall.get_rect() if self.rect.colliderect(wall): if movement.y > 0: self.rect.bottom = wall.top diff --git a/scripts/wall.py b/scripts/wall.py index e69de29..1455352 100644 --- a/scripts/wall.py +++ b/scripts/wall.py @@ -0,0 +1,38 @@ +import pygame + +from scripts.constants import * + + +class Wall: + def __init__(self, game, x: float, y: float, width: float, height: float): + self.game = game + self.x = x + self.y = y + self.width = width + self.height = height + self.rect = pygame.Rect(x, y, width, height) + + for i in range(self.width): + if i % 64 == 0: + end_ergebnis_width = i + + for i in range(self.height): + if i % 64 == 0: + end_ergebnis_height = i + + self.length: dict = { + "width": end_ergebnis_width+TILE_SIZE, + "height": end_ergebnis_height+TILE_SIZE, + } + + def update(self): + pass + + def render(self, surface: pygame.Surface): + for x in range(self.length["width"]): + for y in range(self.length["height"]): + if y % TILE_SIZE == 0 and x % TILE_SIZE == 0: + surface.blit(self.game.assets["wall"], pygame.Rect(self.x+x, self.y+y, self.width, self.height)) + + def get_rect(self) -> pygame.Rect: + return self.rect \ No newline at end of file