Skip to main content

LevelController

Struct LevelController 

Source
pub struct LevelController { /* private fields */ }
Expand description

关卡控制器结构体。

管理僵尸的生成时机、类型和波次。它实现了完整的关卡流程控制, 包括初始等待时间、波次管理、难度递增和胜利条件判定。

Implementations§

Source§

impl LevelController

Source

pub fn new() -> Self

创建一个新的 LevelController 实例。

初始化时,设置关卡开始时间为当前时间,并配置波次和生成规律。 第一波僵尸将在关卡开始后18秒出现。

§Returns

返回一个新的 LevelController 实例。

Source

pub fn is_final_wave_announced(&mut self) -> bool

获取当前是否已经宣布最后一波来袭。

当最后一波僵尸出现时,此方法将返回true,可用于在UI上显示“最后一波来袭“的通知。 注意:此方法会设置内部标记,确保只返回一次true

§Returns

如果最后一波已经开始且尚未宣布,则返回true;否则返回false

Source

pub fn is_level_completed(&self, zombies: &[Zombie]) -> bool

检查关卡是否胜利完成。

当所有波次的僵尸都已生成且场上没有活着的僵尸时,表示关卡胜利。

§Arguments
  • zombies - 当前场上所有僵尸的引用切片。
§Returns

如果满足胜利条件,则返回true;否则返回false

Source

pub fn is_wave_cleared(&self, zombies: &[Zombie]) -> bool

检查当前场上是否还有僵尸存活。

§Arguments
  • zombies - 当前场上所有僵尸的引用切片。
§Returns

如果场上没有活着的僵尸,则返回true;否则返回false

Source

pub fn update(&mut self, _dt: u64, zombies: &[Zombie]) -> Vec<ZombieSpawnInfo>

更新关卡控制器的状态,并决定是否需要生成新的僵尸。

实现了完整的波次管理逻辑:

  1. 游戏开始后18秒开始第一波
  2. 每波内生成指定数量的僵尸
  3. 波次之间有休息时间
  4. 难度随波次递增
  5. 最后一波时会标记“最后一波来袭“
§Arguments
  • _dt - 自上次更新以来的时间增量(毫秒)。
§Returns

返回一个 Vec<ZombieSpawnInfo>,其中包含所有在本次更新中需要生成的僵尸的信息。 如果不需要生成僵尸,则返回空向量。

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V