2024-05-10 18:32:23 +02:00
|
|
|
import random
|
2024-03-22 16:59:39 +01:00
|
|
|
import pygame
|
2024-05-08 11:54:49 +02:00
|
|
|
from abc import abstractmethod
|
2024-03-22 16:59:39 +01:00
|
|
|
|
2024-03-10 17:08:39 +01:00
|
|
|
class Animal:
|
2024-05-10 18:32:23 +02:00
|
|
|
def __init__(self, x, y,name, image, food_image, food, environment, activity, ill=False, adult=False,):
|
2024-03-22 16:59:39 +01:00
|
|
|
self.x = x - 1
|
|
|
|
self.y = y - 1
|
2024-03-23 13:55:16 +01:00
|
|
|
self.name = name
|
2024-03-10 17:08:39 +01:00
|
|
|
self.image = image
|
2024-03-22 16:59:39 +01:00
|
|
|
self.adult = adult
|
2024-03-23 13:55:16 +01:00
|
|
|
self.food = food
|
|
|
|
self.food_image = food_image
|
2024-03-24 17:33:58 +01:00
|
|
|
self._feed = 0
|
2024-05-10 18:32:23 +02:00
|
|
|
self.environment = environment # hot/cold/medium
|
|
|
|
self.activity = activity # diurnal/nocturnal
|
|
|
|
self.ill = ill
|
2024-03-22 16:59:39 +01:00
|
|
|
|
|
|
|
def draw(self, screen, grid_size):
|
|
|
|
if self.adult:
|
2024-04-12 23:11:46 +02:00
|
|
|
# Jeśli zwierzę jest dorosłe, skaluj obrazek na większy rozmiar
|
2024-03-22 16:59:39 +01:00
|
|
|
new_width = grid_size * 2
|
|
|
|
new_height = grid_size * 2
|
|
|
|
scaled_image = pygame.transform.scale(self.image, (new_width, new_height))
|
|
|
|
screen.blit(scaled_image, (self.x * grid_size, self.y * grid_size))
|
|
|
|
else:
|
2024-04-12 23:11:46 +02:00
|
|
|
# Jeśli zwierzę nie jest dorosłe, skaluj obrazek na rozmiar jednej kratki
|
|
|
|
scaled_image = pygame.transform.scale(self.image, (grid_size, grid_size))
|
|
|
|
screen.blit(scaled_image, (self.x * grid_size, self.y * grid_size))
|
2024-03-22 16:59:39 +01:00
|
|
|
|
2024-03-23 13:55:16 +01:00
|
|
|
def draw_exclamation(self, screen, grid_size, x, y):
|
|
|
|
exclamation_image = pygame.image.load('images/exclamation.png')
|
2024-04-12 23:11:46 +02:00
|
|
|
exclamation_image = pygame.transform.scale(exclamation_image, (int(grid_size * 0.45), int(grid_size * 0.45)))
|
|
|
|
screen.blit(exclamation_image, (x * grid_size, y * grid_size))
|
2024-03-23 13:55:16 +01:00
|
|
|
|
2024-05-10 01:56:12 +02:00
|
|
|
def draw_food(self, screen, grid_size, x, y,food_image):
|
2024-04-12 23:11:46 +02:00
|
|
|
scale = 0.45
|
2024-05-10 01:56:12 +02:00
|
|
|
food_image = pygame.image.load(food_image)
|
2024-03-23 13:55:16 +01:00
|
|
|
|
2024-04-12 23:11:46 +02:00
|
|
|
if(self.adult):
|
|
|
|
y = y + 1
|
|
|
|
scale = 0.7
|
|
|
|
food_image = pygame.transform.scale(food_image, (int(grid_size * scale), int(grid_size * scale)))
|
|
|
|
screen.blit(food_image, (x * grid_size, (y + 1) * grid_size - int(grid_size * scale)))
|
2024-03-22 16:59:39 +01:00
|
|
|
|
2024-05-10 18:32:23 +02:00
|
|
|
def is_ill(self):
|
|
|
|
chance = random.randint(1, 100)
|
|
|
|
if chance >= 90:
|
|
|
|
return True
|
2024-05-12 16:25:09 +02:00
|
|
|
else: return False
|
2024-05-10 18:32:23 +02:00
|
|
|
|
|
|
|
def draw_illness(self, screen, grid_size, x, y):
|
|
|
|
scale = 0.45
|
|
|
|
illness_image = pygame.image.load('images/ill.png')
|
|
|
|
y = y
|
|
|
|
|
|
|
|
if self.adult:
|
|
|
|
x = x + 1
|
|
|
|
y = y
|
|
|
|
scale = 0.7
|
|
|
|
|
|
|
|
x_blit = x * grid_size + (grid_size - int(grid_size * scale))
|
|
|
|
illness_image = pygame.transform.scale(illness_image, (int(grid_size * scale), int(grid_size * scale)))
|
|
|
|
screen.blit(illness_image, (x_blit, y * grid_size))
|
2024-03-22 16:59:39 +01:00
|
|
|
|
|
|
|
@abstractmethod
|
|
|
|
def getting_hungry(self):
|
2024-04-12 23:11:46 +02:00
|
|
|
pass
|