Compare commits
No commits in common. "a1b39f2484f72c6142e5a109be614f8b068e1213" and "737d595d50665a02b4e5d56a59131cd311ce0ac1" have entirely different histories.
a1b39f2484
...
737d595d50
9
main.py
9
main.py
@ -26,7 +26,7 @@ GRID_HEIGHT = 15 # Number of cells vertically
|
|||||||
CELL_SIZE = 20 # Size of each cell in pixels
|
CELL_SIZE = 20 # Size of each cell in pixels
|
||||||
|
|
||||||
DEFAULT_TPS = 20 # Number of ticks per second for the simulation
|
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):
|
def draw_grid(screen, camera, showing_grid=True):
|
||||||
@ -150,9 +150,6 @@ def main():
|
|||||||
# sets seed to 67 >_<
|
# sets seed to 67 >_<
|
||||||
random.seed(67)
|
random.seed(67)
|
||||||
|
|
||||||
if FOOD_SPAWNING:
|
|
||||||
world.add_object(FoodObject(Position(x=random.randint(-100, 100), y=random.randint(-100, 100))))
|
|
||||||
|
|
||||||
running = True
|
running = True
|
||||||
while running:
|
while running:
|
||||||
deltatime = clock.get_time() / 1000.0 # Convert milliseconds to seconds
|
deltatime = clock.get_time() / 1000.0 # Convert milliseconds to seconds
|
||||||
@ -245,8 +242,8 @@ def main():
|
|||||||
objects = world.get_objects()
|
objects = world.get_objects()
|
||||||
food = len([obj for obj in objects if isinstance(obj, FoodObject)])
|
food = len([obj for obj in objects if isinstance(obj, FoodObject)])
|
||||||
|
|
||||||
# if food < 10 and FOOD_SPAWNING == True:
|
if food < 10 and FOOD_SPAWNING == True:
|
||||||
# world.add_object(FoodObject(Position(x=random.randint(-100, 100), y=random.randint(-100, 100))))
|
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
|
# ensure selected objects are still valid or have not changed position, if so, reselect them
|
||||||
selected_objects = [
|
selected_objects = [
|
||||||
|
|||||||
@ -1,5 +1,4 @@
|
|||||||
import random, math
|
import random
|
||||||
from multiprocessing.reduction import duplicate
|
|
||||||
|
|
||||||
from world.world import Position, BaseEntity
|
from world.world import Position, BaseEntity
|
||||||
import pygame
|
import pygame
|
||||||
@ -76,12 +75,6 @@ def food_decay_yellow(decay: int) -> int:
|
|||||||
else:
|
else:
|
||||||
return 255 - decay
|
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):
|
class FoodObject(BaseEntity):
|
||||||
"""
|
"""
|
||||||
@ -98,7 +91,7 @@ class FoodObject(BaseEntity):
|
|||||||
self.max_visual_width: int = 10
|
self.max_visual_width: int = 10
|
||||||
self.decay: int = 0
|
self.decay: int = 0
|
||||||
self.decay_rate: int = 1
|
self.decay_rate: int = 1
|
||||||
self.max_decay = 200
|
self.max_decay = 50
|
||||||
self.interaction_radius: int = 50
|
self.interaction_radius: int = 50
|
||||||
self.neighbors: int = 0
|
self.neighbors: int = 0
|
||||||
self.flags: dict[str, bool] = {
|
self.flags: dict[str, bool] = {
|
||||||
@ -127,18 +120,6 @@ class FoodObject(BaseEntity):
|
|||||||
self.decay = self.max_decay
|
self.decay = self.max_decay
|
||||||
self.flag_for_death()
|
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
|
return self
|
||||||
|
|
||||||
def normalize_decay_to_color(self) -> int:
|
def normalize_decay_to_color(self) -> int:
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user