rust-pilot/src/game/bullet.rs

34 lines
667 B
Rust

use piston_window::math::*;
const BULLET_POLY: &[[Scalar; 2]] = &[
[-1.5, -1.5],
[-1.5, 1.5],
[1.5, 1.5],
[1.5, -1.5]
];
#[derive(Debug)]
pub struct Bullet {
pub position: Vec2d,
pub velocity: Vec2d,
pub ttl: Scalar,
pub geometry: &'static [[Scalar; 2]]
}
impl Bullet {
pub fn new(position: Vec2d, velocity: Vec2d, ttl: Scalar) -> Self {
Bullet {
position,
velocity,
ttl,
geometry: BULLET_POLY
}
}
pub fn update(&mut self, dt: Scalar) -> Scalar {
self.position = add(self.position, self.velocity);
self.ttl -= dt;
self.ttl
}
}