dorosłe osobniki

This commit is contained in:
LuminoX 2024-03-10 17:40:26 +01:00
parent c46e523488
commit 82b2060409
2 changed files with 27 additions and 0 deletions

16
adult_animal.py Normal file
View File

@ -0,0 +1,16 @@
import pygame
from animal import Animal
class AdultAnimal(Animal):
def __init__(self,x,y,image, width=2,height=2):
super().__init__(x,y,image)
self.width=width
self.height=height
def draw(self, screen, grid_size):
new_width = grid_size * self.width
new_height = grid_size * self.height
scaled_image = pygame.transform.scale(self.image, (new_width, new_height))
screen.blit(scaled_image, (self.x * grid_size, self.y * grid_size))

11
main.py
View File

@ -1,6 +1,7 @@
import pygame
import sys
from animal import Animal
from adult_animal import AdultAnimal
BLACK = (0, 0, 0)
@ -28,11 +29,16 @@ an1=Animal(10,1,animal_image)
an2=Animal(12,1,animal_image)
an3=Animal(14,7,animal_image)
old_an1=AdultAnimal(3,6, animal_image,width=2,height=2)
animals=[]
animals.append(an1)
animals.append(an2)
animals.append(an3)
old_animals=[]
old_animals.append(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):
@ -47,6 +53,10 @@ def draw_animals():
for animal in animals:
animal.draw(screen,GRID_SIZE)
def draw_old_animals():
for animal in old_animals:
animal.draw(screen,GRID_SIZE)
def main():
global agent_pos
clock = pygame.time.Clock()
@ -70,6 +80,7 @@ def main():
screen.blit(background_image,(0,0))
draw_grid()
draw_animals()
draw_old_animals()
draw_agent(agent_pos)
pygame.display.flip()
clock.tick(10)