Galactica/src/ship.rs

41 lines
635 B
Rust
Raw Normal View History

2023-12-21 11:26:44 -08:00
use crate::physics::Cartesian;
2023-12-20 19:05:12 -08:00
use crate::physics::PhysBody;
2023-12-22 16:51:21 -08:00
use crate::Camera;
use crate::Sprite;
2023-12-20 19:05:12 -08:00
2023-12-21 11:26:44 -08:00
pub enum ShipKind {
Gypsum,
}
impl ShipKind {
fn sprite(&self) -> &'static str {
match self {
2023-12-22 16:51:21 -08:00
Self::Gypsum => "gypsum",
2023-12-21 11:26:44 -08:00
}
}
}
2023-12-20 19:05:12 -08:00
pub struct Ship {
pub body: PhysBody,
kind: ShipKind,
}
impl Ship {
2023-12-21 11:26:44 -08:00
pub fn new(kind: ShipKind, pos: Cartesian) -> Self {
2023-12-20 19:05:12 -08:00
Ship {
2023-12-21 11:26:44 -08:00
body: PhysBody::new(pos),
2023-12-20 19:05:12 -08:00
kind,
}
}
2023-12-22 16:51:21 -08:00
pub fn sprite(&self, camera: &Camera) -> Sprite {
let p = self.body.pos - camera.pos;
2023-12-20 19:05:12 -08:00
2023-12-22 16:51:21 -08:00
return Sprite {
position: (p.x, p.y),
name: self.kind.sprite().to_owned(),
angle: self.body.angle as f32,
};
2023-12-20 19:05:12 -08:00
}
}