Start integrating asset loading and animations
This commit is contained in:
+16
-2
@@ -6,14 +6,15 @@ use std::ops::{Index, IndexMut};
|
||||
|
||||
use bevy::prelude::*;
|
||||
use bevy_ggrs::{PlayerInputs, Rollback};
|
||||
use strum::IntoEnumIterator;
|
||||
use strum_macros::EnumIter;
|
||||
|
||||
use crate::game_settings::GameSettings;
|
||||
use crate::input::FighterInputFrame;
|
||||
use crate::netcode::GGRSCfg;
|
||||
use crate::player::Player;
|
||||
|
||||
struct FighterInputBufferedActions {}
|
||||
|
||||
#[derive(Clone, Copy, EnumIter)]
|
||||
pub enum FighterCommands {
|
||||
SmashMoveLeft,
|
||||
SmashMoveRight,
|
||||
@@ -85,6 +86,10 @@ impl FighterInput {
|
||||
pub fn has_command(&self, command: FighterCommands) -> bool {
|
||||
self.command_lifetimes[command] > 0
|
||||
}
|
||||
|
||||
pub fn reduce_command_lifetime(&mut self, command: FighterCommands) {
|
||||
self.command_lifetimes[command] = self.command_lifetimes[command].saturating_sub(1);
|
||||
}
|
||||
}
|
||||
|
||||
/// Turns this frame's rolled-back inputs into per-fighter [`FighterInput`]
|
||||
@@ -95,6 +100,11 @@ pub fn postprocess_input(
|
||||
game_settings: Res<GameSettings>,
|
||||
) {
|
||||
for (mut input, player) in query {
|
||||
|
||||
for command in FighterCommands::iter() {
|
||||
input.reduce_command_lifetime(command);
|
||||
}
|
||||
|
||||
input.push_input_frame(inputs[player.handle].0);
|
||||
|
||||
// Directional smash detection
|
||||
@@ -117,6 +127,10 @@ pub fn postprocess_input(
|
||||
}
|
||||
}
|
||||
|
||||
if !input.prev_frame.jump && input.current_frame.jump {
|
||||
input.set_lifetime(FighterCommands::Jump, game_settings.input_common.input_buffer_size);
|
||||
}
|
||||
|
||||
if x_abs >= axis_threshold && input.frames_in_smash_move_deadzone <= frame_threshold {
|
||||
input.clear_command(FighterCommands::SmashMoveLeft);
|
||||
input.clear_command(FighterCommands::SmashMoveRight);
|
||||
|
||||
+2
-1
@@ -1,7 +1,7 @@
|
||||
use bevy::prelude::*;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use crate::math::vec::FGVec2;
|
||||
use crate::{input::InputActionState, math::vec::FGVec2};
|
||||
|
||||
/// One frame of a player's raw input. This is the type GGRS serializes and
|
||||
/// sends over the wire, so keep it small and keep it `PartialEq`.
|
||||
@@ -9,4 +9,5 @@ use crate::math::vec::FGVec2;
|
||||
pub struct FighterInputFrame {
|
||||
pub movement: FGVec2,
|
||||
pub directional_attack: FGVec2,
|
||||
pub jump: bool
|
||||
}
|
||||
|
||||
@@ -44,7 +44,9 @@ pub fn preprocess_keyboard_input(
|
||||
InputMapAction::MovementYDir(sign) => {
|
||||
input_frame.movement.y += (sign) * action_strength
|
||||
}
|
||||
InputMapAction::Jump => todo!(),
|
||||
InputMapAction::Jump => {
|
||||
input_frame.jump = action_strength != FGi32::ZERO
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+3
-1
@@ -3,12 +3,14 @@
|
||||
//! decides how to read it.
|
||||
|
||||
use bevy::prelude::*;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
#[derive(Debug)]
|
||||
#[derive(Debug, Serialize, Deserialize, Copy, Clone, PartialEq, Default)]
|
||||
pub enum InputActionState {
|
||||
JustPressed,
|
||||
Pressed,
|
||||
JustReleased,
|
||||
#[default]
|
||||
Released,
|
||||
}
|
||||
|
||||
|
||||
@@ -39,6 +39,11 @@ impl Plugin for FighterInputPlugin {
|
||||
key: KeyCode::KeyA,
|
||||
action: InputMapAction::MovementXDir(-1),
|
||||
},
|
||||
// jump
|
||||
KeyboardInputMapElement {
|
||||
key: KeyCode::Space,
|
||||
action: InputMapAction::Jump,
|
||||
},
|
||||
],
|
||||
})
|
||||
.add_systems(ReadInputs, keyboard::preprocess_keyboard_input)
|
||||
|
||||
Reference in New Issue
Block a user