Decay rate is now accelerated by nearby food.
All checks were successful
Build Simulation and Test / Run All Tests (push) Successful in 33s

This commit is contained in:
Sam 2025-06-03 19:55:31 -05:00
parent 3a4301f7cb
commit 11bd766e62

View File

@ -90,7 +90,10 @@ class FoodObject(BaseEntity):
super().__init__(position)
self.max_visual_width: int = 10
self.decay: int = 0
self.decay_rate: int = 1
self.max_decay = 50
self.interaction_radius: int = 50
self.neighbors: int = 0
self.flags: dict[str, bool] = {
"death": False,
"can_interact": True,
@ -106,14 +109,27 @@ class FoodObject(BaseEntity):
if interactable is None:
interactable = []
self.decay += 1
self.neighbors = len(interactable)
if self.decay > 255:
self.decay = 255
if self.neighbors > 0:
self.decay += self.decay_rate * (1 + (self.neighbors / 10))
else:
self.decay += self.decay_rate
if self.decay > self.max_decay:
self.decay = self.max_decay
self.flag_for_death()
return self
def normalize_decay_to_color(self) -> int:
"""
Normalizes the decay value to a color component.
:return: Normalized decay value (0-255).
"""
return self.decay / self.max_decay * 255 if self.max_decay > 0 else 0
def render(self, camera: Any, screen: Any) -> None:
"""
Renders the food object as a decaying colored circle.
@ -124,7 +140,7 @@ class FoodObject(BaseEntity):
if camera.is_in_view(*self.position.get_position()):
pygame.draw.circle(
screen,
(255 - self.decay, food_decay_yellow(self.decay), 0),
(255 - self.normalize_decay_to_color(), food_decay_yellow(self.normalize_decay_to_color()), 0),
camera.world_to_screen(*self.position.get_position()),
int(5 * camera.zoom)
)
@ -135,4 +151,4 @@ class FoodObject(BaseEntity):
:return: String representation.
"""
return f"FoodObject({self.position}, decay={self.decay})"
return f"FoodObject({self.position}, decay={self.decay}, decay_rate={self.decay_rate * (1 + (self.neighbors / 10))})"