summaryrefslogtreecommitdiff
path: root/src/game/player.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/game/player.rs')
-rw-r--r--src/game/player.rs49
1 files changed, 49 insertions, 0 deletions
diff --git a/src/game/player.rs b/src/game/player.rs
new file mode 100644
index 0000000..acfc494
--- /dev/null
+++ b/src/game/player.rs
@@ -0,0 +1,49 @@
+use arrayvec::ArrayVec;
+use crate::geometry::*;
+
+#[derive(Debug, PartialEq, Eq, Clone)]
+pub struct Player {
+ pub active_worm: usize,
+ pub worms: ArrayVec<[Worm; 3]>
+}
+
+#[derive(Debug, PartialEq, Eq, Clone)]
+pub struct Worm {
+ pub id: i32,
+ pub health: i32,
+ pub position: Point2d<i8>,
+ pub weapon_damage: i32,
+ pub weapon_range: u8
+}
+
+impl Player {
+ pub fn find_worm(&self, id: i32) -> Option<&Worm> {
+ self.worms
+ .iter()
+ .find(|w| w.id == id)
+ }
+
+ pub fn find_worm_mut(&mut self, id: i32) -> Option<&mut Worm> {
+ self.worms
+ .iter_mut()
+ .find(|w| w.id == id)
+ }
+
+ pub fn active_worm(&self) -> &Worm {
+ &self.worms[self.active_worm]
+ }
+
+ pub fn active_worm_mut(&mut self) -> &mut Worm {
+ &mut self.worms[self.active_worm]
+ }
+
+ pub fn health(&self) -> i32 {
+ self.worms
+ .iter()
+ .map(|w| w.health)
+ .sum()
+ }
+
+ // TODO: Cycle to next worm
+}
+