86 lines
4.1 KiB
Python
86 lines
4.1 KiB
Python
![]() |
import pygame
|
||
|
import random
|
||
|
import models.field_block as field_block
|
||
|
import models.plant as plant
|
||
|
|
||
|
|
||
|
|
||
|
class PlantsSettings:
|
||
|
def __init__(self, surface, cell_size, cell_number):
|
||
|
self.cell_number = cell_number
|
||
|
self.cell_size = cell_size
|
||
|
self.surface = surface
|
||
|
self.all_blocks = []
|
||
|
|
||
|
self.flower_image = pygame.image.load(r'resources/flower.png').convert_alpha()
|
||
|
self.flower_image = pygame.transform.scale(self.flower_image, (self.cell_size, self.cell_size))
|
||
|
|
||
|
self.stone_image = pygame.image.load(r'resources/stone.png').convert_alpha()
|
||
|
self.stone_image = pygame.transform.scale(self.stone_image, (self.cell_size, self.cell_size))
|
||
|
|
||
|
self.bush_image = pygame.image.load(r'resources/bush.png').convert_alpha()
|
||
|
self.bush_image = pygame.transform.scale(self.bush_image, (self.cell_size, self.cell_size))
|
||
|
|
||
|
self.ivy_image = pygame.image.load(r'resources/ivy.png').convert_alpha()
|
||
|
self.ivy_image = pygame.transform.scale(self.ivy_image, (self.cell_size, self.cell_size))
|
||
|
|
||
|
self.wheat_dead_image = pygame.image.load(r'resources/wheat_dead.png').convert_alpha()
|
||
|
self.wheat_dead_image = pygame.transform.scale(self.wheat_dead_image, (self.cell_size, self.cell_size))
|
||
|
self.wheat_image = pygame.image.load(r'resources/wheat.png').convert_alpha()
|
||
|
self.wheat_image = pygame.transform.scale(self.wheat_image, (self.cell_size, self.cell_size))
|
||
|
|
||
|
self.aim_image = pygame.image.load(r'resources/aim.png').convert_alpha()
|
||
|
self.aim_image = pygame.transform.scale(self.aim_image, (self.cell_size, self.cell_size))
|
||
|
|
||
|
def locate_plant(self, field_list, name, num_of_blocks): # finds open space (coordinates)
|
||
|
|
||
|
for i in range(num_of_blocks):
|
||
|
while True:
|
||
|
rand_x = random.randint(0, self.cell_number - 1) # to check
|
||
|
rand_y = random.randint(0, self.cell_number - 1)
|
||
|
if [rand_x, rand_y] not in self.all_blocks:
|
||
|
self.all_blocks.append([rand_x, rand_y])
|
||
|
if name == 'wheat':
|
||
|
self.block = plant.Plant(
|
||
|
i, name, 0, self.wheat_dead_image, self.wheat_image, rand_x, rand_y, False
|
||
|
)
|
||
|
if name == 'ivy':
|
||
|
self.block = plant.Plant(
|
||
|
i, name, 1, self.ivy_image, self.ivy_image, rand_x, rand_y, False
|
||
|
)
|
||
|
if name == 'flower':
|
||
|
self.block = plant.Plant(
|
||
|
i, name, 1, self.flower_image, self.flower_image, rand_x, rand_y, False
|
||
|
)
|
||
|
if name == 'stone':
|
||
|
self.block = plant.Plant(
|
||
|
i, name, 1, self.stone_image, self.stone_image, rand_x, rand_y, False
|
||
|
)
|
||
|
if name == 'buch':
|
||
|
self.block = plant.Plant(
|
||
|
i, name, 1, self.bush_image, self.bush_image, rand_x, rand_y, False
|
||
|
)
|
||
|
if name == 'aim':
|
||
|
self.block = plant.Plant(
|
||
|
999, name, 1, self.aim_image, self.aim_image, rand_x, rand_y, False
|
||
|
)
|
||
|
field_list.append(self.block)
|
||
|
break
|
||
|
|
||
|
def locate_aim(self, field_list, x, y):
|
||
|
self.block = plant.Plant(
|
||
|
999, 'aim', 1, self.aim_image, self.aim_image, x, y, False
|
||
|
)
|
||
|
field_list.append(self.block)
|
||
|
|
||
|
def draw_plant(self, field_list):
|
||
|
for obj in field_list:
|
||
|
if obj.state == 0:
|
||
|
self.surface.blit(obj.image_state_zero, (int(obj.xy[0] * self.cell_size), int(obj.xy[1] * self.cell_size)))
|
||
|
if obj.state == 1:
|
||
|
self.surface.blit(obj.image_state_one, (int(obj.xy[0] * self.cell_size), int(obj.xy[1] * self.cell_size)))
|
||
|
|
||
|
def draw_aim(self, aim_list):
|
||
|
x = int(aim_list[0].xy[0] * self.cell_size)
|
||
|
y = int(aim_list[0].xy[1] * self.cell_size)
|
||
|
self.surface.blit(self.aim_image, (x, y)) # rotate tractor
|