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)