2023-12-20 19:05:12 -08:00
|
|
|
use sdl2::render::Canvas;
|
|
|
|
use sdl2::video::Window;
|
|
|
|
|
|
|
|
use crate::physics::PhysVec;
|
2023-12-20 20:06:54 -08:00
|
|
|
use crate::physics::Position;
|
2023-12-20 19:05:12 -08:00
|
|
|
use crate::Camera;
|
|
|
|
use crate::Drawable;
|
|
|
|
use crate::SpriteAtlas;
|
|
|
|
|
|
|
|
pub struct Doodad {
|
2023-12-20 20:06:54 -08:00
|
|
|
pub sprite: String,
|
|
|
|
pub pos: Position,
|
|
|
|
pub scale: u32,
|
|
|
|
pub angle: f64,
|
2023-12-20 19:05:12 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
impl Drawable for Doodad {
|
|
|
|
fn position(&self) -> PhysVec {
|
2023-12-20 20:06:54 -08:00
|
|
|
self.pos.to_cartesian().into()
|
2023-12-20 19:05:12 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
fn draw(
|
|
|
|
&self,
|
|
|
|
canvas: &mut Canvas<Window>,
|
|
|
|
sa: &SpriteAtlas,
|
|
|
|
c: &Camera,
|
|
|
|
) -> Result<(), String> {
|
2023-12-20 20:31:09 -08:00
|
|
|
let pos = self.screen_position(canvas, c);
|
2023-12-20 19:05:12 -08:00
|
|
|
let sprite = sa.get(&self.sprite);
|
2023-12-20 20:36:18 -08:00
|
|
|
sprite.draw(canvas, pos, self.angle, 1.0)?;
|
2023-12-20 19:05:12 -08:00
|
|
|
return Ok(());
|
|
|
|
}
|
|
|
|
}
|