added second layer for start of pause menu stuff
This commit is contained in:
parent
a703f6ab85
commit
9de729fb7f
8 changed files with 247 additions and 11 deletions
88
Cargo.lock
generated
88
Cargo.lock
generated
|
|
@ -1074,6 +1074,18 @@ dependencies = [
|
|||
"tracing",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "bevy_prototype_lyon"
|
||||
version = "0.15.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "eb09bb9cadacae3238d1bdc856b71a164a17f93e1e94db62011dd969dacbe75b"
|
||||
dependencies = [
|
||||
"bevy",
|
||||
"lyon_algorithms",
|
||||
"lyon_tessellation",
|
||||
"svgtypes",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "bevy_ptr"
|
||||
version = "0.17.3"
|
||||
|
|
@ -1310,6 +1322,7 @@ name = "bevy_stock_photo"
|
|||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"bevy",
|
||||
"bevy_prototype_lyon",
|
||||
"enumset",
|
||||
"rand",
|
||||
"serde",
|
||||
|
|
@ -2297,6 +2310,12 @@ dependencies = [
|
|||
"miniz_oxide",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "float_next_after"
|
||||
version = "1.0.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "8bf7cc16383c4b8d58b9905a8509f02926ce3058053c056376248d958c9df1e8"
|
||||
|
||||
[[package]]
|
||||
name = "fnv"
|
||||
version = "1.0.7"
|
||||
|
|
@ -2862,6 +2881,17 @@ dependencies = [
|
|||
"bitflags 2.10.0",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "kurbo"
|
||||
version = "0.11.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "c62026ae44756f8a599ba21140f350303d4f08dcdcc71b5ad9c9bb8128c13c62"
|
||||
dependencies = [
|
||||
"arrayvec",
|
||||
"euclid",
|
||||
"smallvec",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "lazy_static"
|
||||
version = "1.5.0"
|
||||
|
|
@ -2955,6 +2985,48 @@ version = "0.4.29"
|
|||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "5e5032e24019045c762d3c0f28f5b6b8bbf38563a65908389bf7978758920897"
|
||||
|
||||
[[package]]
|
||||
name = "lyon_algorithms"
|
||||
version = "1.0.16"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f4c0829e28c4f336396f250d850c3987e16ce6db057ffe047ce0dd54aab6b647"
|
||||
dependencies = [
|
||||
"lyon_path",
|
||||
"num-traits",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "lyon_geom"
|
||||
version = "1.0.18"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e260b6de923e6e47adfedf6243013a7a874684165a6a277594ee3906021b2343"
|
||||
dependencies = [
|
||||
"arrayvec",
|
||||
"euclid",
|
||||
"num-traits",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "lyon_path"
|
||||
version = "1.0.16"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "1aeca86bcfd632a15984ba029b539ffb811e0a70bf55e814ef8b0f54f506fdeb"
|
||||
dependencies = [
|
||||
"lyon_geom",
|
||||
"num-traits",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "lyon_tessellation"
|
||||
version = "1.0.16"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f3f586142e1280335b1bc89539f7c97dd80f08fc43e9ab1b74ef0a42b04aa353"
|
||||
dependencies = [
|
||||
"float_next_after",
|
||||
"lyon_path",
|
||||
"num-traits",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "mach2"
|
||||
version = "0.4.3"
|
||||
|
|
@ -4121,6 +4193,12 @@ version = "0.3.7"
|
|||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "d66dc143e6b11c1eddc06d5c423cfc97062865baf299914ab64caa38182078fe"
|
||||
|
||||
[[package]]
|
||||
name = "siphasher"
|
||||
version = "1.0.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "56199f7ddabf13fe5074ce809e7d3f42b42ae711800501b5b16ea82ad029c39d"
|
||||
|
||||
[[package]]
|
||||
name = "skrifa"
|
||||
version = "0.37.0"
|
||||
|
|
@ -4237,6 +4315,16 @@ version = "0.4.5"
|
|||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "0193cc4331cfd2f3d2011ef287590868599a2f33c3e69bc22c1a3d3acf9e02fb"
|
||||
|
||||
[[package]]
|
||||
name = "svgtypes"
|
||||
version = "0.15.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "68c7541fff44b35860c1a7a47a7cadf3e4a304c457b58f9870d9706ece028afc"
|
||||
dependencies = [
|
||||
"kurbo",
|
||||
"siphasher",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "swash"
|
||||
version = "0.2.6"
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@ edition = "2024"
|
|||
|
||||
[dependencies]
|
||||
bevy = "0.17.3"
|
||||
bevy_prototype_lyon = "0.15.0"
|
||||
enumset = "1.1.10"
|
||||
rand = "0.9.2"
|
||||
serde = { version = "1.0.228", features = ["derive"] }
|
||||
|
|
|
|||
BIN
assets/fonts/GloriaHalleluja.ttf
Normal file
BIN
assets/fonts/GloriaHalleluja.ttf
Normal file
Binary file not shown.
|
|
@ -1 +1,2 @@
|
|||
pub mod navi;
|
||||
pub mod pause;
|
||||
|
|
|
|||
|
|
@ -1,4 +1,6 @@
|
|||
use bevy::{post_process::bloom::Bloom, prelude::*, sprite::Anchor};
|
||||
use bevy::{
|
||||
camera::visibility::RenderLayers, post_process::bloom::Bloom, prelude::*, sprite::Anchor,
|
||||
};
|
||||
use rand::Rng;
|
||||
|
||||
use crate::{
|
||||
|
|
@ -26,6 +28,10 @@ impl Plugin for NaviGameplayPlugin {
|
|||
#[derive(Component)]
|
||||
pub struct PlayerVWBus;
|
||||
|
||||
#[derive(Component)]
|
||||
#[require(Camera2d)]
|
||||
struct MainCamera;
|
||||
|
||||
pub fn setup_scene(
|
||||
mut commands: Commands,
|
||||
mut meshes: ResMut<Assets<Mesh>>,
|
||||
|
|
@ -36,7 +42,16 @@ pub fn setup_scene(
|
|||
MeshMaterial2d(materials.add(Color::srgb(0.2, 0.2, 0.3))),
|
||||
));
|
||||
|
||||
commands.spawn((Camera2d, Bloom::NATURAL));
|
||||
commands.spawn((
|
||||
MainCamera,
|
||||
Camera {
|
||||
order: 1,
|
||||
// clear_color: ClearColorConfig::None,
|
||||
..default()
|
||||
},
|
||||
Bloom::NATURAL,
|
||||
RenderLayers::layer(0),
|
||||
));
|
||||
}
|
||||
|
||||
pub fn spawn_bus(mut commands: Commands, asset_server: Res<AssetServer>) {
|
||||
|
|
@ -106,9 +121,9 @@ pub fn move_player(
|
|||
}
|
||||
}
|
||||
|
||||
pub fn follow_player(
|
||||
mut camera: Single<&mut Transform, (With<Camera2d>, Without<PlayerVWBus>)>,
|
||||
player: Single<&Transform, (With<PlayerVWBus>, Without<Camera2d>)>,
|
||||
fn follow_player(
|
||||
mut camera: Single<&mut Transform, (With<MainCamera>, Without<PlayerVWBus>)>,
|
||||
player: Single<&Transform, (With<PlayerVWBus>, Without<MainCamera>)>,
|
||||
time: Res<Time>,
|
||||
) {
|
||||
let Vec3 { x, y, .. } = player.translation;
|
||||
|
|
|
|||
115
src/gameplay/pause.rs
Normal file
115
src/gameplay/pause.rs
Normal file
|
|
@ -0,0 +1,115 @@
|
|||
use bevy::{
|
||||
camera::visibility::RenderLayers, post_process::bloom::Bloom, prelude::*, sprite::Anchor,
|
||||
};
|
||||
|
||||
use crate::{
|
||||
GameState, PauseState,
|
||||
utils::input::{GameInputPlugin, InputButton, InputMessage, InputPressStatus},
|
||||
};
|
||||
|
||||
const COLOR_BG: Color = Color::srgba_u8(249, 226, 156, 255);
|
||||
const COLOR_HL1: Color = Color::srgba_u8(187, 241, 241, 255);
|
||||
const COLOR_HL2: Color = Color::srgba_u8(192, 149, 145, 255);
|
||||
|
||||
pub struct PausePlugin;
|
||||
|
||||
impl Plugin for PausePlugin {
|
||||
fn build(&self, app: &mut App) {
|
||||
app.add_systems(Startup, setup_pause).add_systems(
|
||||
Update,
|
||||
(
|
||||
listen_for_pause.run_if(in_state(PauseState::Running)),
|
||||
listen_for_unpause.run_if(in_state(PauseState::Paused)),
|
||||
animate_in.run_if(in_state(PauseState::AnimatingIntoPause)),
|
||||
animate_out.run_if(in_state(PauseState::AnimatingOutOfPause)),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Component)]
|
||||
pub struct PauseMenuRoot;
|
||||
|
||||
#[derive(Component)]
|
||||
#[require(Camera2d)]
|
||||
struct PauseCamera;
|
||||
|
||||
fn setup_pause(
|
||||
mut commands: Commands,
|
||||
assets: Res<AssetServer>,
|
||||
mut meshes: ResMut<Assets<Mesh>>,
|
||||
mut materials: ResMut<Assets<ColorMaterial>>,
|
||||
) {
|
||||
commands.spawn((
|
||||
PauseCamera,
|
||||
Camera {
|
||||
order: 3,
|
||||
clear_color: ClearColorConfig::None,
|
||||
|
||||
..default()
|
||||
},
|
||||
// Bloom::NATURAL,
|
||||
RenderLayers::layer(3),
|
||||
));
|
||||
commands.spawn((
|
||||
Mesh2d(meshes.add(Triangle2d::new(
|
||||
Vec2::new(-100., -100.),
|
||||
Vec2::new(-100., 100.),
|
||||
Vec2::new(-100., 100.),
|
||||
))),
|
||||
MeshMaterial2d(materials.add(Color::srgb(0.2, 0.2, 0.3))),
|
||||
RenderLayers::layer(3),
|
||||
));
|
||||
commands.spawn((
|
||||
Node {
|
||||
position_type: PositionType::Absolute,
|
||||
width: percent(80),
|
||||
height: percent(80),
|
||||
align_items: AlignItems::Center,
|
||||
justify_content: JustifyContent::Center,
|
||||
..default()
|
||||
},
|
||||
UiTransform::from_translation(Val2::px(0., 0.)),
|
||||
BackgroundColor(COLOR_BG),
|
||||
Visibility::Visible,
|
||||
PauseMenuRoot,
|
||||
));
|
||||
}
|
||||
|
||||
fn listen_for_pause(
|
||||
mut next: ResMut<NextState<PauseState>>,
|
||||
mut btn_msgs: MessageReader<InputMessage>,
|
||||
) {
|
||||
for btn_msg in btn_msgs.read() {
|
||||
if btn_msg.just_pressed(InputButton::Pause) {
|
||||
next.set(PauseState::AnimatingIntoPause);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn listen_for_unpause(
|
||||
mut next: ResMut<NextState<PauseState>>,
|
||||
mut btn_msgs: MessageReader<InputMessage>,
|
||||
) {
|
||||
for btn_msg in btn_msgs.read() {
|
||||
if btn_msg.just_pressed(InputButton::Pause) {
|
||||
next.set(PauseState::AnimatingOutOfPause);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn animate_in(
|
||||
mut menu_visibility: Single<&mut Visibility, With<PauseMenuRoot>>,
|
||||
mut next_state: ResMut<NextState<PauseState>>,
|
||||
) {
|
||||
**menu_visibility = Visibility::Visible;
|
||||
next_state.set(PauseState::Paused);
|
||||
}
|
||||
|
||||
fn animate_out(
|
||||
mut menu_visibility: Single<&mut Visibility, With<PauseMenuRoot>>,
|
||||
mut next_state: ResMut<NextState<PauseState>>,
|
||||
) {
|
||||
**menu_visibility = Visibility::Hidden;
|
||||
next_state.set(PauseState::Running);
|
||||
}
|
||||
10
src/main.rs
10
src/main.rs
|
|
@ -1,8 +1,7 @@
|
|||
use bevy::{post_process::bloom::Bloom, prelude::*, sprite::Anchor};
|
||||
use rand::Rng;
|
||||
|
||||
use crate::{
|
||||
gameplay::navi::NaviGameplayPlugin,
|
||||
gameplay::{navi::NaviGameplayPlugin, pause::PausePlugin},
|
||||
utils::input::{GameInputPlugin, InputButton, InputPressStatus},
|
||||
};
|
||||
|
||||
|
|
@ -29,7 +28,12 @@ pub enum PauseState {
|
|||
fn main() {
|
||||
println!("Hello, world!");
|
||||
App::new()
|
||||
.add_plugins((DefaultPlugins, GameInputPlugin, NaviGameplayPlugin))
|
||||
.add_plugins((
|
||||
DefaultPlugins,
|
||||
GameInputPlugin,
|
||||
NaviGameplayPlugin,
|
||||
PausePlugin,
|
||||
))
|
||||
.init_state::<GameState>()
|
||||
.init_state::<PauseState>()
|
||||
.run();
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@ impl Plugin for GameInputPlugin {
|
|||
fn build(&self, app: &mut App) {
|
||||
app.insert_resource(InputPressStatus::default())
|
||||
.add_message::<InputMessage>()
|
||||
.add_systems(Update, process_input);
|
||||
.add_systems(Update, (process_input, input_debug_logger));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -28,7 +28,7 @@ fn process_input(
|
|||
}
|
||||
}
|
||||
|
||||
#[derive(EnumSetType)]
|
||||
#[derive(EnumSetType, Debug)]
|
||||
pub enum InputButton {
|
||||
Up,
|
||||
Down,
|
||||
|
|
@ -39,12 +39,13 @@ pub enum InputButton {
|
|||
Pause,
|
||||
}
|
||||
|
||||
#[derive(PartialEq, Debug)]
|
||||
pub enum InputAction {
|
||||
Pressed,
|
||||
Released,
|
||||
}
|
||||
|
||||
#[derive(Message)]
|
||||
#[derive(Message, Debug)]
|
||||
pub struct InputMessage {
|
||||
button: InputButton,
|
||||
action: InputAction,
|
||||
|
|
@ -73,6 +74,11 @@ impl InputMessage {
|
|||
pub fn new(button: InputButton, action: InputAction) -> Self {
|
||||
Self { button, action }
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pub fn just_pressed(&self, button: InputButton) -> bool {
|
||||
self.button == button && self.action == InputAction::Pressed
|
||||
}
|
||||
}
|
||||
|
||||
impl KeyboardMapping {
|
||||
|
|
@ -80,3 +86,9 @@ impl KeyboardMapping {
|
|||
Self { key, button }
|
||||
}
|
||||
}
|
||||
|
||||
fn input_debug_logger(mut input_reader: MessageReader<InputMessage>) {
|
||||
for msg in input_reader.read() {
|
||||
info!("Input Event: {:?}", msg);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue