changes: added a visible mark where the chicken goes to

This commit is contained in:
Aliaksei Brown 2023-05-08 21:15:37 +02:00
parent 5608eb2729
commit 0c025a857d
19 changed files with 59 additions and 6 deletions

BIN
.DS_Store vendored Normal file

Binary file not shown.

8
.idea/.gitignore vendored Normal file
View File

@ -0,0 +1,8 @@
# Default ignored files
/shelf/
/workspace.xml
# Editor-based HTTP Client requests
/httpRequests/
# Datasource local storage ignored files
/dataSources/
/dataSources.local.xml

View File

@ -0,0 +1,6 @@
<component name="InspectionProjectProfileManager">
<settings>
<option name="USE_PROJECT_PROFILE" value="false" />
<version value="1.0" />
</settings>
</component>

4
.idea/misc.xml Normal file
View File

@ -0,0 +1,4 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectRootManager" version="2" project-jdk-name="Python 3.8" project-jdk-type="Python SDK" />
</project>

8
.idea/modules.xml Normal file
View File

@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/.idea/si23traktor.iml" filepath="$PROJECT_DIR$/.idea/si23traktor.iml" />
</modules>
</component>
</project>

10
.idea/si23traktor.iml Normal file
View File

@ -0,0 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="PYTHON_MODULE" version="4">
<component name="NewModuleRootManager">
<content url="file://$MODULE_DIR$">
<excludeFolder url="file://$MODULE_DIR$/venv" />
</content>
<orderEntry type="jdk" jdkName="Python 3.8" jdkType="Python SDK" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>

6
.idea/vcs.xml Normal file
View File

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="$PROJECT_DIR$" vcs="Git" />
</component>
</project>

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -36,8 +36,8 @@ class Search:
# cost = node.distance # cost = node.distance
cost = 0 cost = 0
# cost += 10 if stones[node.state[0], node.state[1]] == 1 else 1 # cost += 10 if stones[node.state[0], node.state[1]] == 1 else 1
cost += 1000000 if (node.state[0], node.state[1]) in stones else 1 cost += 1000 if (node.state[0], node.state[1]) in stones else 1
cost += 30 if (node.state[0], node.state[1]) in flowers else 1 cost += 30 if ((node.state[0]), (node.state[1])) in flowers else 1
if node.parent: if node.parent:
node = node.parent node = node.parent

View File

@ -26,6 +26,8 @@ class Blocks:
self.fawn_wheat_image = pygame.image.load(r'resources/fawn_wheat.png').convert_alpha() 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.fawn_wheat_image = pygame.transform.scale(self.fawn_wheat_image, (cell_size, cell_size))
self.red_image = pygame.image.load(r'resources/redBush.png').convert_alpha()
self.red_image = pygame.transform.scale(self.red_image, (cell_size, cell_size))
self.soil = soil.Soil() self.soil = soil.Soil()
@ -59,6 +61,8 @@ class Blocks:
self.parent_screen.blit(self.fawn_seed_image, (x, y)) self.parent_screen.blit(self.fawn_seed_image, (x, y))
if color == 'fawn_wheat': if color == 'fawn_wheat':
self.parent_screen.blit(self.fawn_wheat_image, (x, y)) self.parent_screen.blit(self.fawn_wheat_image, (x, y))
if color == 'red':
self.parent_screen.blit(self.red_image, (x, y))

15
main.py
View File

@ -11,7 +11,7 @@ from pygame.locals import *
class Game: class Game:
cell_size = 50 cell_size = 50
cell_number = 15 # horizontally cell_number = 15 # horizontally
blocks_number = 15 blocks_number = 20
def __init__(self): def __init__(self):
@ -21,6 +21,7 @@ class Game:
self.flower_body = [] self.flower_body = []
self.dead_grass_body = [] self.dead_grass_body = []
self.grass_body = [] self.grass_body = []
self.red_block = [] #aim block
self.fawn_seed_body = [] self.fawn_seed_body = []
self.fawn_wheat_body = [] self.fawn_wheat_body = []
@ -53,6 +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.stone_body)
self.blocks.locate_blocks(self.blocks_number, self.cell_number, self.flower_body) self.blocks.locate_blocks(self.blocks_number, self.cell_number, self.flower_body)
#self.blocks.locate_blocks(1, self.cell_number, self.red_block)
# self.potato = blocks.Blocks(self.surface, self.cell_size) # self.potato = blocks.Blocks(self.surface, self.cell_size)
# self.potato.locate_soil('black earth', 6, 1, []) # self.potato.locate_soil('black earth', 6, 1, [])
@ -67,7 +70,7 @@ class Game:
clock = pygame.time.Clock() clock = pygame.time.Clock()
move_tractor_event = pygame.USEREVENT + 1 move_tractor_event = pygame.USEREVENT + 1
pygame.time.set_timer(move_tractor_event, 1000) # tractor moves every 1000 ms pygame.time.set_timer(move_tractor_event, 150) # tractor moves every 1000 ms
tractor_next_moves = [] tractor_next_moves = []
astar_search_object = astar_search.Search(self.cell_size, self.cell_number) astar_search_object = astar_search.Search(self.cell_size, self.cell_number)
@ -98,18 +101,20 @@ class Game:
random_x = random.randrange(0, self.cell_number * self.cell_size, 50) random_x = random.randrange(0, self.cell_number * self.cell_size, 50)
random_y = random.randrange(0, self.cell_number * self.cell_size, 50) random_y = random.randrange(0, self.cell_number * self.cell_size, 50)
print("Generated target: ",random_x, random_y) print("Generated target: ",random_x, random_y)
if self.red_block:
self.red_block.pop()
self.red_block.append([random_x/50, random_y/50])
# below line should be later moved into tractor.py # below line should be later moved into tractor.py
angles = {0: 'UP', 90: 'RIGHT', 270: 'LEFT', 180: 'DOWN'} angles = {0: 'UP', 90: 'RIGHT', 270: 'LEFT', 180: 'DOWN'}
#bandaid to know about stones #bandaid to know about stones
tractor_next_moves = astar_search_object.astarsearch( tractor_next_moves = astar_search_object.astarsearch(
[self.tractor.x, self.tractor.y, angles[self.tractor.angle]], [random_x, random_y], self.blocks.stones, self.flower_body) [self.tractor.x, self.tractor.y, angles[self.tractor.angle]], [random_x, random_y], self.stone_body, self.flower_body)
else: else:
self.tractor.move(tractor_next_moves.pop(0)[0], self.cell_size, self.cell_number) self.tractor.move(tractor_next_moves.pop(0)[0], self.cell_size, self.cell_number)
elif event.type == QUIT: elif event.type == QUIT:
running = False running = False
self.surface.fill((123, 56, 51)) # background color self.surface.fill((123, 56, 51)) # background color
self.grass.set_and_place_block_of_grass('good') self.grass.set_and_place_block_of_grass('good')
self.black_earth.place_soil(self.black_earth_body, 'black_earth') self.black_earth.place_soil(self.black_earth_body, 'black_earth')
self.green_earth.place_soil(self.green_earth_body, 'green_earth') self.green_earth.place_soil(self.green_earth_body, 'green_earth')
@ -122,6 +127,8 @@ class Game:
self.blocks.place_blocks(self.surface, self.cell_size, self.stone_body, 'stone') 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') self.blocks.place_blocks(self.surface, self.cell_size, self.flower_body, 'flower')
self.blocks.place_blocks(self.surface, self.cell_size, self.red_block, 'red')
# seeds # seeds
self.blocks.place_blocks(self.surface, self.cell_size, self.fawn_seed_body, 'fawn_seed') self.blocks.place_blocks(self.surface, self.cell_size, self.fawn_seed_body, 'fawn_seed')

BIN
resources/.DS_Store vendored Normal file

Binary file not shown.

BIN
resources/redBush.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.3 KiB