Skip to content

Commit

Permalink
Throw de-jank attempt 1
Browse files Browse the repository at this point in the history
  • Loading branch information
haihala committed Dec 28, 2023
1 parent a94d3ee commit c93dfe2
Show file tree
Hide file tree
Showing 22 changed files with 314 additions and 262 deletions.
38 changes: 37 additions & 1 deletion client/characters/src/actions/action.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ use bevy::prelude::*;
use wag_core::Animation;

use crate::{
ActionBlock, ActionRequirement, Attack, CancelCategory, CancelRule, ContinuationRequirement,
ActionBlock, ActionEvent, ActionRequirement, AnimationRequest, Attack, CancelCategory,
CancelRule, ContinuationRequirement, FlashRequest, ResourceType,
};

#[derive(Clone)]
Expand Down Expand Up @@ -66,6 +67,41 @@ impl Action {
)
}

pub fn throw_target(
animation: impl Into<Animation>,
duration: usize,
damage: i32,
launch_impulse: Vec2,
) -> Self {
Action::new(
None,
CancelCategory::Uncancellable,
vec![ActionBlock {
events: vec![
ActionEvent::Animation(AnimationRequest {
animation: animation.into(),
invert: true,
..default()
}),
ActionEvent::ModifyResource(ResourceType::Health, -damage),
if launch_impulse == Vec2::ZERO {
ActionEvent::Noop
} else {
ActionEvent::Launch {
impulse: launch_impulse,
}
},
ActionEvent::Flash(FlashRequest::hit_flash()),
ActionEvent::Hitstop,
ActionEvent::Lock(duration),
],
exit_requirement: ContinuationRequirement::Time(duration),
..default()
}],
vec![],
)
}

pub fn ground_normal(
input: &'static str,
animation: impl Into<Animation>,
Expand Down
18 changes: 1 addition & 17 deletions client/characters/src/actions/action_block.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
use crate::{ActionEvent, ActionRequirement, CancelRule, FlashRequest, ResourceType, Situation};
use bevy::prelude::*;
use crate::{ActionEvent, ActionRequirement, CancelRule, Situation};

#[derive(Clone, Debug, PartialEq)]
pub struct ActionBlock {
Expand All @@ -26,21 +25,6 @@ impl ActionBlock {
self.clone()
}
}

pub fn throw_target(damage: i32, launch_impulse: Vec2) -> Self {
Self {
events: vec![
ActionEvent::ModifyResource(ResourceType::Health, -damage),
ActionEvent::Launch {
// This may be broken, but it may have been fixed while
// fixing flipping launch velocities
impulse: launch_impulse,
},
ActionEvent::Flash(FlashRequest::hit_flash()),
],
..default()
}
}
}

#[derive(Clone, Debug, Default, PartialEq)]
Expand Down
1 change: 1 addition & 0 deletions client/characters/src/actions/action_event.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ pub enum ActionEvent {
CameraTilt(Vec2),
CameraShake, // TODO: Add strength
Flash(FlashRequest),
Lock(usize),
Noop, // makes writing macros easier
}
impl ActionEvent {
Expand Down
59 changes: 8 additions & 51 deletions client/characters/src/characters/mizku.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use wag_core::{
};

use crate::{
actions::{ActionRequirement, AnimationRequest, Projectile},
actions::{ActionRequirement, Projectile},
resources::{RenderInstructions, ResourceType},
Action, ActionBlock,
ActionEvent::*,
Expand Down Expand Up @@ -493,23 +493,7 @@ fn normals() -> impl Iterator<Item = (MizkuActionId, Action)> {
),
(
MizkuActionId::StandThrowTarget,
Action::grounded(
None,
CancelCategory::Uncancellable,
vec![
ActionBlock {
events: vec![AnimationRequest {
animation: MizkuAnimation::StandThrowTarget.into(),
invert: true,
..default()
}
.into()],
exit_requirement: ContinuationRequirement::Time(20),
..default()
},
ActionBlock::throw_target(10, Vec2::new(2.0, 3.0)),
],
),
Action::throw_target(MizkuAnimation::StandThrowTarget, 20, 10, Vec2::ZERO),
),
(
MizkuActionId::CrouchThrow,
Expand Down Expand Up @@ -547,22 +531,11 @@ fn normals() -> impl Iterator<Item = (MizkuActionId, Action)> {
),
(
MizkuActionId::CrouchThrowTarget,
Action::grounded(
None,
CancelCategory::Uncancellable,
vec![
ActionBlock {
events: vec![AnimationRequest {
animation: MizkuAnimation::CrouchThrowTarget.into(),
invert: true,
..default()
}
.into()],
exit_requirement: ContinuationRequirement::Time(20),
..default()
},
ActionBlock::throw_target(10, Vec2::new(-2.0, 3.0)),
],
Action::throw_target(
MizkuAnimation::CrouchThrowTarget,
21,
10,
Vec2::new(-5.0, 2.0),
),
),
(
Expand Down Expand Up @@ -601,23 +574,7 @@ fn normals() -> impl Iterator<Item = (MizkuActionId, Action)> {
),
(
MizkuActionId::AirThrowTarget,
Action::airborne(
None,
CancelCategory::Uncancellable,
vec![
ActionBlock::throw_target(10, Vec2::new(-2.0, 2.0)),
ActionBlock {
events: vec![AnimationRequest {
animation: MizkuAnimation::AirThrowTarget.into(),
invert: true,
..default()
}
.into()],
exit_requirement: ContinuationRequirement::Time(60),
..default()
},
],
),
Action::throw_target(MizkuAnimation::AirThrowTarget, 3, 10, Vec2::new(-2.0, 2.0)),
),
]
.into_iter()
Expand Down
6 changes: 3 additions & 3 deletions client/input_parsing/src/input_stream/parrot_stream.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,15 @@ impl ParrotStream {
pub fn cycle(&mut self) {
self.mode = match self.mode {
ParrotMode::Listening => {
dbg!("Starting playback.");
println!("Starting playback.");
ParrotMode::Repeating
}
ParrotMode::Repeating => {
dbg!("Entered direct control mode.");
println!("Entered direct control mode.");
ParrotMode::Noop
}
ParrotMode::Noop => {
dbg!("Starting recording.");
println!("Starting recording.");
self.buffer = vec![];
self.buffer_index = 0;
ParrotMode::Listening
Expand Down
4 changes: 2 additions & 2 deletions client/lib/src/assets/models.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ pub fn prep_player_gltf(
for (entity, parent, name, instance, update_material) in &unloaded_instances {
if scene_manager.instance_is_ready(**instance) {
cmds.entity(entity).remove::<PlayerModelHook>();
dbg!("Scene is ready");
println!("Scene is ready");
assign_joints(
name.cloned().unwrap_or_default().as_str(),
entity,
Expand All @@ -54,7 +54,7 @@ pub fn prep_player_gltf(
&children,
&names,
);
dbg!("Joints are ready");
println!("Joints are ready");
}

// Iterate over all entities in scene (once it's loaded)
Expand Down
2 changes: 1 addition & 1 deletion client/lib/src/damage/hitboxes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ impl HitboxSpawner {
}
}

pub(super) fn spawn_new(
pub(super) fn spawn_new_hitboxes(
mut commands: Commands,
clock: Res<Clock>,
models: Res<Models>,
Expand Down
8 changes: 6 additions & 2 deletions client/lib/src/damage/hitreg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -412,13 +412,13 @@ pub(super) fn snap_and_switch(
});

if actions.contains(&ActionEvent::SnapToOpponent) {
let switch = actions.contains(&ActionEvent::SideSwitch) as i32 as f32;
let switch = actions.contains(&ActionEvent::SideSwitch);

let raw_diff = self_tf.translation.x - other_tf.translation.x; // This ought to be positive when attacker is on the left
let width_between = (self_pushbox.width() + other_pushbox.width()) / 2.0;

let new_position = other_tf.translation
+ Vec3::X * raw_diff.signum() * width_between * (1.0 - (2.0 * switch));
+ Vec3::X * raw_diff.signum() * width_between * (if switch { -1.0 } else { 1.0 });

self_tf.translation = new_position;
self_velocity.sync_with(&other_velocity);
Expand All @@ -431,6 +431,10 @@ pub(super) fn stun_actions(
clock: Res<Clock>,
) {
for (mut state, mut velocity, facing) in &mut query {
if state.unlock_frame().is_some() {
continue;
}

for action in state.drain_matching_actions(|action| {
if matches!(
*action,
Expand Down
2 changes: 1 addition & 1 deletion client/lib/src/damage/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ impl Plugin for DamagePlugin {
app.add_systems(
Update,
(
hitboxes::spawn_new,
hitboxes::spawn_new_hitboxes,
hitreg::clash_parry,
hitreg::detect_hits.pipe(hitreg::apply_hits),
hitreg::stun_actions,
Expand Down
6 changes: 4 additions & 2 deletions client/lib/src/dev/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ fn setup(mut config: ResMut<GizmoConfig>) {

fn shader_test_system(keys: Res<Input<KeyCode>>, mut players: Query<&mut PlayerState>) {
if keys.just_pressed(KeyCode::S) {
dbg!("Playing shader flash");
println!("Playing shader flash");
for mut player in &mut players {
player.add_actions(vec![ActionEvent::Flash(FlashRequest {
color: GI_PARRY_FLASH_COLOR,
Expand All @@ -75,14 +75,15 @@ fn shader_test_system(keys: Res<Input<KeyCode>>, mut players: Query<&mut PlayerS

fn audio_test_system(keys: Res<Input<KeyCode>>, mut sounds: ResMut<Sounds>) {
if keys.just_pressed(KeyCode::A) {
dbg!("Playing whoosh audio");
println!("Playing whoosh audio");
sounds.play(SoundEffect::Whoosh);
}
}

fn fullscreen_toggle(keys: Res<Input<KeyCode>>, mut windows: Query<&mut Window>) {
if keys.just_pressed(KeyCode::F) {
let mut win = windows.get_single_mut().unwrap();
println!("Fullscreen toggle");

win.mode = match win.mode {
WindowMode::Windowed => WindowMode::BorderlessFullscreen,
Expand All @@ -94,6 +95,7 @@ fn fullscreen_toggle(keys: Res<Input<KeyCode>>, mut windows: Query<&mut Window>)

fn pause_toggle(keys: Res<Input<KeyCode>>, mut time: ResMut<Time<Virtual>>) {
if keys.just_pressed(KeyCode::P) {
println!("Pause toggle");
let new_speed = 1.0 - time.relative_speed();
time.set_relative_speed(new_speed);
}
Expand Down
19 changes: 19 additions & 0 deletions client/lib/src/physics/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,10 @@ fn player_gravity(
)>,
) {
for (mut velocity, mut state, mut spawner, tf, stats) in &mut players {
if state.unlock_frame().is_some() {
continue;
}

let is_airborne = tf.translation.y > GROUND_PLANE_HEIGHT;

if is_airborne {
Expand All @@ -96,6 +100,10 @@ fn player_input(
mut query: Query<(&mut PlayerState, &mut PlayerVelocity, &Stats, &Facing)>,
) {
for (mut state, mut velocity, status_effects, facing) in &mut query {
if state.unlock_frame().is_some() {
continue;
}

for _ in state.drain_matching_actions(|action| {
if ActionEvent::ClearMovement == *action {
Some(())
Expand Down Expand Up @@ -140,12 +148,19 @@ struct PlayerMovingQuery<'a> {

fn move_players(mut query: Query<PlayerMovingQuery>) {
for mut p in &mut query {
if p.state.unlock_frame().is_some() {
continue;
}
p.tf.translation += p.velocity.get_shift().extend(0.0);
}
}

fn push_players(mut query: Query<PlayerMovingQuery>, players: Res<Players>) {
if let Ok([p1, p2]) = query.get_many_mut([players.one, players.two]) {
if p1.state.unlock_frame().is_some() || p2.state.unlock_frame().is_some() {
return;
}

if let Some(overlap) = p1
.push_box
.with_offset(p1.tf.translation.truncate())
Expand Down Expand Up @@ -195,6 +210,10 @@ fn clamp_players(
let right_border = camera_x + VIEWPORT_HALFWIDTH - CAMERA_EDGE_COLLISION_PADDING;

if let Ok([mut p1, mut p2]) = queries.p0().get_many_mut([players.one, players.two]) {
if p1.state.unlock_frame().is_some() || p2.state.unlock_frame().is_some() {
return;
}

// Either neither or both should be pushing
assert!(p1.velocity.pushing == p2.velocity.pushing);
let pushing = p1.velocity.pushing || p2.velocity.pushing;
Expand Down
38 changes: 38 additions & 0 deletions client/lib/src/player/locks.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
use bevy::prelude::*;
use characters::ActionEvent;
use player_state::PlayerState;
use wag_core::{Clock, Joint, Joints};

pub fn handle_locks(
mut players: Query<(&mut PlayerState, Entity, &Joints)>,
clock: Res<Clock>,
mut tfs: Query<&mut Transform>,
) {
for (mut state, player_entity, joints) in &mut players {
if let Some(unlock_frame) = state.unlock_frame() {
if unlock_frame <= clock.frame {
// Move the player by abdomen joint transform to snap the character where the model is
let model = joints.nodes.get(&Joint::Abdomen).unwrap();
let [model_tf, mut player_tf] = tfs.get_many_mut([*model, player_entity]).unwrap();
player_tf.translation -= Vec3 {
// This is a hack, as there is no good bone to base the offset on
x: model_tf.translation.x,
y: model_tf.translation.y - 0.95,
z: 0.0,
};

state.unlock(player_tf.translation.y > 0.1);
}
}

for duration in state.drain_matching_actions(|action| {
if let ActionEvent::Lock(frames) = action {
Some(frames.to_owned())
} else {
None
}
}) {
state.lock(duration + clock.frame);
}
}
}
Loading

0 comments on commit c93dfe2

Please sign in to comment.