2024-03-05 14:36:03 +01:00
|
|
|
import pygame
|
|
|
|
import sys
|
2024-03-24 17:10:52 +01:00
|
|
|
import random
|
|
|
|
import time
|
2024-03-22 16:59:39 +01:00
|
|
|
from elephant import Elephant
|
2024-03-22 20:11:58 +01:00
|
|
|
from giraffe import Giraffe
|
|
|
|
from penguin import Penguin
|
|
|
|
from parrot import Parrot
|
|
|
|
from bear import Bear
|
2024-03-22 16:59:39 +01:00
|
|
|
from agent import Agent
|
2024-03-24 17:10:52 +01:00
|
|
|
from cage import Cages
|
|
|
|
|
|
|
|
# Stała bool na potrzeby debugowania
|
|
|
|
DEBUG_MODE = True
|
|
|
|
# Interwał w sekundach, po którym klatka staje się brudna
|
|
|
|
DIRTY_CAGE_INTERVAL = 1
|
2024-03-05 14:36:03 +01:00
|
|
|
|
|
|
|
BLACK = (0, 0, 0)
|
|
|
|
|
2024-03-24 17:10:52 +01:00
|
|
|
GRID_SIZE = 70
|
2024-03-05 14:36:03 +01:00
|
|
|
GRID_WIDTH = 20
|
|
|
|
GRID_HEIGHT = 10
|
|
|
|
|
|
|
|
pygame.init()
|
|
|
|
|
|
|
|
WINDOW_SIZE = (GRID_WIDTH * GRID_SIZE, GRID_HEIGHT * GRID_SIZE)
|
|
|
|
screen = pygame.display.set_mode(WINDOW_SIZE)
|
|
|
|
pygame.display.set_caption("Mini Zoo")
|
|
|
|
|
2024-03-22 16:59:39 +01:00
|
|
|
|
2024-03-05 14:36:03 +01:00
|
|
|
|
2024-03-22 20:11:58 +01:00
|
|
|
background_image = pygame.image.load('images/tło.jpg')
|
2024-03-05 14:36:03 +01:00
|
|
|
background_image = pygame.transform.scale(background_image, WINDOW_SIZE)
|
|
|
|
|
2024-03-24 17:10:52 +01:00
|
|
|
smell_icon = pygame.image.load('images/smell_icon2.png')
|
|
|
|
smell_icon = pygame.transform.scale(smell_icon, (GRID_SIZE, GRID_SIZE))
|
|
|
|
smell_icon.set_colorkey((213, 208, 126))
|
2024-03-23 13:55:16 +01:00
|
|
|
|
|
|
|
an1 = Parrot(16, 2)
|
|
|
|
an2 = Penguin(8, 6)
|
|
|
|
an3 = Bear(14, 9)
|
2024-03-22 20:11:58 +01:00
|
|
|
old_an2 = Giraffe(18,4, adult=True)
|
2024-03-23 13:55:16 +01:00
|
|
|
old_an1 = Elephant(4, 7, adult=True)
|
|
|
|
an4 = Elephant(4,3)
|
2024-03-10 17:08:39 +01:00
|
|
|
|
2024-03-23 13:55:16 +01:00
|
|
|
Animals = [an1, an2, an3, an4, old_an1, old_an2]
|
2024-03-10 17:40:26 +01:00
|
|
|
|
2024-03-05 14:36:03 +01:00
|
|
|
def draw_grid():
|
|
|
|
for y in range(0, GRID_HEIGHT * GRID_SIZE, GRID_SIZE):
|
|
|
|
for x in range(0, GRID_WIDTH * GRID_SIZE, GRID_SIZE):
|
|
|
|
rect = pygame.Rect(x, y, GRID_SIZE, GRID_SIZE)
|
|
|
|
pygame.draw.rect(screen, BLACK, rect, 1)
|
|
|
|
|
2024-03-24 17:10:52 +01:00
|
|
|
# Rysowanie obszarów klatek
|
|
|
|
if DEBUG_MODE:
|
|
|
|
for cage in Cages:
|
|
|
|
top_left = cage.top_left
|
|
|
|
bottom_right = cage.bottom_right
|
|
|
|
x1 = top_left[0] * GRID_SIZE
|
|
|
|
y1 = top_left[1] * GRID_SIZE
|
|
|
|
x2 = (bottom_right[0] + 1) * GRID_SIZE
|
|
|
|
y2 = (bottom_right[1] + 1) * GRID_SIZE
|
|
|
|
pygame.draw.rect(screen, (255, 0, 0), (x1, y1, x2 - x1, y2 - y1), 2)
|
|
|
|
|
|
|
|
|
2024-03-23 13:55:16 +01:00
|
|
|
|
2024-03-22 16:59:39 +01:00
|
|
|
|
2024-03-22 17:16:34 +01:00
|
|
|
def draw_Animals():
|
|
|
|
for Animal in Animals:
|
|
|
|
Animal.draw(screen, GRID_SIZE)
|
|
|
|
if Animal.feed() == 'True':
|
2024-03-23 13:55:16 +01:00
|
|
|
Animal.draw_exclamation(screen, GRID_SIZE, Animal.x, Animal.y)
|
|
|
|
else:
|
|
|
|
Animal.draw_food(screen,GRID_SIZE,Animal.x,Animal.y)
|
2024-03-05 14:36:03 +01:00
|
|
|
|
2024-03-24 17:10:52 +01:00
|
|
|
def generate_dirty_cage():
|
|
|
|
cage_index = random.randint(0, len(Cages) - 1)
|
|
|
|
selected_cage = Cages[cage_index]
|
|
|
|
|
|
|
|
top_left = selected_cage.top_left
|
|
|
|
bottom_right = selected_cage.bottom_right
|
|
|
|
width = bottom_right[0] - top_left[0] + 1
|
|
|
|
height = bottom_right[1] - top_left[1] + 1
|
|
|
|
x = random.randint(top_left[0], bottom_right[0])
|
|
|
|
y = random.randint(top_left[1], bottom_right[1])
|
|
|
|
|
|
|
|
if (x, y) not in selected_cage.smell_icons:
|
|
|
|
selected_cage.smell_icons.append((x, y))
|
|
|
|
|
|
|
|
def draw_dirty_cages():
|
|
|
|
for cage in Cages:
|
|
|
|
for icon_pos in cage.smell_icons:
|
|
|
|
x, y = icon_pos
|
|
|
|
screen.blit(smell_icon, (x * GRID_SIZE, y * GRID_SIZE))
|
2024-03-10 17:08:39 +01:00
|
|
|
|
2024-03-10 17:40:26 +01:00
|
|
|
|
2024-03-05 14:36:03 +01:00
|
|
|
def main():
|
2024-03-22 20:11:58 +01:00
|
|
|
agent = Agent(0, 0, 'images/avatar.png', GRID_SIZE)
|
2024-03-05 14:36:03 +01:00
|
|
|
clock = pygame.time.Clock()
|
2024-03-24 17:10:52 +01:00
|
|
|
# Timer do śledzenia pojawienia się brudnej klatki
|
|
|
|
dirty_cage_timer = time.time()
|
|
|
|
|
2024-03-05 14:36:03 +01:00
|
|
|
while True:
|
|
|
|
for event in pygame.event.get():
|
|
|
|
if event.type == pygame.QUIT:
|
|
|
|
pygame.quit()
|
|
|
|
sys.exit()
|
2024-03-24 17:10:52 +01:00
|
|
|
agent.handle_event(event,GRID_HEIGHT,GRID_WIDTH,Animals, Cages)
|
2024-03-05 14:36:03 +01:00
|
|
|
|
2024-03-24 17:10:52 +01:00
|
|
|
# Sprawdź, czy już czas na wygenerowanie brudnej klatki
|
|
|
|
if time.time() - dirty_cage_timer >= DIRTY_CAGE_INTERVAL:
|
|
|
|
generate_dirty_cage()
|
|
|
|
# Zresetuj timer
|
|
|
|
dirty_cage_timer = time.time()
|
|
|
|
for cage in Cages:
|
|
|
|
print(cage.get_cleanliness_state()) # Wyświetl stan czystości dla każdej klatki
|
2024-03-05 14:36:03 +01:00
|
|
|
|
|
|
|
screen.blit(background_image,(0,0))
|
|
|
|
draw_grid()
|
2024-03-22 17:16:34 +01:00
|
|
|
draw_Animals()
|
2024-03-24 17:10:52 +01:00
|
|
|
draw_dirty_cages()
|
2024-03-22 16:59:39 +01:00
|
|
|
|
|
|
|
|
|
|
|
agent.draw(screen)
|
2024-03-05 14:36:03 +01:00
|
|
|
pygame.display.flip()
|
|
|
|
clock.tick(10)
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
main()
|