Poziomy jedzenia i max głodu
This commit is contained in:
parent
12c53aff35
commit
3baf0209a0
@ -30,9 +30,9 @@ class Animal:
|
|||||||
exclamation_image = pygame.transform.scale(exclamation_image, (int(grid_size * 0.45), int(grid_size * 0.45)))
|
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))
|
screen.blit(exclamation_image, (x * grid_size, y * grid_size))
|
||||||
|
|
||||||
def draw_food(self, screen, grid_size, x, y):
|
def draw_food(self, screen, grid_size, x, y,food_image):
|
||||||
scale = 0.45
|
scale = 0.45
|
||||||
food_image = pygame.image.load(self.food_image)
|
food_image = pygame.image.load(food_image)
|
||||||
|
|
||||||
if(self.adult):
|
if(self.adult):
|
||||||
y = y + 1
|
y = y + 1
|
||||||
@ -40,9 +40,6 @@ class Animal:
|
|||||||
food_image = pygame.transform.scale(food_image, (int(grid_size * scale), int(grid_size * scale)))
|
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)))
|
screen.blit(food_image, (x * grid_size, (y + 1) * grid_size - int(grid_size * scale)))
|
||||||
|
|
||||||
@abstractmethod
|
|
||||||
def feed(self):
|
|
||||||
pass
|
|
||||||
|
|
||||||
@abstractmethod
|
@abstractmethod
|
||||||
def getting_hungry(self):
|
def getting_hungry(self):
|
||||||
|
@ -41,7 +41,13 @@ def create_animals():
|
|||||||
def draw_Animals(Animals, const):
|
def draw_Animals(Animals, const):
|
||||||
for Animal in Animals:
|
for Animal in Animals:
|
||||||
Animal.draw(const.screen, const.GRID_SIZE)
|
Animal.draw(const.screen, const.GRID_SIZE)
|
||||||
if Animal.feed() == 'True':
|
if Animal.getting_hungry() == 5:
|
||||||
Animal.draw_exclamation(const.screen, const.GRID_SIZE, Animal.x, Animal.y)
|
Animal.draw_exclamation(const.screen, const.GRID_SIZE, Animal.x, Animal.y)
|
||||||
else:
|
Animal.draw_food(const.screen,const.GRID_SIZE,Animal.x,Animal.y,'images/empty_bowl.png')
|
||||||
Animal.draw_food(const.screen,const.GRID_SIZE,Animal.x,Animal.y)
|
if Animal.getting_hungry() >= 4 and Animal.getting_hungry() < 5:
|
||||||
|
Animal.draw_exclamation(const.screen, const.GRID_SIZE, Animal.x, Animal.y)
|
||||||
|
Animal.draw_food(const.screen,const.GRID_SIZE,Animal.x,Animal.y,'images/almost_empty.png')
|
||||||
|
if Animal.getting_hungry() >= 2 and Animal.getting_hungry() < 4:
|
||||||
|
Animal.draw_food(const.screen,const.GRID_SIZE,Animal.x,Animal.y,'images/half_bowl.png')
|
||||||
|
if Animal.getting_hungry() < 2:
|
||||||
|
Animal.draw_food(const.screen,const.GRID_SIZE,Animal.x,Animal.y,'images/full_bowl.png')
|
@ -14,13 +14,6 @@ class Bear(Animal):
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
def feed(self):
|
|
||||||
self.getting_hungry()
|
|
||||||
if self._feed < 2:
|
|
||||||
return 'False'
|
|
||||||
else:
|
|
||||||
return 'True'
|
|
||||||
|
|
||||||
|
|
||||||
def getting_hungry(self):
|
def getting_hungry(self):
|
||||||
checktime = datetime.now()
|
checktime = datetime.now()
|
||||||
@ -28,3 +21,6 @@ class Bear(Animal):
|
|||||||
minutes_passed = delta.total_seconds() / 60
|
minutes_passed = delta.total_seconds() / 60
|
||||||
self._feed += minutes_passed
|
self._feed += minutes_passed
|
||||||
self._starttime = checktime
|
self._starttime = checktime
|
||||||
|
if self._feed > 5:
|
||||||
|
self._feed = 5
|
||||||
|
return self._feed
|
@ -21,17 +21,12 @@ class Elephant(Animal):
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
def feed(self):
|
|
||||||
self.getting_hungry()
|
|
||||||
if self._feed < 0.3:
|
|
||||||
return 'False'
|
|
||||||
else:
|
|
||||||
return 'True'
|
|
||||||
|
|
||||||
|
|
||||||
def getting_hungry(self):
|
def getting_hungry(self):
|
||||||
checktime = datetime.now()
|
checktime = datetime.now()
|
||||||
delta = checktime - self._starttime
|
delta = checktime - self._starttime
|
||||||
minutes_passed = delta.total_seconds() / 60
|
minutes_passed = delta.total_seconds() / 50
|
||||||
self._feed += minutes_passed
|
self._feed += minutes_passed
|
||||||
self._starttime = checktime
|
self._starttime = checktime
|
||||||
|
if self._feed > 5:
|
||||||
|
self._feed = 5
|
||||||
|
return self._feed
|
@ -16,17 +16,12 @@ class Giraffe(Animal):
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
def feed(self):
|
|
||||||
self.getting_hungry()
|
|
||||||
if self._feed < 0.8:
|
|
||||||
return 'False'
|
|
||||||
else:
|
|
||||||
return 'True'
|
|
||||||
|
|
||||||
|
|
||||||
def getting_hungry(self):
|
def getting_hungry(self):
|
||||||
checktime = datetime.now()
|
checktime = datetime.now()
|
||||||
delta = checktime - self._starttime
|
delta = checktime - self._starttime
|
||||||
minutes_passed = delta.total_seconds() / 60
|
minutes_passed = delta.total_seconds() / 30
|
||||||
self._feed += minutes_passed
|
self._feed += minutes_passed
|
||||||
self._starttime = checktime
|
self._starttime = checktime
|
||||||
|
if self._feed > 5:
|
||||||
|
self._feed = 5
|
||||||
|
return self._feed
|
@ -16,17 +16,12 @@ class Parrot(Animal):
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
def feed(self):
|
|
||||||
self.getting_hungry()
|
|
||||||
if self._feed < 1.5:
|
|
||||||
return 'False'
|
|
||||||
else:
|
|
||||||
return 'True'
|
|
||||||
|
|
||||||
|
|
||||||
def getting_hungry(self):
|
def getting_hungry(self):
|
||||||
checktime = datetime.now()
|
checktime = datetime.now()
|
||||||
delta = checktime - self._starttime
|
delta = checktime - self._starttime
|
||||||
minutes_passed = delta.total_seconds() / 60
|
minutes_passed = delta.total_seconds() / 20
|
||||||
self._feed += minutes_passed
|
self._feed += minutes_passed
|
||||||
self._starttime = checktime
|
self._starttime = checktime
|
||||||
|
if self._feed > 5:
|
||||||
|
self._feed = 5
|
||||||
|
return self._feed
|
@ -16,17 +16,12 @@ class Penguin(Animal):
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
def feed(self):
|
|
||||||
self.getting_hungry()
|
|
||||||
if self._feed < 2:
|
|
||||||
return 'False'
|
|
||||||
else:
|
|
||||||
return 'True'
|
|
||||||
|
|
||||||
|
|
||||||
def getting_hungry(self):
|
def getting_hungry(self):
|
||||||
checktime = datetime.now()
|
checktime = datetime.now()
|
||||||
delta = checktime - self._starttime
|
delta = checktime - self._starttime
|
||||||
minutes_passed = delta.total_seconds() / 60
|
minutes_passed = delta.total_seconds() / 15
|
||||||
self._feed += minutes_passed
|
self._feed += minutes_passed
|
||||||
self._starttime = checktime
|
self._starttime = checktime
|
||||||
|
if self._feed > 5:
|
||||||
|
self._feed = 5
|
||||||
|
return self._feed
|
4
agent.py
4
agent.py
@ -63,7 +63,7 @@ def feed_animal(self, animals, goal):
|
|||||||
if self.x == goal_x and self.y == goal_y:
|
if self.x == goal_x and self.y == goal_y:
|
||||||
for animal in animals:
|
for animal in animals:
|
||||||
if animal.x == goal_x and animal.y == goal_y:
|
if animal.x == goal_x and animal.y == goal_y:
|
||||||
if animal._feed < self._food :
|
if animal.getting_hungry() < self._food :
|
||||||
self._food -= animal._feed
|
self._food -= animal._feed
|
||||||
animal._feed = 0
|
animal._feed = 0
|
||||||
print(animal.name, "fed with", animal.food)
|
print(animal.name, "fed with", animal.food)
|
||||||
@ -79,5 +79,5 @@ def take_food(self):
|
|||||||
house_y = 1
|
house_y = 1
|
||||||
if self.x == house_x and self.y == house_y:
|
if self.x == house_x and self.y == house_y:
|
||||||
if self._food == 0:
|
if self._food == 0:
|
||||||
self._food = 15
|
self._food = 25
|
||||||
print("Agent took food and current food level is", self._food)
|
print("Agent took food and current food level is", self._food)
|
||||||
|
BIN
images/almost_empty.png
Normal file
BIN
images/almost_empty.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 59 KiB |
BIN
images/empty_bowl.png
Normal file
BIN
images/empty_bowl.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 54 KiB |
BIN
images/full_bowl.png
Normal file
BIN
images/full_bowl.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 81 KiB |
BIN
images/half_bowl.png
Normal file
BIN
images/half_bowl.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 80 KiB |
2
main.py
2
main.py
@ -97,7 +97,7 @@ def main():
|
|||||||
spawn_obstacles()
|
spawn_obstacles()
|
||||||
cost_map = generate_cost_map(Animals, Terrain_Obstacles)
|
cost_map = generate_cost_map(Animals, Terrain_Obstacles)
|
||||||
for animal in Animals:
|
for animal in Animals:
|
||||||
animal._feed = 2 # Ustawienie, aby zwierzę było głodne
|
animal._feed = 3
|
||||||
spawned = True
|
spawned = True
|
||||||
|
|
||||||
draw_Animals(Animals, const)
|
draw_Animals(Animals, const)
|
||||||
|
Loading…
Reference in New Issue
Block a user