And with that... I believe we have correctness

Animations are still a bit janky but the core gameplay loop seem secure!
main
Elijah C. Voigt 1 year ago
parent 9bb6d08d28
commit 91787dff88

@ -91,7 +91,8 @@ impl Plugin for Display3dPlugin {
pick_up.run_if(any_component_added::<game::Selected>()),
put_down.run_if(any_component_removed::<game::Selected>()),
dissolve_animation.run_if(any_with_component::<Dissolving>),
capture_piece.run_if(any_with_component::<game::BeingCaptured>),
capture_piece_start.run_if(any_component_added::<game::BeingCaptured>()),
capture_piece_end.run_if(any_component_removed::<Dissolving>()),
monitor_animations
.run_if(in_state(GameState::Play))
.run_if(any_component_changed::<AnimationPlayer>()),
@ -1160,93 +1161,38 @@ fn setup_dissolve_materials(
/// When a piece is captured...
/// 1. Play a cool "captured" animation and a neat sound
/// 2. Move the piece to the side of the board
/// 3. Play the same "captured" animation in reverse
/// The animation is like a 'beam me up scotty' sorta thing.
fn capture_piece(
events: Query<(Entity, &Dissolvable), (With<Display3d>, Added<game::BeingCaptured>)>,
mut query: Query<
(&mut Transform, &Side, &Dissolvable),
(With<Display3d>, With<game::BeingCaptured>),
>,
dissolving: Query<Entity, With<Dissolving>>,
mut state: Local<Option<game::CaptureFlow>>,
fn capture_piece_start(
events: Query<(Entity, &Dissolvable), Added<game::BeingCaptured>>,
mut commands: Commands,
score: Res<game::Score>,
mut timer: Local<f32>,
time: Res<Time>,
) {
debug!("Running capture piece routine");
match *state {
// State is None, so we need to initiate the animation
None => {
*state = events.iter().next().map(|(entity, dissolvable)| {
// Insert the "Dissolving::Out" tag on the entity we want to fade out
events.iter().for_each(|(entity, dissolvable)| {
commands
.entity(entity)
.insert(Dissolving::Out(dissolvable.duration));
// Set the next state to start fading out
game::CaptureFlow::FadeOut(entity)
});
}
Some(s) => {
match s {
game::CaptureFlow::FadeOut(_entity) => {
// Wait for fade-out animation
// If all pieces are done dissolving
if dissolving.is_empty() && *timer >= 3.0 {
debug!("Nothing dissolving, moving on to next step!");
// reset the timer
*timer = 0.0;
// Move to next state now that animation is done
*state = s.next();
// This takes effect after updating all children
} else {
*timer += time.delta_seconds();
}
}
game::CaptureFlow::Store(entity) => {
let (mut t, side, dissolvable) = query
.get_mut(entity)
.expect("Visibility and Transform of captured piece");
// HACK: This is dirty. Why side, but score.captures(!side)?
debug!(
"Capture translation: ({:?}, {:?}) {:?}",
side,
score.captures(!*side).saturating_sub(1),
t.translation
);
debug!("Setting translation for captured piece {:?}", entity);
t.translation =
capture_translation(side, score.captures(!*side).saturating_sub(1));
commands
.entity(entity)
.insert(Dissolving::In(dissolvable.duration));
*state = s.next();
}
game::CaptureFlow::FadeIn(entity) => {
// If we have completed the dissolve-in animation
if dissolving.is_empty() {
debug!("Nothing dissolving, moving on to next step!");
/// Once done fading out:
/// 1. Move piece to side of board
/// 2. Remove BeingCaptured component
/// 3. Add Captured marker
fn capture_piece_end(
mut events: RemovedComponents<Dissolving>,
mut query: Query<(Entity, &Dissolvable, &Side, &mut Transform), With<BeingCaptured>>,
mut commands: Commands,
score: Res<game::Score>,
) {
events.read().for_each(|e| {
if let Ok((entity, dissolvable, side, mut transform)) = query.get_mut(e) {
transform.translation = capture_translation(side, score.captures(!*side));
// Update the 'BeingCaptured' -> 'Captured' status
commands
.entity(entity)
.insert(Captured)
.remove::<BeingCaptured>();
// Move to next state now that animation is done
*state = s.next();
}
}
}
}
.insert(Dissolving::In(dissolvable.duration))
.remove::<BeingCaptured>()
.insert(Captured);
}
});
}
fn debug_selected(

@ -247,29 +247,6 @@ pub(crate) struct Move {
pub move_type: MoveType,
}
/// Enum for the Capture event flow
#[derive(Debug, Clone, Copy, Resource)]
pub(crate) enum CaptureFlow {
// Run the "fade out" animation
FadeOut(Entity),
// Put the captured piece next to the board
Store(Entity),
// Run the "fade in" animation
FadeIn(Entity),
}
impl CaptureFlow {
/// The capture flow so we can move from one "capture flow state" to the next
/// Fade out, then store, then fade in
pub(crate) fn next(&self) -> Option<Self> {
match self {
Self::FadeOut(e) => Some(Self::Store(*e)),
Self::Store(e) => Some(Self::FadeIn(*e)),
Self::FadeIn(_) => None,
}
}
}
#[derive(Debug, Component, PartialEq, Clone, Default, Copy, Eq, Hash)]
pub(crate) struct BoardIndex {
pub x: usize,

Loading…
Cancel
Save