import pygame from screen import SCREEN # global SCREEN global BLACK global gridObjects global imgTree global imgTree imgTree = pygame.image.load('img/tree.png') gridObjects = {} # Store grid-box objects from Grid Class class Grid(object): # ta klasa rysuje kratÄ™ na ekranie def __init__(self, x, y, sx, sy): self.x = x self.y = y self.sx = sx self.sy = sy self.width = 1 def draw(self): # global SCREEN global BLACK # SCREEN = pygame.display.set_mode([600,650]) BLACK = (0, 0, 0) pygame.draw.rect(SCREEN, BLACK, (self.x, self.y, self.sx, self.sy), self.width) class Box(object): # global SCREEN def __init__(self, x, y, sx, sy, color): self.x = x self.y = y self.sx = sx self.sy = sy self.color = color def draw(self): # global SCREEN # SCREEN = pygame.display.set_mode([600,650]) # global BLACK pygame.draw.rect(SCREEN, self.color, pygame.Rect(self.x, self.y, self.sx, self.sy)) class Obstacle(object): def __init__(self, mouseObj): self.mseX = mouseObj[0] self.mseY = mouseObj[1] for grid in gridObjects: g = getGridBoxes(grid) self.x = g.x self.y = g.y self.sx = g.sx self.sy = g.sy if self.mseX > self.x and self.mseX < self.x + self.sx: if self.mseY > self.y and self.mseY < self.y + self.sy: self.posX = self.x self.posY = self.y self.gridBox = grid def draw(self): # pygame.draw.rect(SCREEN, GREY, pygame.Rect(self.posX, self.posY, self.sx, self.sy)) global imgTree SCREEN.blit(imgTree, (self.posX, self.posY)) # pygame.display.update() def getGridBoxes(grid_box): global gridObjects return gridObjects[grid_box]