heads module

This commit is contained in:
2025-04-02 01:43:56 +08:00
parent 01e6e944d3
commit 9aaa015bd6
11 changed files with 36 additions and 33 deletions

View File

@@ -3,7 +3,7 @@ mod thrown;
use crate::{ use crate::{
GameState, GameState,
active_heads::ActiveHeads, heads::ActiveHeads,
npc::Hit, npc::Hit,
player::{Player, PlayerRig}, player::{Player, PlayerRig},
tb_entities::EnemySpawn, tb_entities::EnemySpawn,

View File

@@ -2,7 +2,7 @@ use super::AimState;
use crate::{ use crate::{
GameState, GameState,
backpack::UiHeadState, backpack::UiHeadState,
heads_ui::HeadsImages, heads::HeadsImages,
loading_assets::UIAssets, loading_assets::UIAssets,
npc::{Hitpoints, NpcHead}, npc::{Hitpoints, NpcHead},
}; };

View File

@@ -1,5 +1,5 @@
use super::{BackbackSwapEvent, Backpack, UiHeadState}; use super::{BackbackSwapEvent, Backpack, UiHeadState};
use crate::{GameState, heads_ui::HeadsImages, loading_assets::UIAssets, sounds::PlaySound}; use crate::{GameState, heads::HeadsImages, loading_assets::UIAssets, sounds::PlaySound};
use bevy::prelude::*; use bevy::prelude::*;
static HEAD_SLOTS: usize = 5; static HEAD_SLOTS: usize = 5;

View File

@@ -3,7 +3,7 @@ mod ui_head_state;
use crate::{ use crate::{
GameState, GameState,
active_heads::{HEAD_COUNT, HeadState}, heads::{HEAD_COUNT, HeadState},
}; };
use bevy::prelude::*; use bevy::prelude::*;

View File

@@ -1,7 +1,6 @@
use crate::heads::HeadState;
use bevy::prelude::*; use bevy::prelude::*;
use crate::active_heads::HeadState;
#[derive(Clone, Copy, Debug, PartialEq, Reflect, Default)] #[derive(Clone, Copy, Debug, PartialEq, Reflect, Default)]
pub struct UiHeadState { pub struct UiHeadState {
pub head: usize, pub head: usize,

View File

@@ -1,5 +1,5 @@
use crate::{ use crate::{
GameState, abilities::TriggerState, active_heads::SelectActiveHead, backpack::BackpackAction, GameState, abilities::TriggerState, backpack::BackpackAction, heads::SelectActiveHead,
}; };
use bevy::{ use bevy::{
input::{ input::{

View File

@@ -1,14 +1,10 @@
use crate::{ use crate::{GameState, backpack::UiHeadState, loading_assets::UIAssets};
GameState,
active_heads::{ActiveHeads, HEAD_COUNT, HEAD_SLOTS},
backpack::UiHeadState,
loading_assets::UIAssets,
player::head_id_to_str,
};
use bevy::prelude::*; use bevy::prelude::*;
use bevy_ui_gradients::{AngularColorStop, BackgroundGradient, ConicGradient, Gradient, Position}; use bevy_ui_gradients::{AngularColorStop, BackgroundGradient, ConicGradient, Gradient, Position};
use std::f32::consts::PI; use std::f32::consts::PI;
use super::{ActiveHeads, HEAD_SLOTS, HeadsImages};
#[derive(Component, Reflect, Default)] #[derive(Component, Reflect, Default)]
#[reflect(Component)] #[reflect(Component)]
struct HeadSelector(pub usize); struct HeadSelector(pub usize);
@@ -21,11 +17,6 @@ struct HeadImage(pub usize);
#[reflect(Component)] #[reflect(Component)]
struct HeadDamage(pub usize); struct HeadDamage(pub usize);
#[derive(Resource, Default)]
pub struct HeadsImages {
pub heads: Vec<Handle<Image>>,
}
#[derive(Resource, Default, Reflect)] #[derive(Resource, Default, Reflect)]
#[reflect(Resource)] #[reflect(Resource)]
struct UiActiveHeads { struct UiActiveHeads {
@@ -44,7 +35,7 @@ pub fn plugin(app: &mut App) {
); );
} }
fn setup(mut commands: Commands, asset_server: Res<AssetServer>, assets: Res<UIAssets>) { fn setup(mut commands: Commands, assets: Res<UIAssets>) {
commands commands
.spawn(Node { .spawn(Node {
position_type: PositionType::Absolute, position_type: PositionType::Absolute,
@@ -66,13 +57,6 @@ fn setup(mut commands: Commands, asset_server: Res<AssetServer>, assets: Res<UIA
} }
}); });
// TODO: load via asset loader
let heads = (0usize..HEAD_COUNT)
.map(|i| asset_server.load(format!("ui/heads/{}.png", head_id_to_str(i))))
.collect();
commands.insert_resource(HeadsImages { heads });
commands.init_resource::<UiActiveHeads>(); commands.init_resource::<UiActiveHeads>();
} }

View File

@@ -1,6 +1,10 @@
mod heads_ui;
use crate::{ use crate::{
GameState,
abilities::HeadAbility, abilities::HeadAbility,
backpack::{BackbackSwapEvent, Backpack}, backpack::{BackbackSwapEvent, Backpack},
player::head_id_to_str,
sounds::PlaySound, sounds::PlaySound,
}; };
use bevy::prelude::*; use bevy::prelude::*;
@@ -8,6 +12,11 @@ use bevy::prelude::*;
pub static HEAD_COUNT: usize = 18; pub static HEAD_COUNT: usize = 18;
pub static HEAD_SLOTS: usize = 5; pub static HEAD_SLOTS: usize = 5;
#[derive(Resource, Default)]
pub struct HeadsImages {
pub heads: Vec<Handle<Image>>,
}
#[derive(Clone, Copy, Debug, PartialEq, Reflect)] #[derive(Clone, Copy, Debug, PartialEq, Reflect)]
pub struct HeadState { pub struct HeadState {
pub head: usize, pub head: usize,
@@ -80,6 +89,8 @@ pub enum SelectActiveHead {
pub struct HeadChanged(pub usize); pub struct HeadChanged(pub usize);
pub fn plugin(app: &mut App) { pub fn plugin(app: &mut App) {
app.add_plugins(heads_ui::plugin);
app.insert_resource(ActiveHeads { app.insert_resource(ActiveHeads {
heads: [ heads: [
Some(HeadState::new(0, 10).with_ability(HeadAbility::Thrown)), Some(HeadState::new(0, 10).with_ability(HeadAbility::Thrown)),
@@ -91,10 +102,21 @@ pub fn plugin(app: &mut App) {
current_slot: 0, current_slot: 0,
}); });
app.add_systems(OnEnter(GameState::Playing), setup);
app.add_observer(on_select_active_head); app.add_observer(on_select_active_head);
app.add_observer(on_swap_backpack); app.add_observer(on_swap_backpack);
} }
fn setup(mut commands: Commands, asset_server: Res<AssetServer>) {
// TODO: load via asset loader
let heads = (0usize..HEAD_COUNT)
.map(|i| asset_server.load(format!("ui/heads/{}.png", head_id_to_str(i))))
.collect();
commands.insert_resource(HeadsImages { heads });
}
fn on_select_active_head( fn on_select_active_head(
trigger: Trigger<SelectActiveHead>, trigger: Trigger<SelectActiveHead>,
mut commands: Commands, mut commands: Commands,

View File

@@ -1,5 +1,4 @@
mod abilities; mod abilities;
mod active_heads;
mod aim; mod aim;
mod alien; mod alien;
mod backpack; mod backpack;
@@ -8,7 +7,7 @@ mod cash;
mod control; mod control;
mod cutscene; mod cutscene;
mod gates; mod gates;
mod heads_ui; mod heads;
mod keys; mod keys;
mod loading_assets; mod loading_assets;
mod loading_map; mod loading_map;
@@ -99,7 +98,6 @@ fn main() {
app.add_plugins(alien::plugin); app.add_plugins(alien::plugin);
app.add_plugins(cash::plugin); app.add_plugins(cash::plugin);
app.add_plugins(player::plugin); app.add_plugins(player::plugin);
app.add_plugins(heads_ui::plugin);
app.add_plugins(gates::plugin); app.add_plugins(gates::plugin);
app.add_plugins(platforms::plugin); app.add_plugins(platforms::plugin);
app.add_plugins(movables::plugin); app.add_plugins(movables::plugin);
@@ -117,7 +115,7 @@ fn main() {
app.add_plugins(loading_map::plugin); app.add_plugins(loading_map::plugin);
app.add_plugins(sprite_3d_animation::plugin); app.add_plugins(sprite_3d_animation::plugin);
app.add_plugins(abilities::plugin); app.add_plugins(abilities::plugin);
app.add_plugins(active_heads::plugin); app.add_plugins(heads::plugin);
app.init_state::<GameState>(); app.init_state::<GameState>();

View File

@@ -1,5 +1,5 @@
use crate::{ use crate::{
GameState, active_heads::HEAD_COUNT, keys::KeySpawn, player::head_id_to_str, sounds::PlaySound, GameState, heads::HEAD_COUNT, keys::KeySpawn, player::head_id_to_str, sounds::PlaySound,
tb_entities::EnemySpawn, tb_entities::EnemySpawn,
}; };
use bevy::prelude::*; use bevy::prelude::*;

View File

@@ -1,6 +1,5 @@
use crate::{ use crate::{
GameState, GameState,
active_heads::HeadChanged,
alien::Animations, alien::Animations,
camera::{CameraArmRotation, CameraTarget}, camera::{CameraArmRotation, CameraTarget},
cash::{Cash, CashCollectEvent}, cash::{Cash, CashCollectEvent},
@@ -8,6 +7,7 @@ use crate::{
Controls, Controls,
controller::{CharacterControllerBundle, MovementBundle, PlayerMovement}, controller::{CharacterControllerBundle, MovementBundle, PlayerMovement},
}, },
heads::HeadChanged,
loading_assets::GameAssets, loading_assets::GameAssets,
physics_layers::GameLayer, physics_layers::GameLayer,
sounds::PlaySound, sounds::PlaySound,