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.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for RespawnSystem
impl RefUnwindSafe for RespawnSystem
impl Send for RespawnSystem
impl Sync for RespawnSystem
impl Unpin for RespawnSystem
impl UnsafeUnpin for RespawnSystem
impl UnwindSafe for RespawnSystem
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can
then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be
further downcast into Rc<ConcreteType> where ConcreteType implements Trait.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.