new: fruits icons, function locat_fruit, fruits_list

This commit is contained in:
Aliaksei Brown 2023-06-18 01:59:54 +02:00
parent 45a6113acf
commit ea24f48acc
20 changed files with 77 additions and 24 deletions

BIN
.DS_Store vendored

Binary file not shown.

View File

@ -11,10 +11,13 @@ class Chicken:
self.left = pygame.image.load(r'resources/chicken/left.png').convert_alpha()
self.right = pygame.image.load(r'resources/chicken/right.png').convert_alpha()
self.up = pygame.transform.scale(self.up, (cell_size+2, cell_size))
self.down = pygame.transform.scale(self.down, (cell_size, cell_size+2))
self.left = pygame.transform.scale(self.left, (cell_size+2, cell_size+2))
self.right = pygame.transform.scale(self.right, (cell_size+4, cell_size+1))
self.cell_size = cell_size
self.cell_number = cell_number
self.up = pygame.transform.scale(self.up, (self.cell_size+2, self.cell_size))
self.down = pygame.transform.scale(self.down, (self.cell_size, self.cell_size+2))
self.left = pygame.transform.scale(self.left, (self.cell_size+2, self.cell_size+2))
self.right = pygame.transform.scale(self.right, (self.cell_size+4, self.cell_size+1))
self.x = 1 # to-check: start pos may be written explicit
self.y = 1
@ -22,8 +25,6 @@ class Chicken:
self.direction = 'up'
self.image = self.down
self.step = 0
self.cell_size = cell_size
self.cell_number = cell_number
def move(self, direction):
print('MOVE')

View File

@ -9,39 +9,45 @@ class PlantsSettings:
self.cell_number = cell_number
self.cell_size = cell_size
self.surface = surface
self.all_blocks = []
self.all_plants = []
self.all_fruits = []
#plants
self.flower_image = pygame.image.load(r'resources/plants/flower.png').convert_alpha()
self.flower_image = pygame.transform.scale(self.flower_image, (self.cell_size, self.cell_size))
self.eggplant_image = pygame.image.load(r'resources/vegies/1.png').convert_alpha()
self.eggplant_image = pygame.transform.scale(self.eggplant_image, (self.cell_size, self.cell_size))
self.stone_image = pygame.image.load(r'resources/stones/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/plants/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/plants/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/plants/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/plants/wheat.png').convert_alpha()
self.wheat_image = pygame.transform.scale(self.wheat_image, (self.cell_size, self.cell_size))
#vegies
self.eggplant_image = pygame.image.load(r'resources/vegies/1.png').convert_alpha()
self.eggplant_image = pygame.transform.scale(self.eggplant_image, (self.cell_size, self.cell_size))
#fruits
self.strawberrie_image = pygame.image.load(r'resources/fruits/6.png').convert_alpha()
self.strawberrie_image = pygame.transform.scale(self.strawberrie_image, (self.cell_size, self.cell_size))
self.grapes_image = pygame.image.load(r'resources/fruits/8.png').convert_alpha()
self.grapes_image = pygame.transform.scale(self.grapes_image, (self.cell_size-12, self.cell_size))
self.apple_image = pygame.image.load(r'resources/fruits/9.png').convert_alpha()
self.apple_image = pygame.transform.scale(self.apple_image, (self.cell_size, self.cell_size))
self.banana_image = pygame.image.load(r'resources/fruits/10.png').convert_alpha()
self.banana_image = pygame.transform.scale(self.banana_image, (self.cell_size, self.cell_size))
self.stone_image = pygame.image.load(r'resources/stones/stone.png').convert_alpha()
self.stone_image = pygame.transform.scale(self.stone_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 [rand_x, rand_y] not in self.all_plants:
self.all_plants.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
@ -73,6 +79,40 @@ class PlantsSettings:
field_list.append(self.block)
break
def locate_fruit(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_fruits:
self.all_fruits.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 == 'strawberrie':
self.block = plant.Plant(
i, name, 1, self.strawberrie_image, self.strawberrie_image, rand_x, rand_y, False
)
if name == 'grapes':
self.block = plant.Plant(
i, name, 1, self.grapes_image, self.grapes_image, rand_x, rand_y, False
)
if name == 'apple':
self.block = plant.Plant(
i, name, 1, self.apple_image, self.apple_image, rand_x, rand_y, False
)
if name == 'banana':
self.block = plant.Plant(
i, name, 1, self.banana_image, self.banana_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
)
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

20
main.py
View File

@ -31,6 +31,7 @@ class Game:
self.grass_list = [] # 1-level
self.plant_list = [] # 2-level
self.fruits_list = [] # 2-level - second model agent
self.stone_list = [] # 3-level
self.aim_list = [] # 4-level
@ -40,13 +41,23 @@ class Game:
self.Plants = plants_settings.PlantsSettings(self.surface, self.cell_size, self.cell_number)
self.Plants.locate_plant(self.plant_list, 'wheat', self.blocks_number)
self.Plants.locate_plant(self.plant_list, 'flower', self.blocks_number)
self.Plants.locate_plant(self.plant_list, 'eggplant', self.blocks_number)
#plant_list
# self.Plants.locate_plant(self.plant_list, 'wheat', self.blocks_number)
# self.Plants.locate_plant(self.plant_list, 'flower', self.blocks_number)
# self.Plants.locate_plant(self.plant_list, 'bush', self.blocks_number)
#fruits_list
self.Plants.locate_fruit(self.fruits_list, 'apple', self.blocks_number)
self.Plants.locate_fruit(self.fruits_list, 'banana', self.blocks_number)
self.Plants.locate_fruit(self.fruits_list, 'strawberry', self.blocks_number)
self.Plants.locate_fruit(self.fruits_list, 'grapes', self.blocks_number)
self.Plants.locate_fruit(self.plant_list, 'wheat', self.blocks_number)
self.Plants.locate_aim(self.aim_list, 0, 0)
self.Plants.locate_plant(self.stone_list, 'stone', self.blocks_number)
self.Plants.locate_fruit(self.stone_list, 'stone', self.blocks_number)
#self.image_wheat = self.Plants.wheat_watered()
self.chicken = chick.Chicken(self.surface, self.cell_size, self.cell_number)
@ -118,6 +129,7 @@ class Game:
self.surface.fill((123, 56, 51)) # background color
self.Field.draw_grass(self.grass_list)
self.Plants.draw_plant(self.plant_list)
self.Plants.draw_plant(self.fruits_list)
self.Plants.draw_plant(self.stone_list)
self.Plants.draw_aim(self.aim_list)

BIN
resources/.DS_Store vendored

Binary file not shown.

BIN
resources/fruits/.DS_Store vendored Normal file

Binary file not shown.

BIN
resources/fruits/10.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 10 KiB

BIN
resources/fruits/11.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 60 KiB

BIN
resources/fruits/2.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 72 KiB

BIN
resources/fruits/4.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 11 KiB

BIN
resources/fruits/5.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 11 KiB

BIN
resources/fruits/6.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 10 KiB

BIN
resources/fruits/8.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.2 KiB

BIN
resources/fruits/9.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 12 KiB

BIN
resources/vegies/.DS_Store vendored Normal file

Binary file not shown.

BIN
resources/vegies/3.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 93 KiB

BIN
resources/vegies/7.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 11 KiB