Skip to content
This repository has been archived by the owner on Oct 24, 2024. It is now read-only.

Commit

Permalink
Going to bed plays out an animation (#139)
Browse files Browse the repository at this point in the history
* Going to bed plays out an animation

* After sleeping, Winnie spawns in the bathroom and the daybar is reset
  • Loading branch information
porkbrain authored Apr 26, 2024
1 parent aff1d22 commit ef1f916
Show file tree
Hide file tree
Showing 13 changed files with 541 additions and 142 deletions.
511 changes: 417 additions & 94 deletions Cargo.lock

Large diffs are not rendered by default.

10 changes: 4 additions & 6 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ members = [


[workspace.dependencies.bevy]
version = "=0.13.1"
version = "=0.13.2"
default-features = false
features = [
"bevy_asset",
Expand All @@ -48,11 +48,9 @@ features = [
[workspace.dependencies]
bevy_pixel_camera = "0.13"
bevy_webp_anim = "0.3"
bevy-inspector-egui = { version = "0.23", default-features = false }
bevy-inspector-egui = { version = "0.24", default-features = false }
leafwing-input-manager = "0.13"
# Upgrade to 0.26.0 panics:
# > Error adding plugin bevy_egui::EguiPlugin: : plugin was already added in application
bevy_egui = "0.25"
bevy_egui = "0.27"

scene_building1_basement1 = { path = "scenes/building1_basement1" }
scene_building1_player_floor = { path = "scenes/building1_player_floor" }
Expand All @@ -72,7 +70,7 @@ common_story = { path = "common/story" }
common_visuals = { path = "common/visuals" }
main_game_lib = { path = "main_game_lib" }

graphviz-rust = "0.8"
graphviz-rust = "0.9"
itertools = "0.12"
lazy_static = "1.4"
logos = "0.14"
Expand Down
4 changes: 4 additions & 0 deletions common/assets/src/paths.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,10 @@ pub mod misc {
"misc/loading_screens/bunny_atlas.png";
pub const LOADING_SCREEN_SPACE_ATLAS: &str =
"misc/loading_screens/space_atlas.png";
pub const LOADING_SCREEN_WINNIE_IN_BATHROOM_ATLAS: &str =
"misc/loading_screens/winnie_in_bathroom_atlas.png";
pub const LOADING_SCREEN_HEDGEHOG_ATLAS: &str =
"misc/loading_screens/hedgehog_atlas.png";
}

pub const EMOJI_ATLAS: &str = "misc/emoji_atlas.png";
43 changes: 36 additions & 7 deletions common/loading_screen/src/atlases.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,41 +9,70 @@ use common_visuals::{AtlasAnimation, AtlasAnimationEnd, AtlasAnimationTimer};

/// All available loading screens animations.
#[allow(missing_docs)]
#[derive(Debug, Clone, Reflect, Default, Copy, strum::VariantArray)]
#[derive(Debug, Clone, Reflect, Default, Copy)]
pub enum LoadingScreenAtlas {
#[default]
Bunny,
Space,
Hedgehog,

/// Special loading screen for after sleep transition.
WinnieInBathroom,
}

impl LoadingScreenAtlas {
/// Picks a random loading screen.
pub fn random() -> Self {
use strum::VariantArray;
let variants = &[Self::Hedgehog, Self::Bunny, Self::Space];

Self::VARIANTS[rand::random::<usize>() % Self::VARIANTS.len()]
variants[rand::random::<usize>() % variants.len()]
}

pub(crate) fn asset_path(self) -> &'static str {
match self {
Self::Bunny => common_assets::misc::LOADING_SCREEN_BUNNY_ATLAS,
Self::Space => common_assets::misc::LOADING_SCREEN_SPACE_ATLAS,
Self::WinnieInBathroom => {
common_assets::misc::LOADING_SCREEN_WINNIE_IN_BATHROOM_ATLAS
}
Self::Hedgehog => {
common_assets::misc::LOADING_SCREEN_HEDGEHOG_ATLAS
}
}
}

pub(crate) fn thingies(
self,
) -> (TextureAtlasLayout, AtlasAnimation, AtlasAnimationTimer) {
let (columns, tile_size, fps) = match self {
Self::Bunny => (26, vec2(210.0, 135.0), 7.0),
Self::Space => (12, vec2(350.0, 190.0), 7.0),
let (columns, tile_size, fps, on_last_frame) = match self {
Self::Bunny => (
26,
vec2(210.0, 135.0),
7.0,
AtlasAnimationEnd::LoopIndefinitely,
),
Self::Space => (
12,
vec2(350.0, 190.0),
7.0,
AtlasAnimationEnd::LoopIndefinitely,
),
Self::WinnieInBathroom => {
(11, vec2(122.0, 121.0), 3.0, AtlasAnimationEnd::RemoveTimer)
}
Self::Hedgehog => (
8,
vec2(122.0, 206.0),
2.0,
AtlasAnimationEnd::LoopIndefinitely,
),
};

(
TextureAtlasLayout::from_grid(tile_size, columns, 1, None, None),
AtlasAnimation {
last: columns - 1,
on_last_frame: AtlasAnimationEnd::LoopIndefinitely,
on_last_frame,
..default()
},
AtlasAnimationTimer::new_fps(fps),
Expand Down
5 changes: 5 additions & 0 deletions main_game/assets/scenes/building1_player_floor.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -605,6 +605,11 @@ texture = ExtResource("23_kalpq")

[node name="Points" type="Node2D" parent="."]

[node name="AfterSleepSpawn" type="Node2D" parent="Points"]
position = Vector2(-144, -58)

[node name="Point" type="Node" parent="Points/AfterSleepSpawn"]

[node name="MeditationSpawn" type="Node2D" parent="Points"]
position = Vector2(25, -60)

Expand Down
1 change: 1 addition & 0 deletions main_game_lib/src/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ pub enum GlobalGameStateTransition {
Building1PlayerFloorToMeditation,
Building1PlayerFloorToDowntown,
Building1PlayerFloorToBuilding1Basement1,
Sleeping,

Building1Basement1ToPlayerFloor,
Building1Basement1ToDowntown,
Expand Down
4 changes: 2 additions & 2 deletions main_game_lib/src/top_down/actor/npc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ pub enum BehaviorResult {
}

/// A behavior tree can be attached to an NPC to drive its actions.
#[derive(Debug, Component, Reflect)]
#[derive(Debug, Component)]
pub struct BehaviorTree {
/// The zeroth element is the root node.
/// The last element is the currently visited node.
Expand All @@ -75,7 +75,7 @@ pub struct BehaviorTree {
/// Nodes can carry state.
/// When a node is visited for the first time, it is cloned and pushed onto the
/// stack.
#[derive(Debug, Clone, Reflect)]
#[derive(Debug, Clone)]
pub enum BehaviorNode {
/// Composite node that runs one child after another.
/// Exits with failed if any child fails, otherwise succeeds.
Expand Down
92 changes: 60 additions & 32 deletions scenes/building1_player_floor/src/actor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ impl bevy::app::Plugin for Plugin {
app.add_systems(
Update,
(
start_meditation_minigame
(start_meditation_minigame, sleep)
.before(DisplayEmojiEventConsumer)
.before(ChangeHighlightedInspectLabelEventConsumer),
enter_the_elevator,
Expand Down Expand Up @@ -72,39 +72,39 @@ fn start_meditation_minigame(
matches!(action, Building1PlayerFloorAction::StartMeditation)
});

if is_triggered {
if daybar.is_depleted() {
if let Some(entity) = zone_to_inspect_label_entity
.map
.get(&Building1PlayerFloorTileKind::MeditationZone)
.copied()
{
inspect_label_events.send(ChangeHighlightedInspectLabelEvent {
entity,
spawn_params: SpawnLabelBgAndTextParams {
highlighted: true,
overwrite_font_color: Some(LIGHT_RED),
// LOCALIZATION
overwrite_display_text: Some("(too tired)".to_string()),
},
});
} else {
error!("Cannot find meditation zone inspect label entity");
}

if let Some(on_parent) = player.get_single_or_none() {
emoji_events.send(DisplayEmojiEvent {
emoji: EmojiKind::Tired,
on_parent,
offset_for: common_story::Character::Winnie,
});
} else {
error!("Cannot find player entity");
}

return;
if !is_triggered {
return;
}

if daybar.is_depleted() {
if let Some(entity) = zone_to_inspect_label_entity
.map
.get(&Building1PlayerFloorTileKind::MeditationZone)
.copied()
{
inspect_label_events.send(ChangeHighlightedInspectLabelEvent {
entity,
spawn_params: SpawnLabelBgAndTextParams {
highlighted: true,
overwrite_font_color: Some(LIGHT_RED),
// LOCALIZATION
overwrite_display_text: Some("(too tired)".to_string()),
},
});
} else {
error!("Cannot find meditation zone inspect label entity");
}

if let Some(on_parent) = player.get_single_or_none() {
emoji_events.send(DisplayEmojiEvent {
emoji: EmojiKind::Tired,
on_parent,
offset_for: common_story::Character::Winnie,
});
} else {
error!("Cannot find player entity");
}
} else {
cmd.insert_resource(LoadingScreenSettings {
atlas: Some(common_loading_screen::LoadingScreenAtlas::Space),
stare_at_loading_screen_for_at_least: Some(
Expand Down Expand Up @@ -207,3 +207,31 @@ fn toggle_zone_hints(
}
}
}

fn sleep(
mut cmd: Commands,
mut action_events: EventReader<Building1PlayerFloorAction>,
mut transition: ResMut<GlobalGameStateTransition>,
mut next_state: ResMut<NextState<GlobalGameState>>,
) {
let is_triggered = action_events
.read()
.any(|action| matches!(action, Building1PlayerFloorAction::Sleep));

if !is_triggered {
return;
}

cmd.insert_resource(LoadingScreenSettings {
atlas: Some(
common_loading_screen::LoadingScreenAtlas::WinnieInBathroom,
),
stare_at_loading_screen_for_at_least: Some(
WINNIE_IN_BATHROOM_TRANSITION_FOR_AT_LEAST,
),
..default()
});

*transition = GlobalGameStateTransition::Sleeping;
next_state.set(Building1PlayerFloor::quitting());
}
7 changes: 6 additions & 1 deletion scenes/building1_player_floor/src/layout.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
mod watch_entry_to_hallway;

use bevy::render::view::RenderLayers;
use bevy_grid_squared::sq;
use bevy_grid_squared::{sq, GridDirection};
use common_visuals::camera::render_layer;
use main_game_lib::{
cutscene::enter_an_elevator::{
Expand Down Expand Up @@ -229,6 +229,11 @@ impl<'a> TscnSpawner for Spawner<'a> {
self.player_builder
.initial_step_time(STEP_TIME_ON_EXIT_ELEVATOR);
}
"AfterSleepSpawn" if self.transition == Sleeping => {
self.player_builder.initial_position(translation.truncate());
self.player_builder.initial_direction(GridDirection::Top);
self.daybar_event.send(IncreaseDayBarEvent::Reset);
}
_ => {}
}
}
Expand Down
3 changes: 3 additions & 0 deletions scenes/building1_player_floor/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,9 @@ fn smooth_exit(
Building1PlayerFloorToDowntown => {
next_state.set(GlobalGameState::LoadingDowntown);
}
Sleeping => {
next_state.set(GlobalGameState::LoadingBuilding1PlayerFloor);
}
_ => {
unreachable!(
"Invalid Building1PlayerFloor transition {transition:?}"
Expand Down
3 changes: 3 additions & 0 deletions scenes/building1_player_floor/src/prelude.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ pub(crate) const START_LOADING_SCREEN_AFTER: Duration = from_millis(500);
/// fading to happen.
pub(crate) const WHEN_ENTERING_MEDITATION_SHOW_LOADING_IMAGE_FOR_AT_LEAST:
Duration = from_millis(1500);
/// Hard coded to make the animation play out.
pub(crate) const WINNIE_IN_BATHROOM_TRANSITION_FOR_AT_LEAST: Duration =
from_millis(3500);

/// Walk down slowly otherwise it'll happen before the player even sees it.
pub(crate) const STEP_TIME_ONLOAD_FROM_MEDITATION: Duration = from_millis(750);

0 comments on commit ef1f916

Please sign in to comment.