2023-12-20 19:05:12 -08:00
|
|
|
use sdl2::render::Canvas;
|
|
|
|
use sdl2::video::Window;
|
|
|
|
|
|
|
|
use crate::physics::PhysBody;
|
|
|
|
use crate::physics::PhysVec;
|
2023-12-20 20:53:23 -08:00
|
|
|
use crate::physics::Position;
|
2023-12-20 19:05:12 -08:00
|
|
|
use crate::Camera;
|
|
|
|
use crate::Drawable;
|
|
|
|
use crate::ShipKind;
|
|
|
|
use crate::SpriteAtlas;
|
|
|
|
|
|
|
|
pub struct Ship {
|
|
|
|
pub body: PhysBody,
|
|
|
|
kind: ShipKind,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Ship {
|
2023-12-20 20:53:23 -08:00
|
|
|
pub fn new(kind: ShipKind, pos: Position) -> Self {
|
2023-12-20 19:05:12 -08:00
|
|
|
Ship {
|
2023-12-20 20:53:23 -08:00
|
|
|
body: PhysBody::new(pos.into()),
|
2023-12-20 19:05:12 -08:00
|
|
|
kind,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Drawable for Ship {
|
|
|
|
fn position(&self) -> PhysVec {
|
|
|
|
return self.body.pos;
|
|
|
|
}
|
|
|
|
|
|
|
|
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.kind.sprite());
|
2023-12-20 20:36:18 -08:00
|
|
|
sprite.draw(canvas, pos, self.body.angle.to_degrees(), 1.0)?;
|
2023-12-20 19:05:12 -08:00
|
|
|
return Ok(());
|
|
|
|
}
|
|
|
|
}
|