Compare commits
	
		
			5 Commits
		
	
	
		
			737d595d50
			...
			a1b39f2484
		
	
	| Author | SHA1 | Date | |
|---|---|---|---|
| a1b39f2484 | |||
| 049525ca59 | |||
| bb521371fa | |||
| 4e05a62274 | |||
| ae88bf0dd2 | 
							
								
								
									
										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 = True | FOOD_SPAWNING = False | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
| def draw_grid(screen, camera, showing_grid=True): | def draw_grid(screen, camera, showing_grid=True): | ||||||
| @ -150,6 +150,9 @@ 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 | ||||||
| @ -242,8 +245,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,4 +1,5 @@ | |||||||
| import random | import random, math | ||||||
|  | from multiprocessing.reduction import duplicate | ||||||
| 
 | 
 | ||||||
| from world.world import Position, BaseEntity | from world.world import Position, BaseEntity | ||||||
| import pygame | import pygame | ||||||
| @ -75,6 +76,12 @@ 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): | ||||||
|     """ |     """ | ||||||
| @ -91,7 +98,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 = 50 |         self.max_decay = 200 | ||||||
|         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] = { | ||||||
| @ -120,6 +127,18 @@ 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