add story shit
This commit is contained in:
parent
a597b09970
commit
c27cfdbb22
7 changed files with 133 additions and 1085 deletions
|
@ -1,6 +1,6 @@
|
||||||
[target.x86_64-unknown-linux-gnu]
|
[target.x86_64-unknown-linux-gnu]
|
||||||
linker = "clang"
|
# linker = "clang"
|
||||||
rustflags = [
|
# rustflags = [
|
||||||
"-C", "link-arg=-fuse-ld=mold",
|
# "-C", "link-arg=-fuse-ld=mold",
|
||||||
]
|
# ]
|
||||||
|
|
||||||
|
|
1086
Cargo.lock
generated
1086
Cargo.lock
generated
File diff suppressed because it is too large
Load diff
|
@ -6,7 +6,7 @@ edition = "2021"
|
||||||
[dependencies]
|
[dependencies]
|
||||||
bevy = { version = "0.14.2" }
|
bevy = { version = "0.14.2" }
|
||||||
bevy_rapier2d = {version = "0.27.0", features = ["debug-render-2d", "simd-stable", "parallel"]}
|
bevy_rapier2d = {version = "0.27.0", features = ["debug-render-2d", "simd-stable", "parallel"]}
|
||||||
bevy_editor_pls = "0.10"
|
# bevy_editor_pls = "0.10"
|
||||||
readformat = "0.1.2"
|
readformat = "0.1.2"
|
||||||
|
|
||||||
# Enable a small amount of optimization in the dev profile.
|
# Enable a small amount of optimization in the dev profile.
|
||||||
|
|
|
@ -7,7 +7,7 @@ use crate::AppState;
|
||||||
|
|
||||||
mod player;
|
mod player;
|
||||||
mod scene;
|
mod scene;
|
||||||
mod set;
|
pub mod set;
|
||||||
|
|
||||||
pub const WORLD_DEPTH: f32 = 0.5;
|
pub const WORLD_DEPTH: f32 = 0.5;
|
||||||
pub const PLAYER_DEPTH: f32 = 0.4;
|
pub const PLAYER_DEPTH: f32 = 0.4;
|
||||||
|
|
|
@ -59,7 +59,8 @@ pub(super) fn player_plugin(app: &mut App) {
|
||||||
move_player,
|
move_player,
|
||||||
debug_player_pos,
|
debug_player_pos,
|
||||||
run_animations::<PlayerAnimations>,
|
run_animations::<PlayerAnimations>,
|
||||||
),
|
)
|
||||||
|
.in_set(IngameSet),
|
||||||
)
|
)
|
||||||
.init_resource::<PlayerSpawnOneshot>();
|
.init_resource::<PlayerSpawnOneshot>();
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,6 +13,7 @@ use crate::parallax::{parallax, Parallax};
|
||||||
use crate::AppState;
|
use crate::AppState;
|
||||||
|
|
||||||
use super::player::PlayerSpawnOneshot;
|
use super::player::PlayerSpawnOneshot;
|
||||||
|
use super::set::IngameSet;
|
||||||
use super::{PLAYER_DEPTH, PLAYER_SIZE_FRACTION};
|
use super::{PLAYER_DEPTH, PLAYER_SIZE_FRACTION};
|
||||||
|
|
||||||
#[derive(Component)]
|
#[derive(Component)]
|
||||||
|
@ -52,7 +53,7 @@ impl From<PlayerCoords> for Transform {
|
||||||
pub(super) fn scene_plugin(app: &mut App) {
|
pub(super) fn scene_plugin(app: &mut App) {
|
||||||
// app.add_plugins(EditorPlugin::default());
|
// app.add_plugins(EditorPlugin::default());
|
||||||
// app.add_systems(, )
|
// app.add_systems(, )
|
||||||
app.add_systems(Startup, (import_text_world,));
|
app.add_systems(Startup, (import_text_world,).in_set(IngameSet));
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Default, Resource)]
|
#[derive(Default, Resource)]
|
||||||
|
|
114
src/main.rs
114
src/main.rs
|
@ -1,7 +1,8 @@
|
||||||
#![allow(unused)]
|
#![allow(unused)]
|
||||||
|
|
||||||
use bevy::prelude::*;
|
use bevy::prelude::*;
|
||||||
use bevy_rapier2d::prelude::*;
|
use bevy_rapier2d::prelude::*;
|
||||||
use game::game_plugin;
|
use game::{game_plugin, set::IngameSet};
|
||||||
use parallax::parallax_plugin;
|
use parallax::parallax_plugin;
|
||||||
|
|
||||||
mod game;
|
mod game;
|
||||||
|
@ -13,6 +14,7 @@ const METER: f32 = 100.;
|
||||||
enum AppState {
|
enum AppState {
|
||||||
#[default]
|
#[default]
|
||||||
MainMenu,
|
MainMenu,
|
||||||
|
StoryPics,
|
||||||
InGame,
|
InGame,
|
||||||
GameOver,
|
GameOver,
|
||||||
}
|
}
|
||||||
|
@ -24,6 +26,15 @@ enum PausedState {
|
||||||
Running,
|
Running,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(States, Debug, Clone, PartialEq, Eq, Hash, Default)]
|
||||||
|
enum StoryPics {
|
||||||
|
#[default]
|
||||||
|
Pic0,
|
||||||
|
Pic1,
|
||||||
|
Pic2,
|
||||||
|
Pic3,
|
||||||
|
}
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let rapier_config = RapierConfiguration {
|
let rapier_config = RapierConfiguration {
|
||||||
scaled_shape_subdivision: 2,
|
scaled_shape_subdivision: 2,
|
||||||
|
@ -46,11 +57,110 @@ fn main() {
|
||||||
.add_plugins(parallax_plugin)
|
.add_plugins(parallax_plugin)
|
||||||
.init_state::<AppState>()
|
.init_state::<AppState>()
|
||||||
.init_state::<PausedState>()
|
.init_state::<PausedState>()
|
||||||
.insert_state(AppState::InGame) // TODO dont
|
.insert_state(AppState::StoryPics) // TODO dont
|
||||||
|
.init_state::<StoryPics>()
|
||||||
.insert_resource(rapier_config)
|
.insert_resource(rapier_config)
|
||||||
|
.configure_sets(Update, IngameSet.run_if(in_state(AppState::InGame)))
|
||||||
|
.add_systems(OnEnter(AppState::StoryPics), setup_storypics)
|
||||||
|
.add_systems(
|
||||||
|
Update,
|
||||||
|
(storypic_next_thingy, update_storypics).run_if(in_state(AppState::StoryPics)),
|
||||||
|
)
|
||||||
|
.add_systems(OnExit(AppState::StoryPics), cleanup_storypics)
|
||||||
.run();
|
.run();
|
||||||
}
|
}
|
||||||
|
|
||||||
fn setup_camera(mut commands: Commands) {
|
fn setup_camera(mut commands: Commands) {
|
||||||
commands.spawn(Camera2dBundle::default());
|
commands.spawn(Camera2dBundle::default());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Component)]
|
||||||
|
struct StoryPicMarker;
|
||||||
|
#[derive(Component)]
|
||||||
|
struct StoryPicNextBtnMarker;
|
||||||
|
|
||||||
|
fn setup_storypics(mut commands: Commands, asset_server: Res<AssetServer>) {
|
||||||
|
let pic0 = asset_server.load("SC01_Once upon a time.png");
|
||||||
|
// force preloads
|
||||||
|
let _pic1: Handle<Image> = asset_server.load("SC02_Gargels_Tower.png");
|
||||||
|
let _pic2: Handle<Image> = asset_server.load("SC03_The Egg.png");
|
||||||
|
let _pic3: Handle<Image> = asset_server.load("SC04_The Letter.png");
|
||||||
|
commands
|
||||||
|
.spawn(ImageBundle {
|
||||||
|
image: UiImage {
|
||||||
|
texture: pic0,
|
||||||
|
..Default::default()
|
||||||
|
},
|
||||||
|
style: Style {
|
||||||
|
width: Val::Percent(100.),
|
||||||
|
height: Val::Percent(100.),
|
||||||
|
|
||||||
|
justify_content: JustifyContent::End,
|
||||||
|
align_items: AlignItems::End,
|
||||||
|
..Default::default()
|
||||||
|
},
|
||||||
|
..Default::default()
|
||||||
|
})
|
||||||
|
.insert(StoryPicMarker)
|
||||||
|
.with_children(|parent| {
|
||||||
|
parent
|
||||||
|
.spawn((ButtonBundle {
|
||||||
|
..Default::default()
|
||||||
|
},))
|
||||||
|
.insert(StoryPicNextBtnMarker)
|
||||||
|
.with_children(|parent| {
|
||||||
|
parent.spawn(TextBundle::from_section(
|
||||||
|
"Weiter...",
|
||||||
|
TextStyle {
|
||||||
|
font_size: 64.,
|
||||||
|
..Default::default()
|
||||||
|
},
|
||||||
|
));
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
fn storypic_next_thingy(
|
||||||
|
interaction_query: Query<&Interaction, (Changed<Interaction>, With<StoryPicNextBtnMarker>)>,
|
||||||
|
cur_pic: Res<State<StoryPics>>,
|
||||||
|
mut pic_switcher: ResMut<NextState<StoryPics>>,
|
||||||
|
mut game_state: ResMut<NextState<AppState>>,
|
||||||
|
) {
|
||||||
|
let Ok(interaction) = interaction_query.get_single() else {
|
||||||
|
return ();
|
||||||
|
};
|
||||||
|
if *interaction == Interaction::Pressed && *cur_pic == StoryPics::Pic3 {
|
||||||
|
game_state.set(AppState::InGame);
|
||||||
|
} else if *interaction == Interaction::Pressed {
|
||||||
|
pic_switcher.set(match cur_pic.clone() {
|
||||||
|
StoryPics::Pic0 => StoryPics::Pic1,
|
||||||
|
StoryPics::Pic1 => StoryPics::Pic2,
|
||||||
|
StoryPics::Pic2 => StoryPics::Pic3,
|
||||||
|
StoryPics::Pic3 => unreachable!(),
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn update_storypics(
|
||||||
|
mut commands: Commands,
|
||||||
|
mut cur_pic: Query<&mut UiImage, With<StoryPicMarker>>,
|
||||||
|
cur_pic_state: Res<State<StoryPics>>,
|
||||||
|
asset_server: Res<AssetServer>,
|
||||||
|
) {
|
||||||
|
if cur_pic_state.is_changed() {
|
||||||
|
let mut pic = cur_pic.single_mut();
|
||||||
|
|
||||||
|
pic.texture = asset_server.load(match cur_pic_state.clone() {
|
||||||
|
StoryPics::Pic0 => "SC01_Once upon a time.png",
|
||||||
|
StoryPics::Pic1 => "SC02_Gargels_Tower.png",
|
||||||
|
StoryPics::Pic2 => "SC03_The Egg.png",
|
||||||
|
StoryPics::Pic3 => "SC04_The Letter.png",
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn cleanup_storypics(mut commands: Commands, to_delete: Query<Entity, With<StoryPicMarker>>) {
|
||||||
|
for e in &to_delete {
|
||||||
|
commands.entity(e).despawn_recursive();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue