Stub out intro animation
parent
59755d2bdd
commit
b983dc8e23
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -0,0 +1,95 @@
|
|||||||
|
use crate::prelude::*;
|
||||||
|
|
||||||
|
pub(crate) struct IntroPlugin;
|
||||||
|
|
||||||
|
impl Plugin for IntroPlugin {
|
||||||
|
fn build(&self, app: &mut App) {
|
||||||
|
app.add_systems(
|
||||||
|
OnExit(GameState::Loading),
|
||||||
|
init_intro_text.run_if(resource_exists::<tweak::GameTweaks>()),
|
||||||
|
)
|
||||||
|
.add_systems(OnEnter(GameState::Intro), activate::<Intro>)
|
||||||
|
.add_systems(OnExit(GameState::Intro), deactivate::<Intro>)
|
||||||
|
.add_systems(Update, play_intro
|
||||||
|
.run_if(in_state(GameState::<Intro>()))
|
||||||
|
.run_if(not(resource_exists::<IntroPlayed>()))
|
||||||
|
)
|
||||||
|
// Continue to play state if the intro is done playing out
|
||||||
|
.add_systems(
|
||||||
|
Update,
|
||||||
|
continue_to_play
|
||||||
|
.run_if(|keys: Res<Input<KeyCode>>| -> bool { keys.just_pressed(KeyCode::Return) })
|
||||||
|
.run_if(resource_exists::<IntroPlayed>()),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Component)]
|
||||||
|
struct Intro;
|
||||||
|
|
||||||
|
#[derive(Debug, Resource)]
|
||||||
|
struct IntroPlayed;
|
||||||
|
|
||||||
|
// Draw the intro text (invisible) on startup
|
||||||
|
// Requires the Tweakfile to be loaded
|
||||||
|
fn init_intro_text(
|
||||||
|
tweaks_file: Res<tweak::GameTweaks>,
|
||||||
|
tweaks: Res<Assets<tweak::Tweaks>>,
|
||||||
|
mut commands: Commands,
|
||||||
|
) {
|
||||||
|
let tweak = tweaks.get(tweaks_file.handle.clone()).expect("Load tweaks");
|
||||||
|
|
||||||
|
let text = tweak.get::<String>("intro_text").expect("Intro text");
|
||||||
|
|
||||||
|
commands
|
||||||
|
.spawn((
|
||||||
|
Intro,
|
||||||
|
NodeBundle {
|
||||||
|
style: Style {
|
||||||
|
width: Val::Percent(100.0),
|
||||||
|
height: Val::Percent(100.0),
|
||||||
|
justify_content: JustifyContent::Center,
|
||||||
|
align_items: AlignItems::Center,
|
||||||
|
flex_direction: FlexDirection::Column,
|
||||||
|
position_type: PositionType::Absolute,
|
||||||
|
padding: UiRect::all(Val::Px(50.0)),
|
||||||
|
..default()
|
||||||
|
},
|
||||||
|
background_color: Color::NONE.into(),
|
||||||
|
visibility: Visibility::Hidden,
|
||||||
|
..default()
|
||||||
|
},
|
||||||
|
))
|
||||||
|
.with_children(|parent| {
|
||||||
|
parent.spawn((
|
||||||
|
Intro,
|
||||||
|
TextBundle::from_sections(text.chars().into_iter().map(|c| TextSection {
|
||||||
|
value: c.to_string(),
|
||||||
|
style: TextStyle {
|
||||||
|
font_size: 16.0,
|
||||||
|
color: Color::WHITE,
|
||||||
|
..default()
|
||||||
|
},
|
||||||
|
}))
|
||||||
|
.with_text_alignment(TextAlignment::Center),
|
||||||
|
));
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
// Upon entering the Intro state, start the intro "animation"
|
||||||
|
fn play_intro(
|
||||||
|
mut text: Query<&mut Text, With<Intro>>,
|
||||||
|
progress: Local<f32>,
|
||||||
|
mut commands: Commands,
|
||||||
|
) {
|
||||||
|
todo!("Play the intro animation, typing each character one at a time...");
|
||||||
|
commands.insert_resource(IntroPlayed);
|
||||||
|
}
|
||||||
|
// Intro animation reveals one character every nth frame
|
||||||
|
|
||||||
|
// Hit enter to skip the "animation"
|
||||||
|
|
||||||
|
// Hit enter once the animation is complete to start the game
|
||||||
|
fn continue_to_play(mut next_state: ResMut<NextState<GameState>>) {
|
||||||
|
next_state.set(GameState::Play)
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue