Stan44 c225632aac laid out and done like most of the ground work
to reorganize the Physics Engine
so that it'll be friendly to others to read.
2024-12-31 01:50:07 -06:00

72 lines
2.9 KiB
Python

from config.settings import np, time, engine_settings
from src.physics.particle import Particle, particle_properties
class SimulationBase:
def __init__(self, width: int, height: int, x: int = 0, y: int = 0):
self.dormant_particles = set()
self.particle_movement_counter = {}
self.DORMANT_THRESHOLD = 10
self.width = width
self.height = height
self.x = x
self.y = y
self.new_x = 0
self.new_y = 0
self.particle_size = 3
self.particles = [[None for _ in range(height)] for _ in range(width)]
print(f"Base init - particles type: {type(self.particles)}")
print(f"After initialization - particles type: {type(self.particles)}")
self.active_particles = set()
self.particle_count = 0
self.brush_size = 1
self.max_brush_size = 20
self.particle_properties = particle_properties
self.particle_types = list(self.particle_properties.keys())
self.current_particle_type = self.particle_types[0] if self.particle_types else 'sand'
self.gravity = 9.8
self.wind_zones = []
self.wind = [0.0, 0.0]
def create_particle(self, x, y): # this is where we create the particle.
if engine_settings ["enable_debug"]:
print(f"Before particle creation - particles type: {type(self.particles)}")
"""Create a new particle with full property support"""
particle_type = self.current_particle_type.lower()
# Check if the particle is within the grid boundaries
if particle_type in self.particle_properties:
grid_x = x // self.particle_size
grid_y = y // self.particle_size
if (0 <= grid_x < self.width and
0 <= grid_y < self.height and
self.particles[grid_x][grid_y] is None):
properties = self.particle_properties[particle_type]
position = (grid_x, grid_y)
new_particle = Particle(
position=position,
velocity=[0, 0],
mass=properties.get('mass', 1.0),
particle_type=particle_type,
properties=properties
)
self.particles[grid_x][grid_y] = new_particle
self.active_particles.add((grid_x, grid_y))
self.particle_count += 1
def create_particle_circle(self, center_x, center_y):
brush_size = int(self.brush_size)
for dx in range(-brush_size, brush_size + 1):
for dy in range(-brush_size, brush_size + 1):
if dx*dx + dy*dy <= brush_size*brush_size: # Circle check
grid_x = (center_x + dx * self.particle_size) // self.particle_size
grid_y = (center_y + dy * self.particle_size) // self.particle_size
self.create_particle(grid_x, grid_y)