Decay rate is now accelerated by nearby food.
All checks were successful
Build Simulation and Test / Run All Tests (push) Successful in 33s
All checks were successful
Build Simulation and Test / Run All Tests (push) Successful in 33s
This commit is contained in:
parent
3a4301f7cb
commit
11bd766e62
@ -90,7 +90,10 @@ class FoodObject(BaseEntity):
|
|||||||
super().__init__(position)
|
super().__init__(position)
|
||||||
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.max_decay = 50
|
||||||
self.interaction_radius: int = 50
|
self.interaction_radius: int = 50
|
||||||
|
self.neighbors: int = 0
|
||||||
self.flags: dict[str, bool] = {
|
self.flags: dict[str, bool] = {
|
||||||
"death": False,
|
"death": False,
|
||||||
"can_interact": True,
|
"can_interact": True,
|
||||||
@ -106,14 +109,27 @@ class FoodObject(BaseEntity):
|
|||||||
if interactable is None:
|
if interactable is None:
|
||||||
interactable = []
|
interactable = []
|
||||||
|
|
||||||
self.decay += 1
|
self.neighbors = len(interactable)
|
||||||
|
|
||||||
if self.decay > 255:
|
if self.neighbors > 0:
|
||||||
self.decay = 255
|
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()
|
self.flag_for_death()
|
||||||
|
|
||||||
return self
|
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:
|
def render(self, camera: Any, screen: Any) -> None:
|
||||||
"""
|
"""
|
||||||
Renders the food object as a decaying colored circle.
|
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()):
|
if camera.is_in_view(*self.position.get_position()):
|
||||||
pygame.draw.circle(
|
pygame.draw.circle(
|
||||||
screen,
|
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()),
|
camera.world_to_screen(*self.position.get_position()),
|
||||||
int(5 * camera.zoom)
|
int(5 * camera.zoom)
|
||||||
)
|
)
|
||||||
@ -135,4 +151,4 @@ class FoodObject(BaseEntity):
|
|||||||
|
|
||||||
:return: String representation.
|
: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))})"
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user