41 lines
892 B
Rust
41 lines
892 B
Rust
use crate::ShipBehavior;
|
|
use galactica_content as content;
|
|
use galactica_physics::{Physics, ShipHandle};
|
|
|
|
/// Player ship behavior.
|
|
/// Controls a ship using controller input
|
|
pub struct Player {
|
|
handle: ShipHandle,
|
|
key_left: bool,
|
|
key_right: bool,
|
|
key_guns: bool,
|
|
key_thrust: bool,
|
|
}
|
|
|
|
impl Player {
|
|
/// Make a new ship controller
|
|
pub fn new(handle: ShipHandle) -> Box<Self> {
|
|
Box::new(Self {
|
|
handle,
|
|
key_left: false,
|
|
key_right: false,
|
|
key_guns: false,
|
|
key_thrust: false,
|
|
})
|
|
}
|
|
}
|
|
|
|
impl ShipBehavior for Player {
|
|
fn update_controls(&mut self, physics: &mut Physics, _content: &content::Content) {
|
|
let s = physics.get_ship_mut(&self.handle).unwrap();
|
|
s.controls.left = self.key_left;
|
|
s.controls.right = self.key_right;
|
|
s.controls.guns = self.key_guns;
|
|
s.controls.thrust = self.key_thrust;
|
|
}
|
|
|
|
fn get_handle(&self) -> ShipHandle {
|
|
return self.handle;
|
|
}
|
|
}
|