Add tile info panel and change tractor model

This commit is contained in:
Adam Szpilkowski 2022-05-30 14:46:30 +02:00
parent e03ee28535
commit b800eec12f
17 changed files with 79 additions and 8 deletions

View File

@ -5,7 +5,7 @@
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
<excludeFolder url="file://$MODULE_DIR$/venv" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="jdk" jdkName="Python 3.10" jdkType="Python SDK" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>

View File

@ -1,4 +1,4 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectRootManager" version="2" project-jdk-name="Python 3.9 (ai-project)" project-jdk-type="Python SDK" />
<component name="ProjectRootManager" version="2" project-jdk-name="Python 3.10" project-jdk-type="Python SDK" />
</project>

Binary file not shown.

Binary file not shown.

After

Width:  |  Height:  |  Size: 29 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 165 KiB

After

Width:  |  Height:  |  Size: 12 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 154 KiB

After

Width:  |  Height:  |  Size: 11 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 154 KiB

After

Width:  |  Height:  |  Size: 11 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 147 KiB

After

Width:  |  Height:  |  Size: 13 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 165 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 154 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 154 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 147 KiB

14
main.py
View File

@ -6,8 +6,12 @@ from src.tractor import Tractor
from src.settings import Settings
from src.utils.bfs import BFSSearcher
from src.constants import Constants as C
from utils.display_info import display_tile_info
import warnings
def main():
warnings.simplefilter(action='ignore', category=FutureWarning)
pygame.init()
settings = Settings()
@ -19,6 +23,7 @@ def main():
screen = pygame.display.set_mode((settings.screen_width, settings.screen_height))
pygame.display.set_caption('TRAKTOHOLIK')
screen.blit(pygame.image.load('assets/images/display_info/img_frame.jpg'), (700, 0))
start_cords = tractor.curr_position
goals = [plant.position for plant in plants_to_water]
@ -37,6 +42,9 @@ def main():
for event in pygame.event.get():
if event.type == pygame.QUIT:
run = False
if event.type == pygame.MOUSEBUTTONDOWN:
if event.button == 1:
display_tile_info(world, screen)
if path:
action = path.pop(0)
@ -55,8 +63,8 @@ def main():
pygame.quit()
# if __name__ == '__main__':
#
if __name__ == '__main__':
main()
# # inicjalizacja array z zerami
# rows = 10
# cols = 10
@ -79,5 +87,3 @@ def main():
# goal = goals.pop(0)
# path = a_star(field, start, goal)
# print(path)
main()

View File

@ -7,7 +7,7 @@ class Settings:
self.freeze_time = 250
# Screen settings
self.screen_width = 700
self.screen_width = 910
self.screen_height = 700
# World settings

View File

@ -24,5 +24,21 @@ class Tile(Sprite):
self.rodzaj_nawozu = rodzaj_nawozu
self.to_water = to_water
def __repr__(self):
return "(type: %s, position: (%s, %s), cost: %s, rodzaj_rośliny: %s, to_water: %s)" % \
(self.type, self.row_id, self.col_id, self.cost, self.rodzaj_rosliny, self.to_water)
def get_type(self):
return self.type
def get_position(self):
return self.row_id, self.col_id
def get_cost(self):
return self.cost
def get_plant_type(self):
return self.rodzaj_rosliny
def get_to_water(self):
return self.to_water

49
src/utils/display_info.py Normal file
View File

@ -0,0 +1,49 @@
import pygame
from tile import Tile
from world import World
WHITE = (255, 255, 255)
def display_tile_info(world_map: World, screen: pygame.Surface):
# pobranie (x, y) kursora
(mx, my) = pygame.mouse.get_pos()\
# obliczenie który to tile
tile_x, tile_y = int(mx / 70), int(my / 70)
# odczytanie info z tilea
tile_info: Tile = world_map.get_tile(tile_x, 9 - tile_y)
# wyświetlenie obrazu
# 9 - y bo gdzieś w kodzie jest odwrócona oś y
screen.blit(pygame.transform.scale(tile_info.image, (140, 140)), (735, 35))
# init fonta
font = pygame.font.Font('assets/images/display_info/Minecraft.ttf', 16)
# typ tile'a
pygame.draw.rect(screen, (139, 139, 139), pygame.Rect(724, 252, 162, 23))
text_render = font.render(tile_info.get_type(), True, WHITE)
screen.blit(text_render, (731, 257))
# pozycja tile'a
pygame.draw.rect(screen, (139, 139, 139), pygame.Rect(724, 327, 162, 23))
text_render = font.render(str(tile_info.get_position()), True, WHITE)
screen.blit(text_render, (731, 332))
# koszt tile'a
pygame.draw.rect(screen, (139, 139, 139), pygame.Rect(724, 401, 162, 23))
text_render = font.render(str(tile_info.get_cost()), True, WHITE)
screen.blit(text_render, (731, 406))
# typ rośliny
pygame.draw.rect(screen, (139, 139, 139), pygame.Rect(724, 475, 162, 23))
text_render = font.render(str(tile_info.get_plant_type()), True, WHITE)
screen.blit(text_render, (731, 480))
# to water
pygame.draw.rect(screen, (139, 139, 139), pygame.Rect(724, 549, 162, 23))
text_render = font.render(str(tile_info.get_to_water()), True, WHITE)
screen.blit(text_render, (731, 554))

View File

@ -94,7 +94,7 @@ class World:
def draw_lines(self, screen):
for line in range(len(self.world_data)):
pygame.draw.line(screen, (255, 255, 255), (0, line * self.settings.tile_size),
(self.settings.screen_width, line * self.settings.tile_size))
(self.settings.screen_height - 1, line * self.settings.tile_size))
pygame.draw.line(screen, (255, 255, 255), (line * self.settings.tile_size, 0),
(line * self.settings.tile_size, self.settings.screen_height))