heal for cash

This commit is contained in:
2025-04-02 11:48:59 +08:00
parent 4652bc4563
commit f74e9261d9
5 changed files with 43 additions and 1 deletions

View File

@@ -23,6 +23,9 @@ pub enum TriggerState {
Inactive, Inactive,
} }
#[derive(Event, Reflect)]
pub struct TriggerCashHeal;
#[derive(Debug, Copy, Clone, PartialEq, Reflect)] #[derive(Debug, Copy, Clone, PartialEq, Reflect)]
pub enum HeadAbility { pub enum HeadAbility {
None, None,

24
src/cash_heal.rs Normal file
View File

@@ -0,0 +1,24 @@
use crate::{abilities::TriggerCashHeal, cash::CashResource, hitpoints::Hitpoints, player::Player};
use bevy::prelude::*;
pub fn plugin(app: &mut App) {
app.add_observer(on_heal_trigger);
}
fn on_heal_trigger(
_trigger: Trigger<TriggerCashHeal>,
mut cash: ResMut<CashResource>,
mut query: Query<&mut Hitpoints, With<Player>>,
) {
let Ok(mut hp) = query.get_single_mut() else {
return;
};
if hp.max() {
return;
}
hp.set_health(100);
cash.cash = cash.cash.saturating_sub(10);
}

View File

@@ -1,5 +1,8 @@
use crate::{ use crate::{
GameState, abilities::TriggerState, backpack::BackpackAction, heads::SelectActiveHead, GameState,
abilities::{TriggerCashHeal, TriggerState},
backpack::BackpackAction,
heads::SelectActiveHead,
}; };
use bevy::{ use bevy::{
input::{ input::{
@@ -106,6 +109,9 @@ fn gamepad_controls(
if gamepad.just_pressed(GamepadButton::DPadUp) { if gamepad.just_pressed(GamepadButton::DPadUp) {
commands.trigger(BackpackAction::OpenClose); commands.trigger(BackpackAction::OpenClose);
} }
if gamepad.just_pressed(GamepadButton::East) {
commands.trigger(TriggerCashHeal);
}
if controls if controls
.gamepad_state .gamepad_state
@@ -162,6 +168,9 @@ fn keyboard_controls(
if keyboard.just_pressed(KeyCode::KeyE) { if keyboard.just_pressed(KeyCode::KeyE) {
commands.trigger(SelectActiveHead::Right); commands.trigger(SelectActiveHead::Right);
} }
if keyboard.just_pressed(KeyCode::Enter) {
commands.trigger(TriggerCashHeal);
}
controls.keyboard_state.move_dir = direction; controls.keyboard_state.move_dir = direction;
controls.keyboard_state.jump = keyboard.pressed(KeyCode::Space); controls.keyboard_state.jump = keyboard.pressed(KeyCode::Space);

View File

@@ -32,6 +32,10 @@ impl Hitpoints {
pub fn get(&self) -> (u32, u32) { pub fn get(&self) -> (u32, u32) {
(self.current, self.max) (self.current, self.max)
} }
pub fn max(&self) -> bool {
self.current == self.max
}
} }
pub fn plugin(app: &mut App) { pub fn plugin(app: &mut App) {

View File

@@ -4,6 +4,7 @@ mod alien;
mod backpack; mod backpack;
mod camera; mod camera;
mod cash; mod cash;
mod cash_heal;
mod control; mod control;
mod cutscene; mod cutscene;
mod gates; mod gates;
@@ -118,6 +119,7 @@ fn main() {
app.add_plugins(abilities::plugin); app.add_plugins(abilities::plugin);
app.add_plugins(heads::plugin); app.add_plugins(heads::plugin);
app.add_plugins(hitpoints::plugin); app.add_plugins(hitpoints::plugin);
app.add_plugins(cash_heal::plugin);
app.init_state::<GameState>(); app.init_state::<GameState>();