diff options
| author | Leonardo Bishop <me@leonardobishop.com> | 2023-07-29 02:55:08 +0100 |
|---|---|---|
| committer | Leonardo Bishop <me@leonardobishop.com> | 2023-07-29 02:55:08 +0100 |
| commit | 95b2259eb4d7362b137d26037f8312b3d80f0244 (patch) | |
| tree | 430f4b61bba71e93802d0edaf61f97a162627666 /code | |
| parent | 743c93752eccb4d243c5869ec82dceb1c443acac (diff) | |
Add fall damage
Diffstat (limited to 'code')
| -rw-r--r-- | code/pawn/component/movement/PlayerController.cs | 12 | ||||
| -rw-r--r-- | code/phase/PlayPhase.cs | 16 | ||||
| -rw-r--r-- | code/phase/WaitPhase.cs | 15 | ||||
| -rw-r--r-- | code/ui/health/Health.razor | 13 |
4 files changed, 42 insertions, 14 deletions
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<Player> {
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;
}
</style>
-<div class="fill" style="background-color: @(Colour); width: @(GetHealth())%;"></div>
+<div class="transition-bar" style="background-color: white; width: @(GetHealth())%;"></div>
+<div class="colour-bar" style="background-color: @(Colour); width: @(GetHealth())%;"></div>
@code
{
|
