Galactica/src/ship.rs

46 lines
696 B
Rust
Raw Normal View History

2023-12-22 17:24:53 -08:00
use cgmath::Point2;
use crate::physics::Pfloat;
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-22 17:24:53 -08:00
use crate::Spriteable;
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-22 17:24:53 -08:00
pub fn new(kind: ShipKind, pos: Point2<Pfloat>) -> 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 17:24:53 -08:00
}
2023-12-20 19:05:12 -08:00
2023-12-22 17:24:53 -08:00
impl Spriteable for Ship {
2023-12-22 19:18:03 -08:00
fn sprite(&self, camera: Camera) -> Sprite {
2023-12-22 16:51:21 -08:00
return Sprite {
2023-12-22 17:24:53 -08:00
position: self.body.pos,
2023-12-22 19:18:03 -08:00
camera: camera,
2023-12-22 16:51:21 -08:00
name: self.kind.sprite().to_owned(),
2023-12-22 17:24:53 -08:00
angle: self.body.angle,
2023-12-22 19:18:03 -08:00
scale: 1.0,
2023-12-22 16:51:21 -08:00
};
2023-12-20 19:05:12 -08:00
}
}