2022-01-20 11:48:58 -05:00
|
|
|
use ::specs::prelude::*;
|
|
|
|
|
|
|
|
use super::{EffectSpawner, EffectType};
|
2022-01-31 11:53:38 -05:00
|
|
|
use crate::components::{ParticleAnimation, ParticleLifetime, Position, Renderable};
|
2022-01-20 11:48:58 -05:00
|
|
|
use crate::map::Map;
|
2022-02-03 09:45:29 -05:00
|
|
|
use crate::systems::particle_system::ParticleBuilder;
|
2022-01-20 11:48:58 -05:00
|
|
|
|
|
|
|
pub fn particle_to_tile(ecs: &mut World, tile_idx: i32, effect: &EffectSpawner) {
|
|
|
|
if let EffectType::Particle {
|
|
|
|
glyph,
|
|
|
|
fg,
|
|
|
|
bg,
|
|
|
|
lifespan,
|
|
|
|
} = effect.effect_type
|
|
|
|
{
|
|
|
|
let map = ecs.fetch::<Map>();
|
|
|
|
let mut particle_builder = ecs.fetch_mut::<ParticleBuilder>();
|
|
|
|
particle_builder.request(
|
|
|
|
tile_idx % map.width,
|
|
|
|
tile_idx / map.width,
|
|
|
|
fg,
|
|
|
|
bg,
|
|
|
|
glyph,
|
|
|
|
lifespan,
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
2022-01-31 11:53:38 -05:00
|
|
|
|
|
|
|
pub fn projectile(ecs: &mut World, tile_idx: i32, effect: &EffectSpawner) {
|
|
|
|
if let EffectType::ParticleProjectile {
|
|
|
|
glyph,
|
|
|
|
fg,
|
|
|
|
bg,
|
|
|
|
lifespan: _,
|
|
|
|
speed,
|
|
|
|
path,
|
|
|
|
} = &effect.effect_type
|
|
|
|
{
|
|
|
|
let x: i32;
|
|
|
|
let y: i32;
|
|
|
|
{
|
|
|
|
let map = ecs.fetch::<Map>();
|
|
|
|
x = tile_idx % map.width;
|
|
|
|
y = tile_idx / map.width;
|
|
|
|
}
|
|
|
|
|
|
|
|
ecs.create_entity()
|
|
|
|
.with(Position { x, y })
|
|
|
|
.with(Renderable {
|
|
|
|
fg: *fg,
|
|
|
|
bg: *bg,
|
|
|
|
glyph: *glyph,
|
|
|
|
render_order: 0,
|
|
|
|
})
|
|
|
|
.with(ParticleLifetime {
|
|
|
|
lifetime_ms: path.len() as f32 * speed,
|
|
|
|
animation: Some(ParticleAnimation {
|
|
|
|
step_time: *speed,
|
|
|
|
path: path.to_vec(),
|
|
|
|
current_step: 0,
|
|
|
|
timer: 0.0,
|
|
|
|
}),
|
|
|
|
})
|
|
|
|
.build();
|
|
|
|
}
|
|
|
|
}
|