diff options
author | Alexander Foremny <aforemny@posteo.de> | 2024-03-15 16:07:58 +0100 |
---|---|---|
committer | Alexander Foremny <aforemny@posteo.de> | 2024-03-15 16:08:00 +0100 |
commit | c71366c2e0a9f0b454957feeb87b51f6b27d54bd (patch) | |
tree | 843e35d09a27275babf4008b58ef72302c18c4ff /src/shared | |
parent | fdee6aa8cf2c51d5004d914458ff661da366e883 (diff) |
feat: add champions
Select champions using the `--champion` flag. Valid values are `ranged`
and `meele` (default).
Diffstat (limited to 'src/shared')
-rw-r--r-- | src/shared/champion.rs | 39 | ||||
-rw-r--r-- | src/shared/projectile.rs | 2 | ||||
-rw-r--r-- | src/shared/stats.rs | 16 |
3 files changed, 55 insertions, 2 deletions
diff --git a/src/shared/champion.rs b/src/shared/champion.rs new file mode 100644 index 0000000..ec27c62 --- /dev/null +++ b/src/shared/champion.rs @@ -0,0 +1,39 @@ +use crate::shared::*; +use std::str::FromStr; + +#[derive(Component, Message, Clone, Copy, Serialize, Deserialize, PartialEq, Debug)] +pub enum Champion { + Meele, + Ranged, +} + +impl Default for Champion { + fn default() -> Champion { + Champion::Meele + } +} + +impl FromStr for Champion { + type Err = String; + + fn from_str(s: &str) -> Result<Champion, String> { + match s { + "ranged" => Ok(Champion::Ranged), + "meele" => Ok(Champion::Meele), + _ => Err(format!("unknown champion: {}", s)), + } + } +} + +pub struct Stats { + pub attack_range: f32, +} + +impl Stats { + pub fn from_champion(champion: Champion) -> Self { + match champion { + Champion::Meele => Stats { attack_range: 25. }, + Champion::Ranged => Stats { attack_range: 60. }, + } + } +} diff --git a/src/shared/projectile.rs b/src/shared/projectile.rs index c42173a..2e9c6c3 100644 --- a/src/shared/projectile.rs +++ b/src/shared/projectile.rs @@ -1,7 +1,5 @@ use crate::shared::*; -pub const ATTACK_RANGE: f32 = 60.; - #[derive(Bundle)] pub struct ProjectileBundle { pub projectile: Projectile, diff --git a/src/shared/stats.rs b/src/shared/stats.rs new file mode 100644 index 0000000..278a19f --- /dev/null +++ b/src/shared/stats.rs @@ -0,0 +1,16 @@ +use crate::shared::champion::*; +use crate::shared::*; + +#[derive(Component, Message, Clone, Serialize, Deserialize, PartialEq)] +pub struct Stats { + pub attack_range: f32, +} + +impl Stats { + pub fn from_champion(champion: Champion) -> Self { + match champion { + Champion::Meele => Stats { attack_range: 35. }, + Champion::Ranged => Stats { attack_range: 60. }, + } + } +} |