use core::ops::Range;
use super::{scale::SUBPIXELS, stream::Plume, DEFAULT_LIFETIME, FULL_SCALE};
#[cfg(feature = "physics")]
use crate::physics::Wind;
use crate::{Color, Context, Direction, Graphics};
#[derive(Debug)]
pub struct Smoke<const SCALE: usize = FULL_SCALE, const LIFETIME: usize = SMOKE_LIFETIME> {
plume: Plume<SCALE, LIFETIME>,
}
impl<const SCALE: usize, const LIFETIME: usize> Smoke<SCALE, LIFETIME> {
pub const fn new(x: i16, y: i16) -> Self {
Self {
plume: Plume::new(x, y, SMOKE_SPEED, None),
}
}
pub const fn with_direction(mut self, direction: Direction) -> Self {
self.plume.set_direction(direction);
self
}
pub const fn with_puffs(mut self, puffs: usize) -> Self {
self.plume.set_puffs(puffs);
self
}
pub fn set_direction(&mut self, direction: Direction) {
self.plume.set_direction(direction);
}
pub fn set_puffing(&mut self, puffing: bool) {
self.plume.set_puffing(puffing);
}
pub fn move_to(&mut self, x: i16, y: i16) {
self.plume.move_to(x, y);
}
#[cfg(feature = "physics")]
pub fn blown_by(&mut self, wind: &Wind) {
self.plume.blown_by(wind);
}
pub fn update(&mut self, ctx: &mut Context) {
self.plume.update(ctx);
}
pub fn draw(&self, gfx: &mut Graphics) {
self.plume.draw(gfx, SMOKE_BIRTH_COLOR, &SMOKE_COLOR_STOPS);
}
}
pub const SMOKE_LIFETIME: usize = 2 * DEFAULT_LIFETIME;
const SMOKE_BIRTH_COLOR: Color = Color::WHITE;
const SMOKE_COLOR_STOPS: [(usize, Color); 2] = [(8, Color::LIGHT_GREY), (20, Color::DARK_GREY)];
const SMOKE_SPEED: Range<i32> = SUBPIXELS / 4..SUBPIXELS * 3 / 4;
#[cfg(test)]
mod tests {
use super::*;
const SMOKE: Smoke<5> = Smoke::new(3, 4)
.with_direction(Direction::Left)
.with_puffs(3);
#[test]
fn the_const_built_smoke_runs_like_any_other() {
let mut smoke = SMOKE;
let mut ctx = Context { _private: () };
smoke.update(&mut ctx);
}
}