diff --git a/game.py b/game.py index b6aec3b..d1a62ea 100644 --- a/game.py +++ b/game.py @@ -1,4 +1,6 @@ import pygame +from pygame.math import Vector2 +from pygame.rect import Rect SCREEN_WIDTH = 1280 SCREEN_HEIGHT = 720 @@ -25,9 +27,10 @@ class Game: self.item_rect = pygame.Rect(70, 150, 10, 10) self.flashlight_rect = pygame.Rect(0, 0, 0, 0) self.color_item = (0, 0, 0) - self.light_points: list[pygame.Vector2] = [] # Level self.walls = [pygame.Rect(100, 100, 20, 50), pygame.Rect(300, 300, 200, 20), pygame.Rect(550, 80, 20, 200)] + # Licht + self.light_points: list[pygame.Vector2] def run(self) -> None: while self.running: @@ -50,11 +53,11 @@ class Game: self.player.speed = 150 self.player.update(walls=self.walls, dt=self.dt) - self.create_light_points() + self.light_points: list[Vector2] = self.create_light_points() - def create_light_points(self): - self.light_points = [] + def create_light_points(self)-> list[pygame.Vector2]: + light_points: list[pygame.Vector2] = [] vector = pygame.Vector2(LIGHT_RADIUS, 0) # Lichtstrahlen berechnen @@ -68,15 +71,14 @@ class Game: if überschneidung: schnittpunkt = pygame.Vector2(überschneidung[0]) ray_end = schnittpunkt - self.light_points.append(ray_end) - + light_points.append(ray_end) + return light_points def render(self) -> None: self.display.fill((0, 0, 0, 0)) - self.flashlight_rect = pygame.draw.polygon(self.display, (243, 255, 74), self.light_points) - pygame.draw.rect(self.display, (255, 0, 0), self.flashlight_rect, 1) + self.flashlight_rect: Rect = pygame.draw.polygon(self.display, (243, 255, 74), self.light_points) self.player.render(surface=self.display) pygame.draw.rect(self.display, self.color_item, self.item_rect) @@ -87,28 +89,7 @@ class Game: pygame.display.update() def calculate_collsions(self) -> None: - - for light_ray in self.light_points: - nearest_x = self.player_pos.x - if self.player_pos.x < self.item_rect.left: - nearest_x = self.item_rect.left - elif self.player_pos.x > self.item_rect.right: - nearest_x = self.item_rect.right - - nearest_y = self.player_pos.y - if self.player_pos.y < self.item_rect.top: - nearest_y = self.item_rect.top - elif self.player_pos.y > self.item_rect.bottom: - nearest_y = self.item_rect.bottom - - dx = self.player_pos.x - nearest_x - dy = self.player_pos.y - nearest_y - distance_squared = dx * dx + dy * dy - - if distance_squared < light_ray.length_squared(): - self.color_item = (0, 0, 255) - else: - self.color_item = (0, 0, 0) + pass class Player: