Compare commits

..

5 Commits

2 changed files with 27 additions and 5 deletions

View File

@ -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 = True
FOOD_SPAWNING = False
def draw_grid(screen, camera, showing_grid=True):
@ -150,6 +150,9 @@ def main():
# sets seed to 67 >_<
random.seed(67)
if FOOD_SPAWNING:
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 +245,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

@ -1,4 +1,5 @@
import random
import random, math
from multiprocessing.reduction import duplicate
from world.world import Position, BaseEntity
import pygame
@ -75,6 +76,12 @@ def food_decay_yellow(decay: int) -> int:
else:
return 255 - decay
def chance_to_grow(decay_rate):
return ((2**(-20*(decay_rate-1)))*12.5)+0.1
def chance(percent):
return random.random() < percent / 100
class FoodObject(BaseEntity):
"""
@ -91,7 +98,7 @@ class FoodObject(BaseEntity):
self.max_visual_width: int = 10
self.decay: int = 0
self.decay_rate: int = 1
self.max_decay = 50
self.max_decay = 200
self.interaction_radius: int = 50
self.neighbors: int = 0
self.flags: dict[str, bool] = {
@ -120,6 +127,18 @@ class FoodObject(BaseEntity):
self.decay = self.max_decay
self.flag_for_death()
grow_chance = chance_to_grow(self.decay_rate * (1 + (self.neighbors / 10)))
# print(grow_chance)
if chance(grow_chance):
# print("Growing")
duplicate_x, duplicate_y = self.position.get_position()
duplicate_x += random.randint(-self.interaction_radius, self.interaction_radius)
duplicate_y += random.randint(-self.interaction_radius, self.interaction_radius)
return [self, FoodObject(Position(x=duplicate_x, y=duplicate_y))]
return self
def normalize_decay_to_color(self) -> int: