Skip to content

Commit

Permalink
Fix YSort and add editable colliders
Browse files Browse the repository at this point in the history
Review fixes

Initial y-sorting debug lines

Fix y-sorting debugging.
Fix y-sort by adding size to the fighters.

new healing system | making it easier to organize

format

format2

format3

Update src/fighter_state.rs

Co-authored-by: Zicklag <zicklag@katharostech.com>

removing status and health

format1
  • Loading branch information
edgarssilva authored and DRuppFv committed Aug 14, 2022
1 parent 15d1bd0 commit e50ac89
Show file tree
Hide file tree
Showing 15 changed files with 210 additions and 59 deletions.
11 changes: 9 additions & 2 deletions assets/fighters/bandit/bandit.fighter.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
name: Bandit

size: [36, 52]

hurtbox:
size: [36, 12]
offset: [0, 0]

stats:
max_health: 150
movement_speed: 150
Expand Down Expand Up @@ -42,8 +48,9 @@ attack:
startup: 1
active: 2
recovery: 3
hitbox: [12, 12]
hitbox_offset: [24, 0]
hitbox:
size: [36, 24]
offset: [24, 0]

audio:
effects:
Expand Down
11 changes: 9 additions & 2 deletions assets/fighters/big_bass/big_bass.fighter.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
name: Bandit

size: [130, 176]

hurtbox:
size: [96, 32]
offset: [0, -16]

stats:
max_health: 350
movement_speed: 75
Expand Down Expand Up @@ -42,8 +48,9 @@ attack:
startup: 5
active: 9
recovery: 14
hitbox: [48, 48]
hitbox_offset: [0, 0]
hitbox:
size: [96, 32]
offset: [0, -69]

audio:
effects:
Expand Down
11 changes: 9 additions & 2 deletions assets/fighters/brute/brute.fighter.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
name: Brute

size: [36, 58]

hurtbox:
size: [36, 12]
offset: [0, 0]

stats:
max_health: 200
movement_speed: 50
Expand Down Expand Up @@ -42,8 +48,9 @@ attack:
startup: 2
active: 3
recovery: 7
hitbox: [12, 12]
hitbox_offset: [24, 0]
hitbox:
size: [36, 24]
offset: [24, 0]

audio:
effects: {}
11 changes: 9 additions & 2 deletions assets/fighters/fishy/fishy.fighter.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
name: Fishy The Fearsome

size: [36, 48]

hurtbox:
size: [36, 12]
offset: [0, 0]

stats:
max_health: 600
movement_speed: 150
Expand Down Expand Up @@ -40,8 +46,9 @@ attack:
startup: 1
active: 2
recovery: 4
hitbox: [16, 16]
hitbox_offset: [24, 0]
hitbox:
size: [32, 32]
offset: [32, 0]

audio:
effects:
Expand Down
11 changes: 9 additions & 2 deletions assets/fighters/sharky/sharky.fighter.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
name: Scrumptious Sharky

size: [36, 48]

hurtbox:
size: [36, 12]
offset: [0, 0]

stats:
max_health: 600
movement_speed: 150
Expand Down Expand Up @@ -40,8 +46,9 @@ attack:
startup: 1
active: 2
recovery: 4
hitbox: [16, 16]
hitbox_offset: [24, 0]
hitbox:
size: [32, 32]
offset: [32, 0]

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

size: [36, 48]

hurtbox:
size: [36, 12]
offset: [0, 0]

stats:
max_health: 100
movement_speed: 150
Expand Down Expand Up @@ -42,8 +48,9 @@ attack:
startup: 1
active: 2
recovery: 3
hitbox: [12, 12]
hitbox_offset: [24, 0]
hitbox:
size: [36, 24]
offset: [24, 0]

audio:
effects: {}
3 changes: 2 additions & 1 deletion assets/locales/en-US/main.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,5 @@ bind-input = Press an input or press Escape to cancel.
# Debug Tools
debug-tools = Debug Tools
show-collision-shapes = Show Collision Shapes
show-world-inspector = Show World Inspector
show-world-inspector = Show World Inspector
show-ysort-lines = Show Y-Sort Lines
4 changes: 2 additions & 2 deletions src/attack.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,8 @@ fn activate_hitbox(
{
if let Some(fighter_data) = fighter_assets.get(fighter_meta) {
commands.entity(entity).insert(Collider::cuboid(
fighter_data.attack.hitbox.x,
fighter_data.attack.hitbox.y,
fighter_data.attack.hitbox.size.x / 2.,
fighter_data.attack.hitbox.size.y / 2.,
));
}
}
Expand Down
5 changes: 4 additions & 1 deletion src/camera.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,13 @@ impl Plugin for CameraPlugin {
}
}

/// Component to sort entities by their y position.
/// Takes in a offset usually the sprite's height.
#[derive(Component, Default, Reflect)]
#[reflect(Component)]
pub struct YSort(f32);
pub struct YSort(pub f32);

/// Applies the y-sorting to the entities Z position.
pub fn y_sort(mut query: Query<(&mut Transform, &YSort)>) {
for (mut transform, ysort) in query.iter_mut() {
transform.translation.z = ysort.0 - transform.translation.y;
Expand Down
16 changes: 15 additions & 1 deletion src/collision.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use bevy::prelude::*;
use bevy_rapier2d::prelude::*;

use crate::consts;
use crate::{consts, metadata::ColliderMeta};

/// Empty struct simply for grouping collision layer constants.
#[derive(Copy, Clone)]
Expand Down Expand Up @@ -29,6 +29,20 @@ pub struct PhysicsBundle {
pub active_collision_types: ActiveCollisionTypes,
pub collision_groups: CollisionGroups,
}

impl PhysicsBundle {
pub fn new(meta: &ColliderMeta, body_layers: u32) -> Self {
PhysicsBundle {
collider: (Collider::cuboid(meta.size.x / 2., meta.size.y / 2.)),
sensor: Sensor,
active_events: ActiveEvents::COLLISION_EVENTS,
active_collision_types: ActiveCollisionTypes::default()
| ActiveCollisionTypes::STATIC_STATIC,
collision_groups: CollisionGroups::new(body_layers, BodyLayers::ALL),
}
}
}

impl Default for PhysicsBundle {
fn default() -> Self {
PhysicsBundle {
Expand Down
10 changes: 3 additions & 7 deletions src/fighter.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
use bevy::prelude::*;
use bevy_rapier2d::prelude::CollisionGroups;
use rand::prelude::SliceRandom;
use serde::Deserialize;

Expand Down Expand Up @@ -80,7 +79,7 @@ impl ActiveFighterBundle {
name: Name::new(fighter.name.clone()),
animated_spritesheet_bundle: AnimatedSpriteSheetBundle {
sprite_sheet: SpriteSheetBundle {
sprite: TextureAtlasSprite::new(0),
sprite: default(),
texture_atlas: fighter
.spritesheet
.atlas_handle
Expand All @@ -99,13 +98,10 @@ impl ActiveFighterBundle {
health: Health(fighter.stats.max_health),
inventory: default(),
damageable: default(),
physics_bundle: PhysicsBundle {
collision_groups: CollisionGroups::new(body_layers, BodyLayers::ALL),
..default()
},
physics_bundle: PhysicsBundle::new(&fighter.hurtbox, body_layers),
idling: Idling,
state_transition_intents: default(),
ysort: default(),
ysort: YSort(fighter.size.y / 2.),
velocity: default(),
};

Expand Down
57 changes: 27 additions & 30 deletions src/fighter_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -679,9 +679,9 @@ fn punching(
// Start the attack from the beginning
animation.play(Punching::ANIMATION, false);

let mut offset = fighter.attack.hitbox_offset;
let mut offset = fighter.attack.hitbox.offset;
if facing.is_left() {
offset *= -1.0
offset.x *= -1.0
}
let attack_frames = fighter.attack.frames;
// Spawn the attack entity
Expand Down Expand Up @@ -764,9 +764,9 @@ fn ground_slam(
{
// Start the attack
if let Some(fighter) = fighter_assets.get(meta_handle) {
let mut offset = fighter.attack.hitbox_offset;
let mut offset = fighter.attack.hitbox.offset;
if facing.is_left() {
offset *= -1.0
offset.x *= -1.0
}
let attack_frames = fighter.attack.frames;
if !ground_slam.has_started {
Expand Down Expand Up @@ -939,19 +939,9 @@ fn dying(
/// Throw the item in the player's inventory
fn throwing(
mut commands: Commands,
mut fighters: Query<
(
Entity,
&Transform,
&Facing,
&Stats,
&mut Inventory,
&mut Health,
),
With<Throwing>,
>,
mut fighters: Query<(Entity, &Transform, &Facing, &mut Inventory), With<Throwing>>,
) {
for (entity, fighter_transform, facing, stats, mut inventory, mut health) in &mut fighters {
for (entity, fighter_transform, facing, mut inventory) in &mut fighters {
// If the player has an item in their inventory
if let Some(item_meta) = inventory.take() {
// Check what kind of item this is.
Expand All @@ -968,11 +958,8 @@ fn throwing(
facing,
));
}
ItemKind::Health {
health: item_health,
} => {
// Refill player's health
**health = (**health + item_health).clamp(0, stats.max_health);
ItemKind::Health { health: _ } => {
panic!("Health items should be used immediately, and can't be thrown");
}
}
}
Expand All @@ -986,14 +973,15 @@ fn throwing(
// Trying to grab an item off the map
fn grabbing(
mut commands: Commands,
mut fighters: Query<(Entity, &Transform, &mut Inventory), With<Grabbing>>,
mut fighters: Query<(Entity, &Transform, &mut Inventory, &Stats, &mut Health), With<Grabbing>>,
items_query: Query<(Entity, &Transform, &Handle<ItemMeta>), With<Item>>,
items_assets: Res<Assets<ItemMeta>>,
) {
// We need to track the picked items, otherwise, in theory, two players could pick the same item.
let mut picked_item_ids = HashSet::new();

for (fighter_ent, fighter_transform, mut fighter_inventory) in &mut fighters {
for (fighter_ent, fighter_transform, mut fighter_inventory, stats, mut health) in &mut fighters
{
// If several items are at pick distance, an arbitrary one is picked.
for (item_ent, item_transform, item) in &items_query {
if !picked_item_ids.contains(&item_ent) {
Expand All @@ -1007,18 +995,27 @@ fn grabbing(
if fighter_item_distance <= consts::PICK_ITEM_RADIUS {
// And our fighter isn't carrying another item
if fighter_inventory.is_none() {
// Pick up the item
picked_item_ids.insert(item_ent);
**fighter_inventory =
Some(items_assets.get(item).expect("Item not loaded!").clone());
commands.entity(item_ent).despawn_recursive();
match items_assets.get(item).unwrap().kind {
ItemKind::Health {
health: item_health,
} => {
// If its health, refill player's health instantly
**health = (**health + item_health).clamp(0, stats.max_health);
commands.entity(item_ent).despawn_recursive();
}
ItemKind::Throwable { damage: _ } => {
// If its throwable, pick up the item
picked_item_ids.insert(item_ent);
**fighter_inventory =
Some(items_assets.get(item).expect("Item not loaded!").clone());
commands.entity(item_ent).despawn_recursive();
}
}
}

break;
}
}
}

// Grabbing is an "instant" state, that is removed at the end of every frame. Eventually it
// may not be and it might play a fighter animation.
commands.entity(fighter_ent).remove::<Grabbing>();
Expand Down
3 changes: 2 additions & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ use utils::ResetController;
use crate::{
damage::DamagePlugin, fighter_state::FighterStatePlugin, input::PlayerAction,
lifetime::LifetimePlugin, loading::LoadingPlugin, localization::LocalizationPlugin,
movement::MovementPlugin, platform::PlatformPlugin,
movement::MovementPlugin, platform::PlatformPlugin, ui::debug_tools::YSortDebugPlugin,
};

#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
Expand Down Expand Up @@ -143,6 +143,7 @@ fn main() {
enabled: false,
..default()
})
.add_plugin(YSortDebugPlugin)
.add_plugin(InspectableRapierPlugin)
.insert_resource(WorldInspectorParams {
enabled: false,
Expand Down
Loading

0 comments on commit e50ac89

Please sign in to comment.