heal for cash
This commit is contained in:
@@ -23,6 +23,9 @@ pub enum TriggerState {
|
||||
Inactive,
|
||||
}
|
||||
|
||||
#[derive(Event, Reflect)]
|
||||
pub struct TriggerCashHeal;
|
||||
|
||||
#[derive(Debug, Copy, Clone, PartialEq, Reflect)]
|
||||
pub enum HeadAbility {
|
||||
None,
|
||||
|
||||
24
src/cash_heal.rs
Normal file
24
src/cash_heal.rs
Normal 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);
|
||||
}
|
||||
@@ -1,5 +1,8 @@
|
||||
use crate::{
|
||||
GameState, abilities::TriggerState, backpack::BackpackAction, heads::SelectActiveHead,
|
||||
GameState,
|
||||
abilities::{TriggerCashHeal, TriggerState},
|
||||
backpack::BackpackAction,
|
||||
heads::SelectActiveHead,
|
||||
};
|
||||
use bevy::{
|
||||
input::{
|
||||
@@ -106,6 +109,9 @@ fn gamepad_controls(
|
||||
if gamepad.just_pressed(GamepadButton::DPadUp) {
|
||||
commands.trigger(BackpackAction::OpenClose);
|
||||
}
|
||||
if gamepad.just_pressed(GamepadButton::East) {
|
||||
commands.trigger(TriggerCashHeal);
|
||||
}
|
||||
|
||||
if controls
|
||||
.gamepad_state
|
||||
@@ -162,6 +168,9 @@ fn keyboard_controls(
|
||||
if keyboard.just_pressed(KeyCode::KeyE) {
|
||||
commands.trigger(SelectActiveHead::Right);
|
||||
}
|
||||
if keyboard.just_pressed(KeyCode::Enter) {
|
||||
commands.trigger(TriggerCashHeal);
|
||||
}
|
||||
|
||||
controls.keyboard_state.move_dir = direction;
|
||||
controls.keyboard_state.jump = keyboard.pressed(KeyCode::Space);
|
||||
|
||||
@@ -32,6 +32,10 @@ impl Hitpoints {
|
||||
pub fn get(&self) -> (u32, u32) {
|
||||
(self.current, self.max)
|
||||
}
|
||||
|
||||
pub fn max(&self) -> bool {
|
||||
self.current == self.max
|
||||
}
|
||||
}
|
||||
|
||||
pub fn plugin(app: &mut App) {
|
||||
|
||||
@@ -4,6 +4,7 @@ mod alien;
|
||||
mod backpack;
|
||||
mod camera;
|
||||
mod cash;
|
||||
mod cash_heal;
|
||||
mod control;
|
||||
mod cutscene;
|
||||
mod gates;
|
||||
@@ -118,6 +119,7 @@ fn main() {
|
||||
app.add_plugins(abilities::plugin);
|
||||
app.add_plugins(heads::plugin);
|
||||
app.add_plugins(hitpoints::plugin);
|
||||
app.add_plugins(cash_heal::plugin);
|
||||
|
||||
app.init_state::<GameState>();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user