Projekt_Si/classes/cell.py

26 lines
1.2 KiB
Python
Raw Normal View History

2024-03-13 23:25:49 +01:00
import pygame
import prefs
class Cell:
def __init__(self, x, y, blocking_movement=False, interactableItem=False, texture=None):
self.X = x
self.Y = y
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
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
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))