Struct de_objects::cannon::LaserCharge
source · pub struct LaserCharge {
charge_time: Duration,
discharge_time: Duration,
charge: f32,
}Expand description
Charge of a laser cannon. It is used to keep track of needed cannon charging time.
A laser cannon cannot fire immediately after it is activated, but takes time to charge. After firing, it has to (re)charge. It has to recharge after it any (re)activation.
Self::tick must be called during every frame. After that,
Self::hold or Self::fire must be called in a loop while
Self::charged returns true.
LaserTimer implements total ordering based on elapsed time since reaching charge for at least one fire.
Fields§
§charge_time: Duration§discharge_time: Duration§charge: f32Implementations§
source§impl LaserCharge
impl LaserCharge
sourcepub fn tick(&mut self, time_delta: Duration, charge: bool)
pub fn tick(&mut self, time_delta: Duration, charge: bool)
Updates the timer.
§Arguments
-
time_delta- time delta since last call to this method. -
charge- true if the cannon is charging, false if it is discharging.
sourcepub fn hold(&mut self)
pub fn hold(&mut self)
Clamps charge to one fire.
Must be called after Self::tick.
sourcepub fn fire(&mut self) -> bool
pub fn fire(&mut self) -> bool
Subtracts one fire worth of charge and returns true if there is charge for another fire.
Must be called after Self::tick.
Trait Implementations§
source§impl Clone for LaserCharge
impl Clone for LaserCharge
source§fn clone(&self) -> LaserCharge
fn clone(&self) -> LaserCharge
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moresource§impl Ord for LaserCharge
impl Ord for LaserCharge
source§impl PartialEq for LaserCharge
impl PartialEq for LaserCharge
source§fn eq(&self, other: &LaserCharge) -> bool
fn eq(&self, other: &LaserCharge) -> bool
self and other values to be equal, and is used
by ==.source§impl PartialOrd for LaserCharge
impl PartialOrd for LaserCharge
1.0.0 · source§fn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
self and other) and is used by the <=
operator. Read moreimpl Eq for LaserCharge
impl StructuralPartialEq for LaserCharge
Auto Trait Implementations§
impl Freeze for LaserCharge
impl RefUnwindSafe for LaserCharge
impl Send for LaserCharge
impl Sync for LaserCharge
impl Unpin for LaserCharge
impl UnwindSafe for LaserCharge
Blanket Implementations§
§impl<T, U> AsBindGroupShaderType<U> for T
impl<T, U> AsBindGroupShaderType<U> for T
§fn as_bind_group_shader_type(&self, _images: &RenderAssets<Image>) -> U
fn as_bind_group_shader_type(&self, _images: &RenderAssets<Image>) -> U
T [ShaderType] for self. When used in [AsBindGroup]
derives, it is safe to assume that all images in self exist.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
§impl<Q, K> Comparable<K> for Q
impl<Q, K> Comparable<K> for Q
§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
§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.§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.§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.§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.§impl<T> DowncastSync for T
impl<T> DowncastSync for T
§impl<T> DynEq for T
impl<T> DynEq for T
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.§impl<S> FromSample<S> for S
impl<S> FromSample<S> for S
fn from_sample_(s: S) -> S
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
source§impl<T> IntoEither for T
impl<T> IntoEither for T
source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moresource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
self from the equivalent element of its
superset. Read more§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
self is actually part of its subset T (and can be converted to it).§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
self.to_subset but without any property checks. Always succeeds.§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
self to the equivalent element of its superset.