aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLibravatar Alexander Foremny <aforemny@posteo.de>2024-03-20 06:39:46 +0100
committerLibravatar Alexander Foremny <aforemny@posteo.de>2024-03-20 06:45:22 +0100
commit716bd0618308d6100556d1231b0b156f48c64778 (patch)
tree9ba09552391330c9bcee2b71d42928234b3ec6ea
parent0165c47ea6c002c4eb177289ced5412b73273a25 (diff)
feat: scale spear damage
-rw-r--r--src/client.rs2
-rw-r--r--src/server.rs20
-rw-r--r--src/shared/ability.rs1
-rw-r--r--src/shared/projectile.rs1
4 files changed, 21 insertions, 3 deletions
diff --git a/src/client.rs b/src/client.rs
index 6d8b296..b4213a2 100644
--- a/src/client.rs
+++ b/src/client.rs
@@ -678,7 +678,7 @@ fn health_indicator_spawn(
screen_position += Vec2::new(12.5, -12.5);
commands.spawn((
TextBundle::from_section(
- format!("{health_gained_or_lost}"),
+ format!("{health_gained_or_lost:.0}"),
TextStyle {
font_size: 6.,
color: if *health_gained < 0. {
diff --git a/src/server.rs b/src/server.rs
index 1b31338..5ac07c0 100644
--- a/src/server.rs
+++ b/src/server.rs
@@ -474,12 +474,28 @@ fn projectile_despawn(
if let Some(target_player) = maybe_target_player {
if let Some(target_entity) = entity_map.0.get(&target_player.0) {
if let Ok(mut health) = healths.get_mut(*target_entity) {
- health.apply_damage(projectile.damage);
+ let damage = match projectile.type_ {
+ ProjectileType::Free(FreeProjectile {
+ position,
+ starting_position,
+ max_distance,
+ scale_damage: Some((min_multiplier, max_multiplier)),
+ ..
+ }) => {
+ let distance_traveled =
+ position.distance(starting_position) / max_distance;
+ let multiplier =
+ min_multiplier.lerp(max_multiplier, distance_traveled);
+ multiplier * projectile.damage
+ }
+ _ => projectile.damage,
+ };
+ health.apply_damage(damage);
let _ = connection_manager
.send_message_to_target::<Channel1, HealthChanged>(
HealthChanged(HealthEvent {
target_player,
- health_gained: -projectile.damage,
+ health_gained: -damage,
}),
NetworkTarget::All,
);
diff --git a/src/shared/ability.rs b/src/shared/ability.rs
index 9502151..8decfc6 100644
--- a/src/shared/ability.rs
+++ b/src/shared/ability.rs
@@ -523,6 +523,7 @@ fn spear_activation(spear: Spear) -> DirectionalAbilityActivation {
direction,
starting_position: position.0,
max_distance: spear.max_distance,
+ scale_damage: Some((0.75, 2.5)),
}),
source_player,
damage: spear.damage,
diff --git a/src/shared/projectile.rs b/src/shared/projectile.rs
index bc0a505..f9fb592 100644
--- a/src/shared/projectile.rs
+++ b/src/shared/projectile.rs
@@ -40,6 +40,7 @@ pub struct FreeProjectile {
pub direction: Vec2,
pub starting_position: Vec2,
pub max_distance: f32,
+ pub scale_damage: Option<(f32, f32)>,
}
#[derive(Component, Message, Serialize, Deserialize, Clone, Debug, PartialEq)]