Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New Fighter State Design and Gameplay Refactor #203

Merged
merged 45 commits into from
Aug 9, 2022
Merged
Show file tree
Hide file tree
Changes from 42 commits
Commits
Show all changes
45 commits
Select commit Hold shift + click to select a range
d8860bb
WIP New Fighter State Design
zicklag Aug 3, 2022
2e364ce
Migrate to Using Generic CustomCommands Type
zicklag Aug 3, 2022
9d9f0a5
Remove Custom Stage For Flushing State Transitions
zicklag Aug 3, 2022
a14a832
Re-enable The bevy_gilrs Feature
zicklag Aug 3, 2022
2634e4a
Work Around Flop Input Not Being Detected
zicklag Aug 3, 2022
593cdf7
Implement Player Movement Constraints
zicklag Aug 3, 2022
ecc29ef
Tidy Up Movement Plugin
zicklag Aug 3, 2022
caca50c
Remove Debugging Stuff From fighter_state.rs
zicklag Aug 3, 2022
dc6fe88
Re-enable Debug Feature and Remove Some Git Deps
zicklag Aug 3, 2022
ac6ac0d
Bring Back Flop Movement and Sound
zicklag Aug 3, 2022
d48784f
Add the KnockedBack State
zicklag Aug 3, 2022
629f8c8
Remove Orphaned KnockBack Implementation
zicklag Aug 3, 2022
689d43b
Re-implement Enemy Targeting and Attacking
zicklag Aug 4, 2022
6aac206
Move Enemy Intent Collector to AI Module
zicklag Aug 4, 2022
5fcfe94
Rename Velocity and Torque Components
zicklag Aug 4, 2022
909650a
Minor Tweaks
zicklag Aug 4, 2022
ddd7fa5
Add Debug Name to Map Items
zicklag Aug 4, 2022
2ab8d8e
Move Around Stats and Add Health Component
zicklag Aug 4, 2022
baeabe5
Fix Hud to Read New Health Component
zicklag Aug 4, 2022
3ec8061
Re-Implement and Organize Attack Damage
zicklag Aug 4, 2022
90c89cc
Reduce Enemy Damage
zicklag Aug 4, 2022
b2c0429
Document And Move Damage System to PostUpdate
zicklag Aug 4, 2022
4362274
Implement Attack Knockback
zicklag Aug 4, 2022
4f60733
Additive States In Preparation For Item Throwing
zicklag Aug 4, 2022
355930c
Rename collisions.rs to collision.rs
zicklag Aug 5, 2022
c622357
Add Helper Methods For Fighter State Transitions
zicklag Aug 5, 2022
9d78207
Add Inventory Component
zicklag Aug 5, 2022
4c77b16
Add Force, Torque, and Lifetime Components
zicklag Aug 5, 2022
84d6add
Move `pause` and `unpause` Systems to the ui Module
zicklag Aug 5, 2022
b0ce837
Move YSort into Camera Module
zicklag Aug 5, 2022
cab341d
Increase Player Health
zicklag Aug 5, 2022
ec264a0
Implement Item Grabbing
zicklag Aug 5, 2022
cae3a05
Implement Thrown Item Damage
zicklag Aug 5, 2022
771b821
Delete orphans.rs
zicklag Aug 5, 2022
fc73ac2
Allow Toggling Damageable
zicklag Aug 6, 2022
d821b1a
Re-Apply Changes From #198
zicklag Aug 6, 2022
81f9bed
Re-apply Changes From #202
zicklag Aug 6, 2022
a720880
Fix Fighter Movement Velocity
zicklag Aug 6, 2022
1e7031b
Make Sure Camera Moves After Players Move
zicklag Aug 6, 2022
927f2cb
Remove Custom Stages
zicklag Aug 7, 2022
39c3e45
Re-add Attack Y Position Correction
zicklag Aug 7, 2022
728acc2
Remove Custom Command Queues
zicklag Aug 7, 2022
0ef5cd6
Remove Overdone and Unneeded Commands Module
zicklag Aug 9, 2022
9b9ffb2
Minor Tweaks to Comments and Names
zicklag Aug 9, 2022
ec820c3
Add a TODO About Knockback and Impulse
zicklag Aug 9, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
262 changes: 257 additions & 5 deletions Cargo.lock

Large diffs are not rendered by default.

15 changes: 8 additions & 7 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ default-features = false
features = [
"x11",
"png",
"filesystem_watcher"
"filesystem_watcher",
"bevy_gilrs"
]

[dependencies]
Expand All @@ -38,7 +39,7 @@ structopt = "0.3.26"
rand = "0.8.5"
getrandom = { version = "0.2", features = ["js"] }

leafwing_input_manager = { git = "https://github.com/Leafwing-Studios/leafwing-input-manager.git", default-features = false, branch = "dev" }
leafwing-input-manager = { version = "0.5", default-features = false }
unic-langid = "0.9.0"
bevy_fluent = { git = "https://github.com/kgv/bevy_fluent.git" }
sys-locale = "0.2.1"
Expand All @@ -48,17 +49,17 @@ async-channel = "1.6.1"
once_cell = "1.13.0"

# Waiting for updates to Bevy 0.8
# bevy_mod_debugdump = { version = "0.4", optional = true }
# bevy-inspector-egui = { version = "0.11", optional = true }
# bevy-inspector-egui-rapier = { version = "0.4", optional = true, features = ["rapier2d"] }
bevy_mod_debugdump = { version = "0.5.0", optional = true }
bevy-inspector-egui = { version = "0.12.1", optional = true }
bevy-inspector-egui-rapier = { version = "0.5.0", optional = true, features = ["rapier2d"] }

[target.'cfg(target_arch = "wasm32")'.dependencies]
web-sys = { version = "0.3", features = ["Window","Location","Storage"] }

[features]
default = []
# Waiting for update to Bevy 0.8
# schedule_graph = ["bevy_mod_debugdump"]
debug = ["bevy_mod_debugdump", "bevy-inspector-egui", "bevy-inspector-egui-rapier"]
schedule_graph = ["bevy_mod_debugdump"]

# Enable optimizations for dependencies but not for our code
[profile.dev.package."*"]
Expand Down
4 changes: 2 additions & 2 deletions assets/fighters/bandit/bandit.fighter.yaml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
name: Bandit

stats:
health: 150
damage: 20
max_health: 150
damage: 4
movement_speed: 150

hud:
Expand Down
4 changes: 2 additions & 2 deletions assets/fighters/brute/brute.fighter.yaml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
name: Brute

stats:
health: 200
damage: 50
max_health: 200
damage: 10
movement_speed: 50

hud:
Expand Down
2 changes: 1 addition & 1 deletion assets/fighters/fishy/fishy.fighter.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name: Fishy The Fearsome

stats:
health: 100
max_health: 600
damage: 35
movement_speed: 150

Expand Down
2 changes: 1 addition & 1 deletion assets/fighters/sharky/sharky.fighter.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name: Scrumptious Sharky

stats:
health: 100
max_health: 600
damage: 35
movement_speed: 150

Expand Down
4 changes: 2 additions & 2 deletions assets/fighters/slinger/slinger.fighter.yaml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
name: Slinger

stats:
health: 100
damage: 35
max_health: 100
damage: 7
movement_speed: 150

hud:
Expand Down
3 changes: 3 additions & 0 deletions assets/items/bottle/bottle.item.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,6 @@ name: Bottle
image:
image: bottle.png
image_size: [11, 31]

kind: !Throwable
damage: 10
7 changes: 5 additions & 2 deletions assets/items/health/health.item.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
name: Health

image:
image: health.png
image_size: [22, 20]
image: health.png
image_size: [22, 20]

kind: !Health
health: 1000000 # Refill all of it
58 changes: 30 additions & 28 deletions src/animation.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use std::ops::Range;

use crate::{state::State, GameStage, GameState};
use crate::GameState;
use bevy::{
prelude::{App, Changed, Component, Plugin, Query, Res},
prelude::*,
sprite::TextureAtlasSprite,
time::{Time, Timer},
utils::HashMap,
Expand All @@ -15,17 +15,24 @@ pub struct AnimationPlugin;
impl Plugin for AnimationPlugin {
fn build(&self, app: &mut App) {
app.add_system_set_to_stage(
GameStage::Animation,
CoreStage::Last,
ConditionSet::new()
.run_in_state(GameState::InGame)
.with_system(animate_on_state_changed)
.with_system(animation_flipping)
.with_system(animation_cycling)
.into(),
);
}
}

/// Bundle for animated sprite sheets
#[derive(Bundle)]
pub struct AnimatedSpriteSheetBundle {
#[bundle]
pub sprite_sheet: SpriteSheetBundle,
pub animation: Animation,
}

#[cfg_attr(feature = "debug", derive(bevy_inspector_egui::Inspectable))]
#[derive(Component, PartialEq, Eq, Clone)]
pub enum Facing {
Expand All @@ -37,10 +44,6 @@ impl Facing {
pub fn is_left(&self) -> bool {
self == &Facing::Left
}

pub fn set(&mut self, facing: Facing) {
*self = facing;
}
}

#[derive(serde::Deserialize, Clone, Debug)]
Expand Down Expand Up @@ -95,31 +98,41 @@ impl<'de> serde::de::Visitor<'de> for RangeVisitor {

#[derive(Component)]
pub struct Animation {
pub animations: HashMap<State, Clip>,
pub animations: HashMap<String, Clip>,
pub current_frame: usize,
current_state: Option<State>,
pub current_animation: Option<String>,
pub timer: Timer,
pub played_once: bool,
}

impl Animation {
pub fn new(fps: f32, animations: HashMap<State, Clip>) -> Self {
pub fn new(fps: f32, animations: HashMap<String, Clip>) -> Self {
Self {
animations,
current_frame: 0,
current_state: None,
current_animation: None,
timer: Timer::from_seconds(fps, false),
played_once: false,
}
}

/// Start playing a new animation
pub fn play(&mut self, name: &str, repeating: bool) {
self.current_animation = Some(name.to_owned());
self.current_frame = 0;
self.timer.reset();
self.timer.unpause();
self.timer.set_repeating(repeating);
self.played_once = false;
}

pub fn is_finished(&self) -> bool {
self.played_once
}

pub fn is_repeating(&self) -> bool {
if let Some(state) = self.current_state {
if let Some(clip) = self.animations.get(&state) {
if let Some(animation) = &self.current_animation {
if let Some(clip) = self.animations.get(animation) {
return clip.repeat;
}
}
Expand All @@ -138,8 +151,8 @@ impl Animation {
}

pub fn get_current_indices(&self) -> Option<&Range<usize>> {
if let Some(state) = self.current_state {
match self.animations.get(&state) {
if let Some(animation) = &self.current_animation {
match self.animations.get(animation) {
Some(clip) => return Some(&clip.frames),
None => return None,
}
Expand All @@ -157,22 +170,11 @@ impl Animation {
}
}

fn animate_on_state_changed(mut query: Query<(&mut Animation, &State), Changed<State>>) {
for (mut animation, state) in query.iter_mut() {
if animation.current_state != Some(*state) {
animation.played_once = false;
animation.current_frame = 0;
animation.current_state = Some(*state);
animation.timer.reset();
}
}
}

fn animation_cycling(mut query: Query<(&mut TextureAtlasSprite, &mut Animation)>, time: Res<Time>) {
//TODO: Add a tick method on Animation
for (mut texture_atlas_sprite, mut animation) in query.iter_mut() {
if animation.is_finished() && !animation.is_repeating() {
return;
continue;
}

animation.timer.tick(time.delta());
Expand Down
2 changes: 1 addition & 1 deletion src/assets.rs
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ impl AssetLoader for FighterLoader {
let frame_audio_handles = meta
.audio
.effect_handles
.entry(*state)
.entry(state.clone())
.or_insert_with(HashMap::new);

frame_audio_handles.insert(*animation_i, effect_handle);
Expand Down
Loading