2023-12-22 17:24:53 -08:00
|
|
|
use cgmath::Point2;
|
|
|
|
|
2023-12-24 18:45:39 -08:00
|
|
|
use crate::{physics::Pfloat, physics::PhysBody, render::SpriteTexture, Sprite, Spriteable};
|
2023-12-20 19:05:12 -08:00
|
|
|
|
2023-12-21 11:26:44 -08:00
|
|
|
pub enum ShipKind {
|
|
|
|
Gypsum,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl ShipKind {
|
2023-12-24 18:45:39 -08:00
|
|
|
fn sprite(&self) -> SpriteTexture {
|
|
|
|
let name = match self {
|
2023-12-24 16:18:36 -08:00
|
|
|
Self::Gypsum => "ship::gypsum",
|
2023-12-24 18:45:39 -08:00
|
|
|
};
|
|
|
|
|
2023-12-25 08:33:31 -08:00
|
|
|
return SpriteTexture(name);
|
2023-12-21 11:26:44 -08:00
|
|
|
}
|
2023-12-23 07:21:14 -08:00
|
|
|
|
|
|
|
fn height(&self) -> Pfloat {
|
|
|
|
match self {
|
|
|
|
Self::Gypsum => 100.0,
|
|
|
|
}
|
|
|
|
}
|
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-24 18:45:39 -08:00
|
|
|
fn get_sprite(&self) -> Sprite {
|
2023-12-22 16:51:21 -08:00
|
|
|
return Sprite {
|
2023-12-22 21:39:47 -08:00
|
|
|
pos: self.body.pos,
|
2023-12-24 18:45:39 -08:00
|
|
|
texture: self.kind.sprite(),
|
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-23 23:56:10 -08:00
|
|
|
parallax: 1.0,
|
2023-12-23 07:21:14 -08:00
|
|
|
height: self.kind.height(),
|
2023-12-22 16:51:21 -08:00
|
|
|
};
|
2023-12-20 19:05:12 -08:00
|
|
|
}
|
|
|
|
}
|