Newer
Older
use std::time::Duration;
use bevy::prelude::*;
use bevy_tweening::lens::TextColorLens;
use bevy_tweening::{Animator, EaseFunction, RepeatCount, RepeatStrategy, Tween};
use micro_musicbox::prelude::{AudioEasing, AudioTween, MusicBox};
#[derive(Component)]
pub struct MenuStateEntity;
pub fn spawn_menu_entities(
mut commands: Commands,
assets: Res<AssetHandles>,
mut musicbox: MusicBox<AssetHandles>,
) {
commands.spawn((
SpriteBundle {
texture: assets.image("menu_background"),
transform: Transform::from_scale(Vec3::splat(0.85)),
..Default::default()
},
MenuStateEntity,
));
commands
.spawn((
MenuStateEntity,
NodeBundle {
style: Style {
size: Size::new(Val::Percent(100.0), Val::Percent(100.0)),
flex_direction: FlexDirection::Column,
align_items: AlignItems::Center,
..Default::default()
},
.with_children(|commands| {
commands.spawn(TextBundle {
text: Text::from_section(
"Trader Tales",
TextStyle {
font_size: 72.0,
font: assets.font("compass_pro"),
color: Color::ANTIQUE_WHITE,
},
),
style: Style {
margin: UiRect::top(Val::Percent(20.0)),
..Default::default()
},
..Default::default()
});
commands.spawn((
TextBundle {
text: Text::from_section(
font: assets.font("compass_pro"),
color: Color::ANTIQUE_WHITE,
},
),
style: Style {
margin: UiRect::top(Val::Px(50.0)),
..Default::default()
},
..Default::default()
},
Animator::new(
Tween::new(
EaseFunction::QuadraticInOut,
Duration::from_secs(1),
TextColorLens {
start: Color::ANTIQUE_WHITE,
end: *Color::ANTIQUE_WHITE.set_a(0.0),
section: 0,
},
)
.with_repeat_count(RepeatCount::Infinite)
.with_repeat_strategy(RepeatStrategy::MirroredRepeat),
),
));
});
}
pub fn go_to_game(input: Res<Input<KeyCode>>, mut commands: Commands) {
if input.just_released(KeyCode::Space) {
commands.insert_resource(NextState(AppState::InGame));
}
}