Stub out intro animation

main
Elijah C. Voigt 2 years ago
parent 59755d2bdd
commit b983dc8e23

BIN
assets/images/border.png (Stored with Git LFS)

Binary file not shown.

@ -29,6 +29,18 @@ Space Blanket Folds - https://www.textures.com/download/PBR0152/133187
Background 2D art by NASA: LINK HERE Background 2D art by NASA: LINK HERE
""" """
[intro]
text = """
At the intersection of humanity's wildest imaginations and the infinite of the cosmos, the lines between possible and real fall apart like dissolving paper.
On Earth, a long tradition of combat and destruction amongst different groups has been upheld and respected; given a place in the social mind. As spacetime stretches ever on, the rhyme of the universe reveals itself, and even includes such traditions.
And so, humanity came face to face with a curiosity. Looking to our martian analogues, we find a twin destructive tradition, but one which seems backwards. In their tradition, each victory is also a loss. Each battle is waged simultaneously with opponent and self, and a mutual pact of annihilation and tactics unfolds until one side lays barren, just as likely to be the victor.
But Can you adapt?
Will you be a part of the universal rhyme, and if so, which side are you on?
"""
[resolution] [resolution]
x = 640 x = 640
y = 480 y = 480
@ -171,7 +183,7 @@ tonemapping = "ReinhardLuminance"
# https://docs.rs/bevy/0.11.3/bevy/render/view/struct.ColorGrading.html # https://docs.rs/bevy/0.11.3/bevy/render/view/struct.ColorGrading.html
### ###
[display3d.color.grading] [display3d.color.grading]
exposure = 1.0 exposure = 2.0
gamma = 1.0 gamma = 1.0
pre_saturation = 1.0 pre_saturation = 1.0
post_saturation = 1.0 post_saturation = 1.0

BIN
assets/models/Martian Chess.glb (Stored with Git LFS)

Binary file not shown.

BIN
assets/untitled.glb (Stored with Git LFS)

Binary file not shown.

@ -3,55 +3,57 @@ use bevy::{gltf::Gltf, prelude::*};
fn main() { fn main() {
App::new() App::new()
.add_plugins((DefaultPlugins,)) .add_plugins((DefaultPlugins,))
.add_systems(Startup, startup) .add_systems(Update, (inspect, load_gltf))
.add_systems(Update, inspect)
.run(); .run();
} }
#[derive(Debug, Resource)] #[derive(Debug, Component)]
struct AssetRegistry { struct InspectScene;
gltfs: Vec<Handle<Gltf>>,
}
fn startup(server: Res<AssetServer>, mut commands: Commands) {
commands.insert_resource(AssetRegistry {
gltfs: vec![server.load("gltf/Martian Chess.glb")],
});
commands.spawn(SpotLightBundle {
transform: Transform::from_xyz(0.0, 5.0, 0.0).looking_at(Vec3::ZERO, Vec3::Y),
..default()
});
commands.spawn(Camera3dBundle {
transform: Transform::from_xyz(1.0, 1.0, 1.0).looking_at(Vec3::new(0.0, 0.3, 0.0), Vec3::Y),
..default()
});
}
fn inspect( fn inspect(
mut events: EventReader<AssetEvent<Gltf>>, mut events: EventReader<AssetEvent<Scene>>,
gltfs: Res<Assets<Gltf>>, current: Query<Entity, With<InspectScene>>,
mut commands: Commands, mut commands: Commands,
) { ) {
events.iter().for_each(|event| match event { events.read().for_each(|event| match event {
AssetEvent::Created { handle } => { AssetEvent::LoadedWithDependencies { id } => {
let gltf = gltfs.get(handle).expect("Fetch GLTF data"); // Cleanup existing scenes
commands.spawn(SceneBundle { current.iter().for_each(|e| {
scene: gltf commands.entity(e).despawn_recursive();
.named_scenes
.get("Board")
.expect("Fetch board scene")
.clone(),
..default()
}); });
// Spawn default GLTF scene
commands.spawn((
SceneBundle {
scene: Handle::Weak(id.clone()),
..default()
},
InspectScene,
));
} }
_ => (), _ => (),
}); });
} }
fn track_named(events: Query<&Name, Added<Name>>) { fn load_gltf(
events.iter().for_each(|name| { mut events: EventReader<FileDragAndDrop>,
info!("named entity: {:?}", name); server: Res<AssetServer>,
}); mut handle: Local<Handle<Gltf>>,
) {
events.read().for_each(|event| match event {
FileDragAndDrop::DroppedFile { path_buf, .. } => {
let p = path_buf
.clone()
.into_os_string()
.into_string()
.unwrap()
.replace(
"D:\\Projects\\src\\gitea.elijah.run\\martian-chess\\assets\\",
"",
);
info!("Loading {:?}", p);
*handle = server.load(p);
}
_ => warn!("ignored"),
})
} }

@ -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)
}

@ -8,6 +8,7 @@ mod debug;
mod display3d; mod display3d;
mod game; mod game;
mod hit; mod hit;
mod intro;
mod loading; mod loading;
mod menu; mod menu;
mod prelude; mod prelude;
@ -63,6 +64,7 @@ fn main() {
app.add_plugins(audio::AudioPlugin); app.add_plugins(audio::AudioPlugin);
app.add_plugins(ui::UiPlugin); app.add_plugins(ui::UiPlugin);
app.add_plugins(tweak::TweakPlugin); app.add_plugins(tweak::TweakPlugin);
app.add_plugins(intro::IntroPlugin);
app.run(); app.run();
} }
@ -72,6 +74,7 @@ pub enum GameState {
Loading, Loading,
Menu, Menu,
Credits, Credits,
Intro,
Play, Play,
Endgame, Endgame,
} }

@ -60,7 +60,7 @@ fn init_menu_ui(mut commands: Commands) {
)); ));
parent parent
.spawn(( .spawn((
GameState::Play, GameState::Intro,
ButtonBundle { ButtonBundle {
style: Style { style: Style {
padding: UiRect::all(Val::Px(5.0)), padding: UiRect::all(Val::Px(5.0)),
@ -73,7 +73,7 @@ fn init_menu_ui(mut commands: Commands) {
)) ))
.with_children(|parent| { .with_children(|parent| {
parent.spawn(( parent.spawn((
GameState::Play, GameState::Intro,
TextBundle::from_section( TextBundle::from_section(
"Start", "Start",
TextStyle { TextStyle {

Loading…
Cancel
Save