Male_zoo_Projekt_SI/main.py

80 lines
1.9 KiB
Python
Raw Normal View History

import pygame
import sys
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
BLACK = (0, 0, 0)
2024-03-22 20:11:58 +01:00
GRID_SIZE = 50
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-22 20:11:58 +01:00
background_image = pygame.image.load('images/tło.jpg')
background_image = pygame.transform.scale(background_image, WINDOW_SIZE)
2024-03-22 20:11:58 +01:00
exclamation_image = pygame.image.load('images/exclamation.png')
2024-03-22 16:59:39 +01:00
exclamation_image = pygame.transform.scale(exclamation_image, (GRID_SIZE,GRID_SIZE))
2024-03-22 20:11:58 +01:00
an1 = Parrot(10, 2)
an2 = Penguin(12, 2)
an3 = Bear(14, 10)
old_an2 = Giraffe(18,4, adult=True)
2024-03-22 16:59:39 +01:00
old_an1 = Elephant(3, 6, adult=True)
2024-03-22 20:11:58 +01:00
Animals = [an1, an2, an3, old_an1, old_an2]
2024-03-10 17:40:26 +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-22 16:59:39 +01:00
def draw_exclamation(x, y):
screen.blit(exclamation_image, (x*GRID_SIZE, y*GRID_SIZE - GRID_SIZE))
2024-03-22 17:16:34 +01:00
def draw_Animals():
for Animal in Animals:
Animal.draw(screen, GRID_SIZE)
if Animal.feed() == 'True':
draw_exclamation(Animal.x, Animal.y)
2024-03-10 17:40:26 +01:00
def main():
2024-03-22 20:11:58 +01:00
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()
2024-03-22 17:16:34 +01:00
agent.handle_event(event,GRID_HEIGHT,GRID_WIDTH,Animals)
2024-03-22 17:16:34 +01:00
screen.blit(background_image,(0,0))
draw_grid()
2024-03-22 17:16:34 +01:00
draw_Animals()
2024-03-22 16:59:39 +01:00
agent.draw(screen)
pygame.display.flip()
clock.tick(10)
if __name__ == "__main__":
main()