From 4e05a622749b2e10430f89f0571e4c0ef0db8898 Mon Sep 17 00:00:00 2001 From: Bnenne Date: Tue, 3 Jun 2025 22:25:41 -0500 Subject: [PATCH] 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. --- main.py | 6 ++++-- world/world.py | 6 ++++-- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/main.py b/main.py index 1485b92..b35e17d 100644 --- a/main.py +++ b/main.py @@ -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 = [ diff --git a/world/world.py b/world/world.py index 63ef11a..3469735 100644 --- a/world/world.py +++ b/world/world.py @@ -110,8 +110,10 @@ 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.") + self.world_size[1] / 2 or position.y >= self.world_size[1] / 2: + # 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)