pub struct InputHandler;Expand description
InputHandler 结构体。
这是一个单元结构体,目前仅包含静态方法用于处理输入事件。 它不持有任何状态,而是直接操作传入的游戏状态变量。
Implementations§
Source§impl InputHandler
impl InputHandler
Sourcepub 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
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§
impl Freeze for InputHandler
impl RefUnwindSafe for InputHandler
impl Send for InputHandler
impl Sync for InputHandler
impl Unpin for InputHandler
impl UnsafeUnpin for InputHandler
impl UnwindSafe for InputHandler
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
Mutably borrows from an owned value. Read more
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
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>
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 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>
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