Food now grows, the chance to graw is dependent on the decay rate. The lower the decay rate, the higher the chance to grow. This helps keep the food from growing exponentially.

This commit is contained in:
Bnenne 2025-06-03 22:20:37 -05:00
parent 56415bb07a
commit ae88bf0dd2

View File

@ -1,4 +1,5 @@
import random import random, math
from multiprocessing.reduction import duplicate
from world.world import Position, BaseEntity from world.world import Position, BaseEntity
import pygame import pygame
@ -75,6 +76,12 @@ def food_decay_yellow(decay: int) -> int:
else: else:
return 255 - decay return 255 - decay
def chance_to_grow(decay_rate):
return ((2**(-20*(decay_rate-1)))*12.5)+0.1
def chance(percent):
return random.random() < percent / 100
class FoodObject(BaseEntity): class FoodObject(BaseEntity):
""" """
@ -91,7 +98,7 @@ class FoodObject(BaseEntity):
self.max_visual_width: int = 10 self.max_visual_width: int = 10
self.decay: int = 0 self.decay: int = 0
self.decay_rate: int = 1 self.decay_rate: int = 1
self.max_decay = 50 self.max_decay = 200
self.interaction_radius: int = 50 self.interaction_radius: int = 50
self.neighbors: int = 0 self.neighbors: int = 0
self.flags: dict[str, bool] = { self.flags: dict[str, bool] = {
@ -120,6 +127,18 @@ class FoodObject(BaseEntity):
self.decay = self.max_decay self.decay = self.max_decay
self.flag_for_death() self.flag_for_death()
grow_chance = chance_to_grow(self.decay_rate * (1 + (self.neighbors / 10)))
print(grow_chance)
if chance(grow_chance):
print("Growing")
duplicate_x, duplicate_y = self.position.get_position()
duplicate_x += random.randint(-self.interaction_radius, self.interaction_radius)
duplicate_y += random.randint(-self.interaction_radius, self.interaction_radius)
return [self, FoodObject(Position(x=duplicate_x, y=duplicate_y))]
return self return self
def normalize_decay_to_color(self) -> int: def normalize_decay_to_color(self) -> int: