fixed tractor's trail and improved some visuals
This commit is contained in:
parent
0e2d63fbbf
commit
dd4f656ea2
Binary file not shown.
@ -148,29 +148,53 @@ class Tractor:
|
||||
|
||||
|
||||
def draw_tractor(self, win):
|
||||
|
||||
imageTractor = pygame.transform.scale(self.image, (TILE_SIZE, TILE_SIZE))
|
||||
win.blit(imageTractor, (self.rect.x, self.rect.y))
|
||||
pygame.display.flip()
|
||||
|
||||
|
||||
def store_tile_image(self, tile):
|
||||
return pygame.image.load(tile.image).convert_alpha()
|
||||
|
||||
def restore_tile_image(self, screen, tile):
|
||||
image = pygame.image.load(tile.image).convert_alpha()
|
||||
image = pygame.transform.scale(image, (TILE_SIZE, TILE_SIZE))
|
||||
screen.blit(image, (tile.x, tile.y))
|
||||
pygame.display.update()
|
||||
|
||||
|
||||
|
||||
#translates move_list generated by bfs into the actual movement:
|
||||
def do_actions(tractor, WIN, move_list):
|
||||
trail = pygame.image.load("resources/images/background.jpg").convert_alpha()
|
||||
trail = pygame.transform.scale(trail, (TILE_SIZE, TILE_SIZE))
|
||||
# trail = pygame.image.load("resources/images/background.jpg").convert_alpha()
|
||||
# trail = pygame.transform.scale(trail, (TILE_SIZE, TILE_SIZE))
|
||||
tile_images = {}
|
||||
for tile in tiles:
|
||||
tile_images[(tile.x, tile.y)] = tractor.store_tile_image(tile)
|
||||
|
||||
pygame.display.update()
|
||||
for move in move_list:
|
||||
WIN.blit(trail, (tractor.rect.x, tractor.rect.y, TILE_SIZE, TILE_SIZE))
|
||||
# WIN.blit(trail, (tractor.rect.x, tractor.rect.y, TILE_SIZE, TILE_SIZE))
|
||||
current_tile = None
|
||||
for tile in tiles:
|
||||
if tile.x == tractor.rect.x and tile.y == tractor.rect.y:
|
||||
current_tile = tile
|
||||
break
|
||||
if current_tile:
|
||||
tractor.restore_tile_image(WIN, current_tile)
|
||||
|
||||
if move == "move":
|
||||
tractor.move()
|
||||
elif move == "rotate_right":
|
||||
tractor.rotate_to_right()
|
||||
elif move == "rotate_left":
|
||||
tractor.rotate_to_left()
|
||||
|
||||
tractor.draw_tractor(WIN)
|
||||
pygame.display.update()
|
||||
time.sleep(0.5)
|
||||
|
||||
|
||||
#displays results of the "work_on_field" function next to the field:
|
||||
def display_work_results(screen, text, position):
|
||||
font = pygame.font.Font(None, 30)
|
||||
|
@ -26,13 +26,10 @@ pygame.display.set_caption('Intelligent tractor')
|
||||
|
||||
def main():
|
||||
run = True
|
||||
|
||||
window = drawWindow(WIN)
|
||||
pygame.display.update()
|
||||
|
||||
|
||||
|
||||
|
||||
#Tractor initialization:
|
||||
tractor = Tractor(0*TILE_SIZE, 0*TILE_SIZE, 2, None, None)
|
||||
tractor.rect.x += fieldX
|
||||
@ -75,9 +72,7 @@ def main():
|
||||
print(moves)
|
||||
|
||||
|
||||
|
||||
# movement based on route-planning:
|
||||
|
||||
tractor.draw_tractor(WIN)
|
||||
time.sleep(1)
|
||||
if moves != False:
|
||||
@ -213,9 +208,18 @@ def main():
|
||||
#work on field:
|
||||
if predykcje == 'work':
|
||||
tractor.work_on_field(WIN, goalTile, d1, p1)
|
||||
|
||||
|
||||
#update the initial state for the next target:
|
||||
istate = Istate(tile_x, tile_y, tractor.direction)
|
||||
|
||||
#old goalTile is displayed with a black border - to show that it was an old target:
|
||||
tiles[tile_index].image = "resources/images/sampling_old_goal.png"
|
||||
image = pygame.image.load(tiles[tile_index].image).convert()
|
||||
image = pygame.transform.scale(image, (TILE_SIZE, TILE_SIZE))
|
||||
WIN.blit(image, (tiles[tile_index].x, tiles[tile_index].y))
|
||||
pygame.display.flip()
|
||||
tractor.draw_tractor(WIN)
|
||||
|
||||
time.sleep(2)
|
||||
print("\n")
|
||||
|
||||
|
BIN
source/resources/images/sampling_old_goal.png
Normal file
BIN
source/resources/images/sampling_old_goal.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 77 KiB |
Loading…
Reference in New Issue
Block a user