school-horror-game/scripts/wall.py
2026-11-11 17:46:48 +01:00

38 lines
1.2 KiB
Python

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.image = self.game.assets["wall"]
self.rect = pygame.FRect(x, y, cols*TILE_SIZE, rows*TILE_SIZE)
self.mask = self.mask = pygame.Mask(self.rect.size, fill=True)
self.drawed_rect = None
self.grid: list[list[pygame.Rect]] = []
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)
self.see_rect = self.mask.get_rect()
print(f"X: {self.see_rect.x}, Y: {self.see_rect.y}")
def update(self):
pass
def render(self, surface: pygame.Surface):
for row in self.grid:
for wall_rect in row:
surface.blit(self.mask.to_surface(), wall_rect)
pygame.draw.rect(surface, "red", self.see_rect, 1)
def get_rect(self) -> pygame.Rect:
return self.rect