Poprawione wyświetlanie jedzenia i wykrzykników

This commit is contained in:
karolajoj 2024-04-12 23:11:46 +02:00
parent ff27920f3d
commit 5747db6aab
12 changed files with 17 additions and 15 deletions

View File

@ -1,7 +1,6 @@
import pygame import pygame
from abc import ABC, abstractmethod from abc import ABC, abstractmethod
class Animal: class Animal:
def __init__(self, x, y,name, image, food_image, food, environment, adult=False,): def __init__(self, x, y,name, image, food_image, food, environment, adult=False,):
self.x = x - 1 self.x = x - 1
@ -15,29 +14,31 @@ class Animal:
self.environment = environment #hot/cold/medium self.environment = environment #hot/cold/medium
def draw(self, screen, grid_size): def draw(self, screen, grid_size):
self.image = pygame.transform.scale(self.image, (grid_size, grid_size))
if self.adult: if self.adult:
# If adult, draw like AdultAnimal # Jeśli zwierzę jest dorosłe, skaluj obrazek na większy rozmiar
new_width = grid_size * 2 new_width = grid_size * 2
new_height = grid_size * 2 new_height = grid_size * 2
scaled_image = pygame.transform.scale(self.image, (new_width, new_height)) scaled_image = pygame.transform.scale(self.image, (new_width, new_height))
screen.blit(scaled_image, (self.x * grid_size, self.y * grid_size)) screen.blit(scaled_image, (self.x * grid_size, self.y * grid_size))
else: else:
# If not adult, draw like normal Animal # Jeśli zwierzę nie jest dorosłe, skaluj obrazek na rozmiar jednej kratki
screen.blit(self.image, (self.x * grid_size, self.y * grid_size)) scaled_image = pygame.transform.scale(self.image, (grid_size, grid_size))
screen.blit(scaled_image, (self.x * grid_size, self.y * grid_size))
def draw_exclamation(self, screen, grid_size, x, y): def draw_exclamation(self, screen, grid_size, x, y):
exclamation_image = pygame.image.load('images/exclamation.png') exclamation_image = pygame.image.load('images/exclamation.png')
exclamation_image = pygame.transform.scale(exclamation_image, (grid_size,grid_size)) exclamation_image = pygame.transform.scale(exclamation_image, (int(grid_size * 0.45), int(grid_size * 0.45)))
screen.blit(exclamation_image, (x*grid_size, y*grid_size - grid_size)) screen.blit(exclamation_image, (x * grid_size, y * grid_size))
def draw_food(self, screen, grid_size, x, y): def draw_food(self, screen, grid_size, x, y):
scale = 0.45
food_image = pygame.image.load(self.food_image) food_image = pygame.image.load(self.food_image)
food_image = pygame.transform.scale(food_image, (grid_size,grid_size))
screen.blit(food_image, (x*grid_size, y*grid_size + grid_size))
if(self.adult):
y = y + 1
scale = 0.7
food_image = pygame.transform.scale(food_image, (int(grid_size * scale), int(grid_size * scale)))
screen.blit(food_image, (x * grid_size, (y + 1) * grid_size - int(grid_size * scale)))
@abstractmethod @abstractmethod
def feed(self): def feed(self):

Binary file not shown.

Before

Width:  |  Height:  |  Size: 133 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 248 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.9 MiB

After

Width:  |  Height:  |  Size: 2.3 MiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 63 KiB

After

Width:  |  Height:  |  Size: 64 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 934 KiB

After

Width:  |  Height:  |  Size: 601 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 256 KiB

After

Width:  |  Height:  |  Size: 444 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 186 KiB

After

Width:  |  Height:  |  Size: 232 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 288 KiB

After

Width:  |  Height:  |  Size: 460 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.5 MiB

After

Width:  |  Height:  |  Size: 1.7 MiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.1 MiB

After

Width:  |  Height:  |  Size: 2.4 MiB

View File

@ -13,7 +13,7 @@ from state_space_search import graphsearch
BLACK = (0, 0, 0) BLACK = (0, 0, 0)
GRID_SIZE = 50 GRID_SIZE = 64
GRID_WIDTH = 30 GRID_WIDTH = 30
GRID_HEIGHT = 15 GRID_HEIGHT = 15
@ -177,9 +177,10 @@ def main():
spawn_all_animals() spawn_all_animals()
# region Test szukania ścieżki # region Test szukania ścieżki
animal = random.choice(Animals) for animal in Animals:
actions = graphsearch(agent.istate, (animal.x, animal.y), GRID_WIDTH, GRID_HEIGHT, obstacles)
animal._feed = 2 # Ustawienie aby zwierzę było głodne animal._feed = 2 # Ustawienie aby zwierzę było głodne
animal = random.choice(Animals)
# actions = graphsearch(agent.istate, (animal.x, animal.y), GRID_WIDTH, GRID_HEIGHT, obstacles)
# endregion # endregion
spawned = True spawned = True