Skip to main content

InputHandler

Struct InputHandler 

Source
pub struct InputHandler;
Expand description

InputHandler 结构体。

这是一个单元结构体,目前仅包含静态方法用于处理输入事件。 它不持有任何状态,而是直接操作传入的游戏状态变量。

Implementations§

Source§

impl InputHandler

Source

pub fn handle_mouse_down( button: MouseButton, x: f32, y: f32, shop: &mut Shop, suns: &mut Vec<Sun>, grid: &mut Grid, plants: &mut Vec<Plant>, selected_plant: &mut Option<PlantType>, sun_count: &mut i32, game_over: bool, shovel: &mut Shovel, ) -> bool

处理鼠标按下事件。

根据鼠标点击的位置和按键,执行相应的游戏操作,例如:

  • 点击阳光:收集阳光并增加阳光计数。
  • 点击商店卡片:如果阳光充足,则选择相应的植物类型以备放置。
  • 在网格上点击(已选择植物时):如果单元格未被占据且阳光充足,则放置植物。
  • 右键点击:取消当前选择的植物。
§Arguments
  • button - 按下的鼠标按键 (ggez::input::mouse::MouseButton)。
  • x - 鼠标点击的屏幕X坐标。
  • y - 鼠标点击的屏幕Y坐标。
  • shop - 可变的 Shop 引用,用于处理商店交互和更新选择状态。
  • suns - 可变的阳光实体列表 (Vec<Sun>),用于检查点击和移除被收集的阳光。
  • grid - 可变的 Grid 引用,用于检查网格位置和标记占据状态。
  • plants - 可变的植物实体列表 (Vec<Plant>),用于添加新放置的植物。
  • selected_plant - 可变的 Option<PlantType>,表示当前从商店选择的植物类型。
  • sun_count - 可变的阳光计数器 (i32)。
  • game_over - 一个布尔值,指示游戏是否已结束。如果为 true,则不处理输入。
§Returns

如果输入事件导致了游戏状态的改变(例如收集了阳光、选择了植物、放置了植物), 则返回 true,否则返回 false

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