Galactica/src/ship.rs
2023-12-25 08:46:10 -08:00

51 lines
808 B
Rust

use cgmath::Point2;
use crate::{physics::Pfloat, physics::PhysBody, render::SpriteTexture, Sprite, Spriteable};
pub enum ShipKind {
Gypsum,
}
impl ShipKind {
fn sprite(&self) -> SpriteTexture {
let name = match self {
Self::Gypsum => "ship::gypsum",
};
return SpriteTexture(name.to_owned());
}
fn size(&self) -> Pfloat {
match self {
Self::Gypsum => 100.0,
}
}
}
pub struct Ship {
pub body: PhysBody,
kind: ShipKind,
}
impl Ship {
pub fn new(kind: ShipKind, pos: Point2<Pfloat>) -> Self {
Ship {
body: PhysBody::new(pos),
kind,
}
}
}
impl Spriteable for Ship {
fn get_sprite(&self) -> Sprite {
return Sprite {
pos: self.body.pos,
texture: self.kind.sprite(),
angle: self.body.angle,
scale: 1.0,
parallax: 1.0,
size: self.kind.size(),
};
}
}