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:25:41 -05:00
parent ae88bf0dd2
commit 4e05a62274
2 changed files with 8 additions and 4 deletions

View File

@ -150,6 +150,8 @@ def main():
# sets seed to 67 >_<
random.seed(67)
world.add_object(FoodObject(Position(x=random.randint(-100, 100), y=random.randint(-100, 100))))
running = True
while running:
deltatime = clock.get_time() / 1000.0 # Convert milliseconds to seconds
@ -242,8 +244,8 @@ def main():
objects = world.get_objects()
food = len([obj for obj in objects if isinstance(obj, FoodObject)])
if food < 10 and FOOD_SPAWNING == True:
world.add_object(FoodObject(Position(x=random.randint(-100, 100), y=random.randint(-100, 100))))
# if food < 10 and FOOD_SPAWNING == True:
# world.add_object(FoodObject(Position(x=random.randint(-100, 100), y=random.randint(-100, 100))))
# ensure selected objects are still valid or have not changed position, if so, reselect them
selected_objects = [

View File

@ -111,7 +111,9 @@ class World:
# Ensure position is within world bounds, considering a center origin
if position.x < -self.world_size[0] / 2 or position.x >= self.world_size[0] / 2 or position.y < - \
self.world_size[1] / 2 or position.y >= self.world_size[1] / 2:
raise ValueError(f"Position is out of world bounds. {position} is out of bounds.")
# force position to be within bounds
position.x = max(-self.world_size[0] / 2, min(position.x, self.world_size[0] / 2 - 1))
position.y = max(-self.world_size[1] / 2, min(position.y, self.world_size[1] / 2 - 1))
return int(position.x // self.partition_size), int(position.y // self.partition_size)