heads module
This commit is contained in:
@@ -3,7 +3,7 @@ mod thrown;
|
||||
|
||||
use crate::{
|
||||
GameState,
|
||||
active_heads::ActiveHeads,
|
||||
heads::ActiveHeads,
|
||||
npc::Hit,
|
||||
player::{Player, PlayerRig},
|
||||
tb_entities::EnemySpawn,
|
||||
|
||||
@@ -2,7 +2,7 @@ use super::AimState;
|
||||
use crate::{
|
||||
GameState,
|
||||
backpack::UiHeadState,
|
||||
heads_ui::HeadsImages,
|
||||
heads::HeadsImages,
|
||||
loading_assets::UIAssets,
|
||||
npc::{Hitpoints, NpcHead},
|
||||
};
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
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::*;
|
||||
|
||||
static HEAD_SLOTS: usize = 5;
|
||||
|
||||
@@ -3,7 +3,7 @@ mod ui_head_state;
|
||||
|
||||
use crate::{
|
||||
GameState,
|
||||
active_heads::{HEAD_COUNT, HeadState},
|
||||
heads::{HEAD_COUNT, HeadState},
|
||||
};
|
||||
use bevy::prelude::*;
|
||||
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
use crate::heads::HeadState;
|
||||
use bevy::prelude::*;
|
||||
|
||||
use crate::active_heads::HeadState;
|
||||
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Reflect, Default)]
|
||||
pub struct UiHeadState {
|
||||
pub head: usize,
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
use crate::{
|
||||
GameState, abilities::TriggerState, active_heads::SelectActiveHead, backpack::BackpackAction,
|
||||
GameState, abilities::TriggerState, backpack::BackpackAction, heads::SelectActiveHead,
|
||||
};
|
||||
use bevy::{
|
||||
input::{
|
||||
|
||||
@@ -1,14 +1,10 @@
|
||||
use crate::{
|
||||
GameState,
|
||||
active_heads::{ActiveHeads, HEAD_COUNT, HEAD_SLOTS},
|
||||
backpack::UiHeadState,
|
||||
loading_assets::UIAssets,
|
||||
player::head_id_to_str,
|
||||
};
|
||||
use crate::{GameState, backpack::UiHeadState, loading_assets::UIAssets};
|
||||
use bevy::prelude::*;
|
||||
use bevy_ui_gradients::{AngularColorStop, BackgroundGradient, ConicGradient, Gradient, Position};
|
||||
use std::f32::consts::PI;
|
||||
|
||||
use super::{ActiveHeads, HEAD_SLOTS, HeadsImages};
|
||||
|
||||
#[derive(Component, Reflect, Default)]
|
||||
#[reflect(Component)]
|
||||
struct HeadSelector(pub usize);
|
||||
@@ -21,11 +17,6 @@ struct HeadImage(pub usize);
|
||||
#[reflect(Component)]
|
||||
struct HeadDamage(pub usize);
|
||||
|
||||
#[derive(Resource, Default)]
|
||||
pub struct HeadsImages {
|
||||
pub heads: Vec<Handle<Image>>,
|
||||
}
|
||||
|
||||
#[derive(Resource, Default, Reflect)]
|
||||
#[reflect(Resource)]
|
||||
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
|
||||
.spawn(Node {
|
||||
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>();
|
||||
}
|
||||
|
||||
@@ -1,6 +1,10 @@
|
||||
mod heads_ui;
|
||||
|
||||
use crate::{
|
||||
GameState,
|
||||
abilities::HeadAbility,
|
||||
backpack::{BackbackSwapEvent, Backpack},
|
||||
player::head_id_to_str,
|
||||
sounds::PlaySound,
|
||||
};
|
||||
use bevy::prelude::*;
|
||||
@@ -8,6 +12,11 @@ use bevy::prelude::*;
|
||||
pub static HEAD_COUNT: usize = 18;
|
||||
pub static HEAD_SLOTS: usize = 5;
|
||||
|
||||
#[derive(Resource, Default)]
|
||||
pub struct HeadsImages {
|
||||
pub heads: Vec<Handle<Image>>,
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Reflect)]
|
||||
pub struct HeadState {
|
||||
pub head: usize,
|
||||
@@ -80,6 +89,8 @@ pub enum SelectActiveHead {
|
||||
pub struct HeadChanged(pub usize);
|
||||
|
||||
pub fn plugin(app: &mut App) {
|
||||
app.add_plugins(heads_ui::plugin);
|
||||
|
||||
app.insert_resource(ActiveHeads {
|
||||
heads: [
|
||||
Some(HeadState::new(0, 10).with_ability(HeadAbility::Thrown)),
|
||||
@@ -91,10 +102,21 @@ pub fn plugin(app: &mut App) {
|
||||
current_slot: 0,
|
||||
});
|
||||
|
||||
app.add_systems(OnEnter(GameState::Playing), setup);
|
||||
|
||||
app.add_observer(on_select_active_head);
|
||||
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(
|
||||
trigger: Trigger<SelectActiveHead>,
|
||||
mut commands: Commands,
|
||||
@@ -1,5 +1,4 @@
|
||||
mod abilities;
|
||||
mod active_heads;
|
||||
mod aim;
|
||||
mod alien;
|
||||
mod backpack;
|
||||
@@ -8,7 +7,7 @@ mod cash;
|
||||
mod control;
|
||||
mod cutscene;
|
||||
mod gates;
|
||||
mod heads_ui;
|
||||
mod heads;
|
||||
mod keys;
|
||||
mod loading_assets;
|
||||
mod loading_map;
|
||||
@@ -99,7 +98,6 @@ fn main() {
|
||||
app.add_plugins(alien::plugin);
|
||||
app.add_plugins(cash::plugin);
|
||||
app.add_plugins(player::plugin);
|
||||
app.add_plugins(heads_ui::plugin);
|
||||
app.add_plugins(gates::plugin);
|
||||
app.add_plugins(platforms::plugin);
|
||||
app.add_plugins(movables::plugin);
|
||||
@@ -117,7 +115,7 @@ fn main() {
|
||||
app.add_plugins(loading_map::plugin);
|
||||
app.add_plugins(sprite_3d_animation::plugin);
|
||||
app.add_plugins(abilities::plugin);
|
||||
app.add_plugins(active_heads::plugin);
|
||||
app.add_plugins(heads::plugin);
|
||||
|
||||
app.init_state::<GameState>();
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
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,
|
||||
};
|
||||
use bevy::prelude::*;
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
use crate::{
|
||||
GameState,
|
||||
active_heads::HeadChanged,
|
||||
alien::Animations,
|
||||
camera::{CameraArmRotation, CameraTarget},
|
||||
cash::{Cash, CashCollectEvent},
|
||||
@@ -8,6 +7,7 @@ use crate::{
|
||||
Controls,
|
||||
controller::{CharacterControllerBundle, MovementBundle, PlayerMovement},
|
||||
},
|
||||
heads::HeadChanged,
|
||||
loading_assets::GameAssets,
|
||||
physics_layers::GameLayer,
|
||||
sounds::PlaySound,
|
||||
|
||||
Reference in New Issue
Block a user