from game.tilemap import *
class Block(pygame.sprite.Sprite):
def __init__(self, image, x, y):
pygame.sprite.Sprite.__init__(self)
self.image = pygame.image.load(get_tile_img(image))
self.image = pygame.transform.scale(self.image, (60, 60))
self.rect = self.image.get_rect()
def __init__(self, image, x, y):
Block.__init__(self, image, x, y)
class Inventory(pygame.sprite.Sprite):
def __init__(self, toolId, x, y):
pygame.sprite.Sprite.__init__(self)
self.image = pygame.image.load(get_tile_img(toolId))
self.rect = self.image.get_rect()
def __init__(self, image, x, y, time):
Block.__init__(self, image, x, y)
if self.life_time < 0:
if self.life_time < 0:
elif self.life_time == 0:
self.image = pygame.image.load(get_tile_img(PUMPKIN_BIG))
self.image = pygame.transform.scale(self.image, (60, 60))
def generate_level(map1, map2):
for i in range(len(map1)):
for j in range(len(map1[0])):
blocks.add(Block(map1[i][j], j * 60, i * 60))
objects.add(GardenBed(map2[i][j], j * 60, i * 60))
elif is_inventory(map2[i][j]):
inventory_sprites.add(Inventory(map2[i][j], j * 60, i * 60))
objects.add(Block(map2[i][j], j * 60, i * 60))
# Настройки игрового окна
screen = pygame.display.set_mode((WIDTH, HEIGHT))
pygame.display.set_caption("Tile game")
clock = pygame.time.Clock()
blocks = pygame.sprite.Group()
objects = pygame.sprite.Group()
vegetables = pygame.sprite.Group()
inventory_sprites = pygame.sprite.Group()
generate_level(ground_map_1, object_map_1)
# Может ли игрок садить растения
# Может ли игрок поливать
# Держим цикл на правильной скорости
# Ввод процесса (события)
for event in pygame.event.get():
# check for closing window
if event.type == pygame.QUIT:
elif event.type == pygame.MOUSEBUTTONDOWN:
mouse_x, mouse_y = event.pos
# Проверка на нажатие на ячейку инвентаря
for tool in inventory_sprites:
if tool.rect.collidepoint(mouse_x, mouse_y):
if tool.toolId == INV_SEEDS:
print('Взяли семена!')
elif tool.toolId == INV_BAILER:
print('Взяли лейку!')
elif tool.toolId == INV_HOE:
print('Взяли тяпку!')
if veg.rect.collidepoint(mouse_x, mouse_y):
# Если НЕ собрали какое-либо растение И в руках персонажа семена
if not harvested and can_plant:
if block.rect.collidepoint(mouse_x, mouse_y) and isinstance(block, GardenBed):
vegetables.add(Vegetable(PUMPKIN_SMALL, block.rect.x, block.rect.y, 200))
# После отрисовки всего, переворачиваем экран