allow switching heads in slots and fix heads
This commit is contained in:
@@ -996,7 +996,7 @@
|
||||
"classname" "enemy_spawn"
|
||||
"origin" "2568 4504 -232"
|
||||
"angles" "0 180 0"
|
||||
"head" "supermarket shopper"
|
||||
"head" "super market shopper"
|
||||
}
|
||||
// entity 24
|
||||
{
|
||||
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
|
Before Width: | Height: | Size: 10 KiB After Width: | Height: | Size: 10 KiB |
@@ -1,5 +1,7 @@
|
||||
use bevy::prelude::*;
|
||||
|
||||
use crate::player::head_id_to_str;
|
||||
|
||||
#[derive(Event, Reflect)]
|
||||
pub enum SwapHead {
|
||||
Left,
|
||||
@@ -35,7 +37,7 @@ pub struct HeadChanged(pub usize);
|
||||
pub fn plugin(app: &mut App) {
|
||||
app.register_type::<HeadDamage>();
|
||||
app.add_systems(Startup, setup);
|
||||
app.add_systems(Update, update);
|
||||
app.add_systems(Update, (update, swap_head_test));
|
||||
app.add_observer(on_swap_head);
|
||||
}
|
||||
|
||||
@@ -66,18 +68,15 @@ fn setup(mut commands: Commands, asset_server: Res<AssetServer>) {
|
||||
}
|
||||
});
|
||||
|
||||
let head_01 = asset_server.load("ui/heads/angry demonstrator.png");
|
||||
let head_02 = asset_server.load("ui/heads/commando.png");
|
||||
let head_03 = asset_server.load("ui/heads/goblin.png");
|
||||
let head_04 = asset_server.load("ui/heads/highland hammer thrower.png");
|
||||
let head_05 = asset_server.load("ui/heads/legionnaire.png");
|
||||
let heads = (0usize..18)
|
||||
.into_iter()
|
||||
.map(|i| asset_server.load(format!("ui/heads/{}.png", head_id_to_str(i))))
|
||||
.collect();
|
||||
|
||||
commands.insert_resource(HeadsImages {
|
||||
heads: vec![head_01, head_02, head_03, head_04, head_05],
|
||||
});
|
||||
commands.insert_resource(HeadsImages { heads });
|
||||
|
||||
commands.insert_resource(ActiveHeads {
|
||||
heads: [Some(0), Some(1), Some(2), Some(3), Some(4)],
|
||||
heads: [Some(0), Some(3), Some(6), Some(8), Some(9)],
|
||||
current_slot: 0,
|
||||
});
|
||||
}
|
||||
@@ -163,6 +162,25 @@ fn spawn_head_ui(
|
||||
});
|
||||
}
|
||||
|
||||
fn swap_head_test(
|
||||
mut commands: Commands,
|
||||
mut active: ResMut<ActiveHeads>,
|
||||
keyboard: Res<ButtonInput<KeyCode>>,
|
||||
) {
|
||||
if keyboard.just_pressed(KeyCode::Comma) {
|
||||
let slot = active.current_slot;
|
||||
let current = active.heads[active.current_slot].unwrap();
|
||||
active.heads[slot] = Some((current + 17) % 18);
|
||||
commands.trigger(HeadChanged(active.heads[slot].unwrap()));
|
||||
}
|
||||
if keyboard.just_pressed(KeyCode::Period) {
|
||||
let slot = active.current_slot;
|
||||
let current = active.heads[active.current_slot].unwrap();
|
||||
active.heads[slot] = Some((current + 1) % 18);
|
||||
commands.trigger(HeadChanged(active.heads[slot].unwrap()));
|
||||
}
|
||||
}
|
||||
|
||||
fn update(
|
||||
res: Res<ActiveHeads>,
|
||||
heads_images: Res<HeadsImages>,
|
||||
|
||||
@@ -257,13 +257,7 @@ fn update_head(
|
||||
return;
|
||||
};
|
||||
|
||||
let head_str = match trigger.0 {
|
||||
0 => "angry demonstrator",
|
||||
1 => "commando",
|
||||
2 => "goblin",
|
||||
3 => "highland hammer thrower",
|
||||
_ => "legionnaire",
|
||||
};
|
||||
let head_str = head_id_to_str(trigger.0);
|
||||
|
||||
commands.spawn((
|
||||
AudioPlayer::new(asset_server.load(format!("sfx/heads/{}.ogg", head_str))),
|
||||
@@ -275,3 +269,27 @@ fn update_head(
|
||||
|
||||
commands.entity(head).insert(SceneRoot(mesh));
|
||||
}
|
||||
|
||||
pub fn head_id_to_str(head: usize) -> &'static str {
|
||||
match head {
|
||||
0 => "angry demonstrator",
|
||||
1 => "carnival knife thrower",
|
||||
2 => "chicago gangster",
|
||||
3 => "commando",
|
||||
4 => "field medic",
|
||||
5 => "geisha",
|
||||
6 => "goblin",
|
||||
7 => "green grocer",
|
||||
8 => "highland hammer thrower",
|
||||
9 => "legionnaire",
|
||||
10 => "mig pilot",
|
||||
11 => "nanny",
|
||||
12 => "panic attack",
|
||||
13 => "salty sea dog",
|
||||
14 => "snow plough operator",
|
||||
15 => "soldier ant",
|
||||
16 => "super market shopper",
|
||||
17 => "troll",
|
||||
_ => unimplemented!(),
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user