From 9e3c34fd3e8d651a261b89bf18aba5e1a4c72a00 Mon Sep 17 00:00:00 2001 From: Sam <61994039+fourthDimensional@users.noreply.github.com> Date: Tue, 3 Jun 2025 19:29:37 -0500 Subject: [PATCH] Enable food spawning and ensure selected objects remain valid during ticks --- main.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/main.py b/main.py index 9badd55..dd1c0f7 100644 --- a/main.py +++ b/main.py @@ -26,7 +26,7 @@ GRID_HEIGHT = 15 # Number of cells vertically CELL_SIZE = 20 # Size of each cell in pixels DEFAULT_TPS = 20 # Number of ticks per second for the simulation -FOOD_SPAWNING = False +FOOD_SPAWNING = True def draw_grid(screen, camera, showing_grid=True): @@ -239,6 +239,11 @@ def main(): if food < 10 and FOOD_SPAWNING == True: world.add_object(FoodObject(Position(random.randint(-200, 200), random.randint(-200, 200)))) + # ensure selected objects are still valid or have not changed position, if so, reselect them + selected_objects = [ + obj for obj in selected_objects if obj in world.get_objects() + ] + print("Tick logic executed") world.tick_all()