27 lines
991 B
Python
27 lines
991 B
Python
import pygame, random
|
|
|
|
from DataModels.Container import Container
|
|
|
|
from PIL import Image,ImageDraw
|
|
from config import CELL_SIZE
|
|
|
|
class Cell( pygame.sprite.Sprite ):
|
|
def __init__( self, x, y, max_rubbish, yellow = 0, green = 0, blue = 0, image_name = None):
|
|
pygame.sprite.Sprite.__init__( self )
|
|
self.image_name = image_name or type(self).__name__
|
|
self.update_rect( x,y )
|
|
self.container = Container( max_rubbish, yellow, green, blue )
|
|
self.update_image()
|
|
|
|
def update_rect( self, x, y ):
|
|
self.x, self.y = x,y
|
|
self.rect = pygame.Rect( x * CELL_SIZE, y * CELL_SIZE, CELL_SIZE, CELL_SIZE )
|
|
|
|
def update_image( self ):
|
|
image = Image.open("Resources/Images/Image_" + self.image_name + ".png" )
|
|
draw = ImageDraw.Draw(image)
|
|
draw.text( (5,5), str( self.container.status() ) )
|
|
mode, size, data = image.mode, image.size, image.tobytes()
|
|
|
|
self.image = pygame.image.frombuffer( data, size, mode )
|