pub struct RespawnSystem {
pub last_checkpoint: Option<u64>,
pub respawn_count: u32,
pub activation_radius: f32,
/* private fields */
}Expand description
Tracks the active checkpoint and handles player respawning.
Call update_checkpoint periodically (e.g. when the player enters a
checkpoint trigger zone) to register the nearest checkpoint as active.
Call respawn on player death to retrieve the saved state.
Fields§
§last_checkpoint: Option<u64>The id of the last activated checkpoint, if any.
respawn_count: u32How many times the player has respawned.
activation_radius: f32The minimum distance from a checkpoint to auto-activate it.
Implementations§
Source§impl RespawnSystem
impl RespawnSystem
pub fn with_activation_radius(self, r: f32) -> Self
Sourcepub fn update_checkpoint(
&mut self,
manager: &CheckpointManager,
player_pos: Vec2,
) -> Option<u64>
pub fn update_checkpoint( &mut self, manager: &CheckpointManager, player_pos: Vec2, ) -> Option<u64>
Update the active checkpoint based on the player’s current position.
If the player is within activation_radius of any checkpoint, the nearest
one becomes the active checkpoint. Returns the id of the newly activated
checkpoint (if one was activated this call) or None.
Sourcepub fn deactivate(&mut self)
pub fn deactivate(&mut self)
Clear the active checkpoint (e.g. at the start of a level).
Sourcepub fn respawn<'a>(
&mut self,
manager: &'a CheckpointManager,
game_time: f64,
) -> Option<&'a WorldSnapshot>
pub fn respawn<'a>( &mut self, manager: &'a CheckpointManager, game_time: f64, ) -> Option<&'a WorldSnapshot>
Get the snapshot to restore on respawn.
Returns None if no checkpoint has been activated.
Sourcepub fn peek_snapshot<'a>(
&self,
manager: &'a CheckpointManager,
) -> Option<&'a WorldSnapshot>
pub fn peek_snapshot<'a>( &self, manager: &'a CheckpointManager, ) -> Option<&'a WorldSnapshot>
Get the snapshot without incrementing the respawn counter.
pub fn has_checkpoint(&self) -> bool
pub fn respawn_history(&self) -> &[RespawnEvent]
pub fn clear_history(&mut self)
Sourcepub fn checkpoint_position(&self, manager: &CheckpointManager) -> Option<Vec2>
pub fn checkpoint_position(&self, manager: &CheckpointManager) -> Option<Vec2>
The position of the active checkpoint, if any.