From 95b2259eb4d7362b137d26037f8312b3d80f0244 Mon Sep 17 00:00:00 2001 From: Leonardo Bishop Date: Sat, 29 Jul 2023 02:55:08 +0100 Subject: Add fall damage --- .sbproj | 2 +- code/pawn/component/movement/PlayerController.cs | 12 +++++++++++- code/phase/PlayPhase.cs | 16 +++++++++++----- code/phase/WaitPhase.cs | 15 ++++++++++----- code/ui/health/Health.razor | 13 ++++++++++--- sounds/fall.sound | 12 ++++++++++++ sounds/fall.wav | Bin 0 -> 53718 bytes 7 files changed, 55 insertions(+), 15 deletions(-) create mode 100644 sounds/fall.sound create mode 100644 sounds/fall.wav diff --git a/.sbproj b/.sbproj index 6172332..2accd0b 100644 --- a/.sbproj +++ b/.sbproj @@ -1,5 +1,5 @@ { - "Title": "Murder Mystery", + "Title": "Murder", "Type": "game", "Org": "leonardobishop", "Ident": "murder", diff --git a/code/pawn/component/movement/PlayerController.cs b/code/pawn/component/movement/PlayerController.cs index 885bf84..2c9a9b9 100644 --- a/code/pawn/component/movement/PlayerController.cs +++ b/code/pawn/component/movement/PlayerController.cs @@ -36,8 +36,18 @@ public class PlayerController : EntityComponent { if ( !Grounded ) { - Entity.Velocity = Entity.Velocity.WithZ( 0 ); + var zVel = Entity.Velocity.z; AddEvent( "grounded" ); + Entity.Velocity = Entity.Velocity.WithZ( 0 ); + + if (zVel < -500) + { + var damageInfo = DamageInfo.Generic( Math.Abs((float)(zVel * 0.05)) ); + Entity.TakeDamage( damageInfo ); + Entity.PlaySound( "fall" ); + return; + } + } var sprintMultiplier = TeamOperations.CanSprint( team ) ? (Input.Down( "run" ) ? 2.5f : 1f) : 1f; diff --git a/code/phase/PlayPhase.cs b/code/phase/PlayPhase.cs index b6210b3..8b4ff7f 100644 --- a/code/phase/PlayPhase.cs +++ b/code/phase/PlayPhase.cs @@ -98,18 +98,24 @@ public class PlayPhase : BasePhase [MurderEvent.Kill] public void OnKill(Entity killer, Entity victim) { - if (killer == null || killer is not Player || victim == null || victim is not Player ) + if (killer is not Player && victim is not Player ) { return; } Player victimPlayer = (Player)victim; - Player killerPlayer = (Player)killer; - Team victimTeam = victimPlayer.CurrentTeam; - Team killerTeam = killerPlayer.CurrentTeam; - victimPlayer.CurrentTeam = Team.Spectator; + if (killer == null) + { + Log.Info( victimPlayer + " died mysteriously" ); + return; + } + + + Player killerPlayer = (Player)killer; + Team killerTeam = killerPlayer.CurrentTeam; + Log.Info( victimPlayer + " died to " + killerPlayer ); if (victimTeam != Team.Murderer && killerTeam != Team.Murderer) diff --git a/code/phase/WaitPhase.cs b/code/phase/WaitPhase.cs index 9eab094..6014467 100644 --- a/code/phase/WaitPhase.cs +++ b/code/phase/WaitPhase.cs @@ -52,21 +52,26 @@ public class WaitPhase : BasePhase pawn.Transform = tx; } - pawn.CurrentTeam = Team.Bystander; pawn.Spawn(); - pawn.Respawn(); + RespawnPlayer( pawn ); } else { var pawn = (Player)client.Pawn; - if (pawn.LifeState == LifeState.Dead) + if (pawn.LifeState == LifeState.Dead && pawn.TimeSinceDeath > 3) { - pawn.CurrentTeam = Team.Bystander; - pawn.Respawn(); + RespawnPlayer( pawn ); } } } } + private void RespawnPlayer(Player pawn) + { + pawn.CurrentTeam = Team.Spectator; + pawn.DressFromClient( pawn.Client ); + pawn.Respawn(); + } + public override void HandleClientJoin( ClientJoinedEvent e ) { diff --git a/code/ui/health/Health.razor b/code/ui/health/Health.razor index 3da2c01..c3c6660 100644 --- a/code/ui/health/Health.razor +++ b/code/ui/health/Health.razor @@ -10,12 +10,19 @@ Health { height: 100%; background-color: rgba(0, 0, 0, 0.90); } -.fill { +.colour-bar { height: 100%; - transition: width 0.2s ease-out; +} +.transition-bar { + height: 100%; + transition: width 1s ease-out 0.5s; + position: absolute; + top: 0; + left: 0; } -
+
+
@code { diff --git a/sounds/fall.sound b/sounds/fall.sound new file mode 100644 index 0000000..9d35ab9 --- /dev/null +++ b/sounds/fall.sound @@ -0,0 +1,12 @@ +{ + "UI": false, + "Volume": "1.00,1.00,0", + "Pitch": "1.00,1.00,0", + "Decibels": 70, + "SelectionMode": "Random", + "Sounds": [ + "sounds/fall.vsnd" + ], + "MaximumDistance": 1143.9335, + "MinimumDistance": 57.196674 +} \ No newline at end of file diff --git a/sounds/fall.wav b/sounds/fall.wav new file mode 100644 index 0000000..c3d5a8e Binary files /dev/null and b/sounds/fall.wav differ -- cgit v1.2.3-70-g09d2