use std::cell::RefCell; use std::ops::Mul; use std::rc::Rc; use std::time::Duration; use skunk2d::{Image, Vec2}; use crate::interpolator::Interpolator; use crate::unit::Unit; pub struct UnitKind { pub sprite: Rc, pub name: String, pub speed: i32, pub movement_duration: Duration } impl UnitKind { pub fn new(name: &str, speed: i32, tick_duration: Duration) -> Rc { UnitKind { sprite: Image::load(format!("assets/units/{}.gif", name).as_str()), name: name.into(), speed, movement_duration: tick_duration.mul(speed as u32) }.into() } pub fn spawn(self: Rc, pos: Vec2) -> Rc> { RefCell::new(Unit { kind: self, pos, interpolator: Interpolator::fake(), old_pos: pos, cooldown: 0 }).into() } }