2024-03-13 23:25:49 +01:00
|
|
|
import pygame
|
|
|
|
import prefs
|
2024-05-05 12:39:12 +02:00
|
|
|
|
2024-03-13 23:25:49 +01:00
|
|
|
class Cell:
|
2024-05-05 12:39:12 +02:00
|
|
|
def __init__(self, x, y,waga, blocking_movement=False, interactableItem=False, texture=None):
|
2024-03-13 23:25:49 +01:00
|
|
|
self.X = x
|
|
|
|
self.Y = y
|
2024-05-05 12:39:12 +02:00
|
|
|
self.waga = waga
|
2024-03-13 23:25:49 +01:00
|
|
|
self.rect = pygame.Rect(x * prefs.CELL_SIZE, y * prefs.CELL_SIZE, prefs.CELL_SIZE, prefs.CELL_SIZE)
|
|
|
|
self.blocking_movement = blocking_movement
|
|
|
|
self.interactableItem = interactableItem
|
|
|
|
if texture:
|
|
|
|
self.prepareTexture(texture)
|
|
|
|
else:
|
|
|
|
self.texture = texture
|
2024-05-05 12:39:12 +02:00
|
|
|
|
|
|
|
def blit_text(self,tekst, x, y, rozmiar_czcionki,window):
|
|
|
|
font = pygame.font.Font('freesansbold.ttf', rozmiar_czcionki)
|
|
|
|
text = font.render(str(tekst), True, (0, 255, 0), (0, 0, 128))
|
|
|
|
textRect = text.get_rect()
|
|
|
|
textRect.center = (x,y)
|
|
|
|
window.blit(text, textRect)
|
2024-03-13 23:25:49 +01:00
|
|
|
|
|
|
|
def prepareTexture(self, texture):
|
|
|
|
preparedTexture = pygame.image.load(texture).convert_alpha()
|
|
|
|
preparedTexture = pygame.transform.scale(preparedTexture, (prefs.CELL_SIZE, prefs.CELL_SIZE))
|
|
|
|
self.texture = preparedTexture
|
2024-03-14 14:33:51 +01:00
|
|
|
def update(self,window):
|
2024-03-13 23:25:49 +01:00
|
|
|
if(self.texture):
|
|
|
|
window.blit(self.texture, self.rect)
|
|
|
|
else:
|
|
|
|
pygame.draw.rect(window, prefs.COLORS[(self.X*prefs.GRID_SIZE+self.Y)%len(prefs.COLORS)], self.rect)
|
|
|
|
pygame.draw.line(window, (0, 0, 0), (self.rect.left, self.rect.top), (self.rect.right, self.rect.top))
|
|
|
|
pygame.draw.line(window, (0, 0, 0), (self.rect.left, self.rect.top), (self.rect.left, self.rect.bottom))
|