Galactica/src/game/ship.rs

53 lines
888 B
Rust
Raw Normal View History

2023-12-22 17:24:53 -08:00
use cgmath::Point2;
2023-12-25 11:17:08 -08:00
use crate::{
2023-12-25 16:21:14 -08:00
physics::Pfloat, physics::PhysicsBody, render::Sprite, render::SpriteTexture,
render::Spriteable,
2023-12-25 11:17:08 -08:00
};
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:35:34 -08:00
return SpriteTexture(name.to_owned());
2023-12-21 11:26:44 -08:00
}
2023-12-23 07:21:14 -08:00
2023-12-25 08:46:10 -08:00
fn size(&self) -> Pfloat {
2023-12-23 07:21:14 -08:00
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 {
2023-12-25 16:21:14 -08:00
pub physicsbody: PhysicsBody,
2023-12-20 19:05:12 -08:00
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-25 16:21:14 -08:00
physicsbody: PhysicsBody::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-25 16:21:14 -08:00
pos: (self.physicsbody.pos.x, self.physicsbody.pos.y, 1.0).into(),
2023-12-24 18:45:39 -08:00
texture: self.kind.sprite(),
2023-12-25 16:21:14 -08:00
angle: self.physicsbody.angle,
2023-12-22 19:18:03 -08:00
scale: 1.0,
2023-12-25 08:46:10 -08:00
size: self.kind.size(),
2023-12-22 16:51:21 -08:00
};
2023-12-20 19:05:12 -08:00
}
}