add: new action seed, harvest; change: new land images

This commit is contained in:
Aliaksei Brown 2023-03-27 15:29:06 +02:00
parent 25348047e8
commit b311117eee
13 changed files with 65 additions and 20 deletions

View File

@ -19,6 +19,13 @@ class Blocks:
self.alive_leaf_image = pygame.image.load(r'resources/alive.png').convert_alpha()
self.alive_leaf_image = pygame.transform.scale(self.alive_leaf_image, (cell_size, cell_size))
self.fawn_seed_image = pygame.image.load(r'resources/fawn_seed.png').convert_alpha()
self.fawn_seed_image = pygame.transform.scale(self.fawn_seed_image, (cell_size, cell_size))
self.fawn_wheat_image = pygame.image.load(r'resources/fawn_wheat.png').convert_alpha()
self.fawn_wheat_image = pygame.transform.scale(self.fawn_wheat_image, (cell_size, cell_size))
self.soil = soil.Soil()
def locate_blocks(self, blocks_number, cell_number, body):
@ -42,6 +49,12 @@ class Blocks:
self.parent_screen.blit(self.stone_image, (x, y))
if color == 'flower':
self.parent_screen.blit(self.flower_image, (x, y))
if color == 'fawn_seed':
self.parent_screen.blit(self.fawn_seed_image, (x, y))
if color == 'fawn_wheat':
self.parent_screen.blit(self.fawn_wheat_image, (x, y))
# if color == 'potato':
# pass

21
land.py
View File

@ -9,27 +9,24 @@ class Land:
self._irrigation = irrigation
self.all_soil_body = all_soil_body
self.grass_image = pygame.image.load(r'resources/grass.png').convert()
self.grass_image = pygame.image.load(r'resources/grass.png').convert_alpha()
self.grass_image = pygame.transform.scale(self.grass_image, (cell_size, cell_size))
self.bad_grass_image = pygame.image.load(r'resources/bad_grass.png').convert()
self.bad_grass_image = pygame.transform.scale(self.bad_grass_image, (cell_size, cell_size))
# self.bad_grass_image = pygame.image.load(r'resources/bad_grass.png').convert()
# self.bad_grass_image = pygame.transform.scale(self.bad_grass_image, (cell_size, cell_size))
self.black_earth_image = pygame.image.load(r'resources/black_earth.png').convert()
self.black_earth_image = pygame.image.load(r'resources/grass.png').convert()
self.black_earth_image = pygame.transform.scale(self.black_earth_image, (cell_size, cell_size))
self.brown_earth_image = pygame.image.load(r'resources/brown_earth.png').convert()
self.brown_earth_image = pygame.transform.scale(self.brown_earth_image, (cell_size, cell_size))
self.green_earth_image = pygame.image.load(r'resources/grass.png').convert()
self.green_earth_image = pygame.transform.scale(self.green_earth_image, (cell_size, cell_size))
self.fawn_soil_image = pygame.image.load(r'resources/fawn_soil.png').convert()
self.fawn_soil_image = pygame.transform.scale(self.fawn_soil_image, (cell_size, cell_size))
self.fen_soil_image = pygame.image.load(r'resources/fen_soil.png').convert()
self.fen_soil_image = pygame.image.load(r'resources/grass.png').convert()
self.fen_soil_image = pygame.transform.scale(self.fen_soil_image, (cell_size, cell_size))
# for i in range(0, cell_number):
# for k in range(0, cell_number):
# all_soil_body.append([i, k])
def locate_soil(self, soil_body): # finds free places(coordinates) for soil and adds them to soil_body[]
number_of_blocs_for_each_soil = 50
@ -53,8 +50,8 @@ class Land:
y = int(body[1] * self.cell_size)
if soil_name == 'black_earth':
self.parent_screen.blit(self.black_earth_image, (x, y))
if soil_name == 'brown_earth':
self.parent_screen.blit(self.brown_earth_image, (x, y))
if soil_name == 'green_earth':
self.parent_screen.blit(self.green_earth_image, (x, y))
if soil_name == 'fawn_soil':
self.parent_screen.blit(self.fawn_soil_image, (x, y))
if soil_name == 'fen_soil':

29
main.py
View File

@ -15,6 +15,7 @@ class Game:
blocks_number = 15
def __init__(self):
self.dead_leaf_body = []
self.green_leaf_body = []
self.stone_body = []
@ -22,8 +23,11 @@ class Game:
self.dead_grass_body = []
self.grass_body = []
self.fawn_seed_body = []
self.fawn_wheat_body = []
self.black_earth_body = []
self.brown_earth_body = []
self.green_earth_body = []
self.fawn_soil_body = []
self.fen_soil_body = []
self.allBodyPos = []
@ -37,8 +41,8 @@ class Game:
# finds places for every type soil and grass
self.black_earth = land.Land(self.surface, self.cell_size, self.cell_number, self.allBodyPos, 100)
self.black_earth.locate_soil(self.black_earth_body)
self.brown_earth = land.Land(self.surface, self.cell_size, self.cell_number, self.allBodyPos, 100)
self.brown_earth.locate_soil(self.brown_earth_body)
self.green_earth = land.Land(self.surface, self.cell_size, self.cell_number, self.allBodyPos, 100)
self.green_earth.locate_soil(self.green_earth_body)
self.fawn_soil = land.Land(self.surface, self.cell_size, self.cell_number, self.allBodyPos, 100)
self.fawn_soil.locate_soil(self.fawn_soil_body)
self.fen_soil = land.Land(self.surface, self.cell_size, self.cell_number, self.allBodyPos, 100)
@ -50,8 +54,8 @@ class Game:
self.blocks.locate_blocks(self.blocks_number, self.cell_number, self.stone_body)
self.blocks.locate_blocks(self.blocks_number, self.cell_number, self.flower_body)
self.potato = blocks.Blocks(self.surface, self.cell_size)
self.potato.locate_soil('black earth', 6, 1, [])
# self.potato = blocks.Blocks(self.surface, self.cell_size)
# self.potato.locate_soil('black earth', 6, 1, [])
self.tractor = tractor.Tractor(self.surface, self.cell_size)
self.tractor.draw()
@ -84,23 +88,34 @@ class Game:
if pygame.key.get_pressed()[K_SPACE]:
self.tractor.water(self.dead_leaf_body, self.green_leaf_body, self.cell_size)
# self.tractor.water(self.grass_body, self.dead_grass_body, self.cell_size)
if pygame.key.get_pressed()[K_q]:
self.tractor.harvest(self.fawn_seed_body, self.fawn_wheat_body, self.cell_size)
self.tractor.put_seed(self.fawn_soil_body, self.fawn_seed_body, self.cell_size)
elif event.type == QUIT:
running = False
self.surface.fill((140, 203, 97)) # background color
self.surface.fill((123, 56, 51)) # background color
self.grass.set_and_place_block_of_grass('good')
self.black_earth.place_soil(self.black_earth_body, 'black_earth')
self.brown_earth.place_soil(self.brown_earth_body, 'brown_earth')
self.green_earth.place_soil(self.green_earth_body, 'green_earth')
self.fawn_soil.place_soil(self.fawn_soil_body, 'fawn_soil')
self.fen_soil.place_soil(self.fen_soil_body, 'fen_soil')
#plants examples
self.blocks.place_blocks(self.surface, self.cell_size, self.dead_leaf_body, 'leaf')
self.blocks.place_blocks(self.surface, self.cell_size, self.green_leaf_body, 'alive')
self.blocks.place_blocks(self.surface, self.cell_size, self.stone_body, 'stone')
self.blocks.place_blocks(self.surface, self.cell_size, self.flower_body, 'flower')
#seeds
self.blocks.place_blocks(self.surface, self.cell_size, self.fawn_seed_body, 'fawn_seed')
#wheat
self.blocks.place_blocks(self.surface, self.cell_size, self.fawn_wheat_body, 'fawn_wheat')
self.tractor.draw()
pygame.display.update()

View File

Before

Width:  |  Height:  |  Size: 2.6 KiB

After

Width:  |  Height:  |  Size: 2.6 KiB

BIN
resources/black_seed.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 15 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 15 KiB

After

Width:  |  Height:  |  Size: 24 KiB

BIN
resources/earth2.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 23 KiB

BIN
resources/fawn_seed.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 18 KiB

View File

Before

Width:  |  Height:  |  Size: 14 KiB

After

Width:  |  Height:  |  Size: 14 KiB

View File

Before

Width:  |  Height:  |  Size: 2.8 KiB

After

Width:  |  Height:  |  Size: 2.8 KiB

View File

Before

Width:  |  Height:  |  Size: 16 KiB

After

Width:  |  Height:  |  Size: 16 KiB

View File

Before

Width:  |  Height:  |  Size: 53 KiB

After

Width:  |  Height:  |  Size: 53 KiB

View File

@ -22,7 +22,7 @@ class Tractor:
self.angle = 0
self.direction = 'up'
self.image = self.down
self.step = 0
self.lastVisitedBlocks = [] # as tractor moves it stores last 3 coordinates
@ -47,7 +47,10 @@ class Tractor:
if self.x != (cell_number-1)*cell_size:
self.x += cell_size
self.image = self.right
self.step = self.step + 1
print(self.x, self.y)
print(self.step)
def water(self, body_before, body_after, cell_size):
self.pos = [self.x/cell_size, self.y/cell_size]
@ -57,6 +60,23 @@ class Tractor:
print('HERE!')
#print(body)
def put_seed(self, body, seed_body, cell_size):
#self.step = 0
self.pos = [self.x/cell_size, self.y/cell_size]
if self.pos in body:
#body.remove(self.pos)
seed_body.append(self.pos)
print('HERE IS THE SEED!')
def harvest(self, seed_body, wheat_body, cell_size):
self.pos = [self.x/cell_size, self.y/cell_size]
if self.pos in seed_body:
seed_body.remove(self.pos)
wheat_body.append(self.pos)
print('HERE IS THE WHEAT!')
def walk(self):
choice = ['up', 'down', 'left', 'right']