Skip to content

Instantly share code, notes, and snippets.

@joereynolds
Last active October 4, 2024 12:23
Show Gist options
  • Select an option

  • Save joereynolds/abc4bafc629e1adc75438f8f23f618ba to your computer and use it in GitHub Desktop.

Select an option

Save joereynolds/abc4bafc629e1adc75438f8f23f618ba to your computer and use it in GitHub Desktop.
death_cross_particle.py
def build(x: int, y: int, level, components: dict) -> List[Particle]:
particle_width = 1
particle_height = 1
random_width_offset = random.randint(-8, 8)
random_height_offset = random.randint(-4, 4)
valid_velocities = [
[{'x': 0, 'y': 1}],
[{'x': 0, 'y': -1}],
[{'x': 1, 'y': 0}],
[{'x': -1, 'y': 0}],
[{'x': -1, 'y': -1}],
[{'x': -1, 'y': 1}],
[{'x': 1, 'y': -1}],
[{'x': 1, 'y':1}],
]
random_velocity = random.choice(valid_velocities)[0]
colour = (151, 17, 17)
ttl = random.choice([0.5, 0.75, 1, 1.25])
components = {
'frees_after_duration': {'class': FreesAfterDuration, 'kwargs': {'duration': ttl}},
'velocity': {'class': Velocity, 'kwargs': {'x': random_velocity['x'], 'y': random_velocity['y']}},
'moves': {'class': Moves, 'kwargs': {'movement_type': 'basic'}},
'speed': {'class': Speed, 'kwargs': {"speed": random.randint(2, 4)}},
}
x = x + particle_width + random_width_offset
y = y + random_height_offset
return [
Particle(
entity_id_generator.generate(),
Vector2(x, y),
particle_width,
particle_height,
colour,
components=components
),
Particle(
entity_id_generator.generate(),
Vector2(x+1, y),
particle_width,
particle_height,
colour,
components=components
),
Particle(
entity_id_generator.generate(),
Vector2(x-1, y),
particle_width,
particle_height,
colour,
components=components
),
Particle(
entity_id_generator.generate(),
Vector2(x, y-1),
particle_width,
particle_height,
colour,
components=components
),
Particle(
entity_id_generator.generate(),
Vector2(x, y+1),
particle_width,
particle_height,
colour,
components=components
),
Particle(
entity_id_generator.generate(),
Vector2(x, y+2),
particle_width,
particle_height,
colour,
components=components
)
]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment