77 lines
1.9 KiB
Python
77 lines
1.9 KiB
Python
import pygame
|
|
import sys
|
|
from elephant import Elephant
|
|
from agent import Agent
|
|
|
|
BLACK = (0, 0, 0)
|
|
|
|
GRID_SIZE = 75
|
|
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")
|
|
|
|
|
|
|
|
background_image = pygame.image.load('tło.jpg')
|
|
background_image = pygame.transform.scale(background_image, WINDOW_SIZE)
|
|
|
|
exclamation_image = pygame.image.load('exclamation.png')
|
|
exclamation_image = pygame.transform.scale(exclamation_image, (GRID_SIZE,GRID_SIZE))
|
|
|
|
an1 = Elephant(10, 2)
|
|
an2 = Elephant(12, 2)
|
|
an3 = Elephant(14, 7)
|
|
|
|
old_an1 = Elephant(3, 6, adult=True)
|
|
|
|
Elephants = [an1, an2, an3,old_an1]
|
|
|
|
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_exclamation(x, y):
|
|
screen.blit(exclamation_image, (x*GRID_SIZE, y*GRID_SIZE - GRID_SIZE))
|
|
|
|
def draw_Elephants():
|
|
for Elephant in Elephants:
|
|
Elephant.draw(screen, GRID_SIZE)
|
|
if Elephant.feed() == 'True':
|
|
draw_exclamation(Elephant.x, Elephant.y)
|
|
|
|
|
|
|
|
def main():
|
|
agent = Agent(0, 0, '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,Elephants)
|
|
|
|
for Elephant in Elephants:
|
|
Elephant.getting_hungry()
|
|
|
|
screen.blit(background_image,(0,0))
|
|
draw_grid()
|
|
draw_Elephants()
|
|
|
|
|
|
|
|
agent.draw(screen)
|
|
pygame.display.flip()
|
|
clock.tick(10)
|
|
|
|
if __name__ == "__main__":
|
|
main()
|