simple hitpoint mechanic
This commit is contained in:
44
src/gates.rs
44
src/gates.rs
@@ -1,4 +1,4 @@
|
||||
use crate::movables::TriggerMovableEvent;
|
||||
use crate::{movables::TriggerMovableEvent, npc::KeyCollected};
|
||||
use bevy::{prelude::*, utils::hashbrown::HashSet};
|
||||
|
||||
#[derive(Resource)]
|
||||
@@ -9,36 +9,34 @@ enum GatesState {
|
||||
|
||||
pub fn plugin(app: &mut App) {
|
||||
app.insert_resource(GatesState::Init);
|
||||
app.add_systems(Update, update);
|
||||
app.add_observer(on_key);
|
||||
}
|
||||
|
||||
fn update(
|
||||
fn on_key(
|
||||
_trigger: Trigger<KeyCollected>,
|
||||
mut commands: Commands,
|
||||
keyboard: Res<ButtonInput<KeyCode>>,
|
||||
mut state: ResMut<GatesState>,
|
||||
asset_server: Res<AssetServer>,
|
||||
) {
|
||||
if keyboard.just_pressed(KeyCode::Digit1) {
|
||||
if matches!(*state, GatesState::Init) {
|
||||
*state = GatesState::GateOpen1;
|
||||
if matches!(*state, GatesState::Init) {
|
||||
*state = GatesState::GateOpen1;
|
||||
|
||||
//TODO: put into a sound effects system
|
||||
commands.spawn((
|
||||
AudioPlayer::new(asset_server.load("sfx/effects/gate.ogg")),
|
||||
PlaybackSettings::DESPAWN,
|
||||
));
|
||||
//TODO: put into actual key collect once we have that
|
||||
commands.spawn((
|
||||
AudioPlayer::new(asset_server.load("sfx/effects/key_collect.ogg")),
|
||||
PlaybackSettings::DESPAWN,
|
||||
));
|
||||
//TODO: put into a sound effects system
|
||||
commands.spawn((
|
||||
AudioPlayer::new(asset_server.load("sfx/effects/gate.ogg")),
|
||||
PlaybackSettings::DESPAWN,
|
||||
));
|
||||
//TODO: put into actual key collect once we have that
|
||||
commands.spawn((
|
||||
AudioPlayer::new(asset_server.load("sfx/effects/key_collect.ogg")),
|
||||
PlaybackSettings::DESPAWN,
|
||||
));
|
||||
|
||||
let entities: HashSet<_> = vec!["fence_01", "fence_02"]
|
||||
.into_iter()
|
||||
.map(|s| String::from(s))
|
||||
.collect();
|
||||
let entities: HashSet<_> = vec!["fence_01", "fence_02"]
|
||||
.into_iter()
|
||||
.map(|s| String::from(s))
|
||||
.collect();
|
||||
|
||||
commands.trigger(TriggerMovableEvent(entities));
|
||||
}
|
||||
commands.trigger(TriggerMovableEvent(entities));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user