diff --git a/.idea/ai-project.iml b/.idea/ai-project.iml index 0c80114..a23e703 100644 --- a/.idea/ai-project.iml +++ b/.idea/ai-project.iml @@ -5,7 +5,7 @@ - + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml index 3fc3916..dc9ea49 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -1,4 +1,4 @@ - + \ No newline at end of file diff --git a/assets/images/display_info/Minecraft.ttf b/assets/images/display_info/Minecraft.ttf new file mode 100644 index 0000000..85c1472 Binary files /dev/null and b/assets/images/display_info/Minecraft.ttf differ diff --git a/assets/images/display_info/img_frame.jpg b/assets/images/display_info/img_frame.jpg new file mode 100644 index 0000000..fd1a27b Binary files /dev/null and b/assets/images/display_info/img_frame.jpg differ diff --git a/assets/images/tractor/tractor-transparent-down.png b/assets/images/tractor/tractor-transparent-down.png index 4909d15..7520505 100644 Binary files a/assets/images/tractor/tractor-transparent-down.png and b/assets/images/tractor/tractor-transparent-down.png differ diff --git a/assets/images/tractor/tractor-transparent-left.png b/assets/images/tractor/tractor-transparent-left.png index 1644f7e..55bd02f 100644 Binary files a/assets/images/tractor/tractor-transparent-left.png and b/assets/images/tractor/tractor-transparent-left.png differ diff --git a/assets/images/tractor/tractor-transparent-right.png b/assets/images/tractor/tractor-transparent-right.png index 9648052..c45c6af 100644 Binary files a/assets/images/tractor/tractor-transparent-right.png and b/assets/images/tractor/tractor-transparent-right.png differ diff --git a/assets/images/tractor/tractor-transparent-up.png b/assets/images/tractor/tractor-transparent-up.png index df18ed4..8fc3875 100644 Binary files a/assets/images/tractor/tractor-transparent-up.png and b/assets/images/tractor/tractor-transparent-up.png differ diff --git a/assets/images/tractor_old/tractor-transparent-down.png b/assets/images/tractor_old/tractor-transparent-down.png new file mode 100644 index 0000000..4909d15 Binary files /dev/null and b/assets/images/tractor_old/tractor-transparent-down.png differ diff --git a/assets/images/tractor_old/tractor-transparent-left.png b/assets/images/tractor_old/tractor-transparent-left.png new file mode 100644 index 0000000..1644f7e Binary files /dev/null and b/assets/images/tractor_old/tractor-transparent-left.png differ diff --git a/assets/images/tractor_old/tractor-transparent-right.png b/assets/images/tractor_old/tractor-transparent-right.png new file mode 100644 index 0000000..9648052 Binary files /dev/null and b/assets/images/tractor_old/tractor-transparent-right.png differ diff --git a/assets/images/tractor_old/tractor-transparent-up.png b/assets/images/tractor_old/tractor-transparent-up.png new file mode 100644 index 0000000..df18ed4 Binary files /dev/null and b/assets/images/tractor_old/tractor-transparent-up.png differ diff --git a/main.py b/main.py index f9bcc00..d822bd5 100644 --- a/main.py +++ b/main.py @@ -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() \ No newline at end of file diff --git a/src/settings.py b/src/settings.py index 34c1140..3423af3 100644 --- a/src/settings.py +++ b/src/settings.py @@ -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 diff --git a/src/tile.py b/src/tile.py index 83f806b..3a13730 100644 --- a/src/tile.py +++ b/src/tile.py @@ -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 \ No newline at end of file diff --git a/src/utils/display_info.py b/src/utils/display_info.py new file mode 100644 index 0000000..adf31d3 --- /dev/null +++ b/src/utils/display_info.py @@ -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)) diff --git a/src/world.py b/src/world.py index a7831ac..872b7f0 100644 --- a/src/world.py +++ b/src/world.py @@ -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))