Male_zoo_Projekt_SI/main.py

100 lines
2.4 KiB
Python

import pygame
import sys
from elephant import Elephant
from giraffe import Giraffe
from penguin import Penguin
from parrot import Parrot
from bear import Bear
from agent import Agent
from enclosure import Enclosure
BLACK = (0, 0, 0)
GRID_SIZE = 50
GRID_WIDTH = 30
GRID_HEIGHT = 15
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")
background_image = pygame.image.load('images/tło.jpg')
background_image = pygame.transform.scale(background_image, WINDOW_SIZE)
fenceH = pygame.image.load('images/fenceHor.png')
fenceV = pygame.image.load('images/fenceVer.png')
blocked = set()
an1 = Parrot(16, 2)
an2 = Penguin(8, 6)
an3 = Bear(14, 9)
old_an2 = Giraffe(18,4, adult=True)
old_an1 = Elephant(4, 7, adult=True)
an4 = Elephant(4,3)
Animals = [an1, an2, an3, an4, old_an1, old_an2]
en1 = Enclosure(1,5,9,11,"medium", fenceH, fenceV)
en2 = Enclosure(29,3, 13,1, 'medium', fenceH, fenceV)
en3 = Enclosure(11,5, 16,11, 'cold', fenceH, fenceV)
en4 = Enclosure(19,11, 30,5, 'hot', fenceH, fenceV)
en5 = Enclosure(4,13, 28,15, 'cold', fenceH, fenceV)
Enclosures = [en1, en2, en3, en4, en5]
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)
def draw_enclosures(set):
for enclosure in Enclosures:
enclosure.draw(screen, GRID_SIZE, blocked)
def draw_Animals():
for Animal in Animals:
Animal.draw(screen, GRID_SIZE)
if Animal.feed() == 'True':
Animal.draw_exclamation(screen, GRID_SIZE, Animal.x, Animal.y)
else:
Animal.draw_food(screen,GRID_SIZE,Animal.x,Animal.y)
def main():
agent = Agent(0, 0, 'images/avatar.png', GRID_SIZE)
clock = pygame.time.Clock()
while True:
for event in pygame.event.get():
if event.type == pygame.QUIT:
pygame.quit()
sys.exit()
agent.handle_event(event,GRID_HEIGHT,GRID_WIDTH,Animals, blocked)
screen.blit(background_image,(0,0))
draw_grid()
draw_enclosures(blocked)
#draw_Animals()
agent.draw(screen)
pygame.display.flip()
clock.tick(10)
if __name__ == "__main__":
main()