2023-04-21 06:30:54 +02:00
|
|
|
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
|
|
|
|
|
2023-06-15 14:03:24 +02:00
|
|
|
|
2023-04-21 06:30:54 +02:00
|
|
|
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)
|
|
|
|
|
2023-06-15 14:03:24 +02:00
|
|
|
|
2023-04-21 06:30:54 +02:00
|
|
|
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))
|
|
|
|
|
2023-06-15 14:03:24 +02:00
|
|
|
|
2023-04-21 06:30:54 +02:00
|
|
|
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()
|
|
|
|
|
2023-06-15 14:03:24 +02:00
|
|
|
|
2023-04-21 06:30:54 +02:00
|
|
|
def getGridBoxes(grid_box):
|
2023-06-15 14:03:24 +02:00
|
|
|
global gridObjects
|
|
|
|
return gridObjects[grid_box]
|