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

Position fighters transform relative to feet #241

Merged
merged 4 commits into from
Aug 29, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
Binary file removed assets/fighters/bandit/Bandit_Skin1.png
Binary file not shown.
Binary file removed assets/fighters/bandit/Bandit_Skin2.png
Binary file not shown.
Binary file removed assets/fighters/bandit/Bandit_Skin3.png
Binary file not shown.
7 changes: 3 additions & 4 deletions assets/fighters/bandit/bandit.fighter.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
name: Bandit

size: [36, 52]

hurtbox:
size: [36, 52]
offset: [0, 0]
Expand All @@ -16,8 +14,9 @@ hud:
image_size: [35, 35]

spritesheet:
image: [Bandit_Skin1.png, Bandit_Skin2.png, Bandit_Skin3.png]
tile_size: [64, 64]
image:
[bandit_headband_64_80.png, bandit_mask_64_80.png, bandit_seaweed_64_80.png]
tile_size: [64, 80]
columns: 7
rows: 6

Expand Down
Binary file added assets/fighters/bandit/bandit_headband_64_80.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/fighters/bandit/bandit_mask_64_80.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/fighters/bandit/bandit_seaweed_64_80.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed assets/fighters/big_bass/BigBass.png
Binary file not shown.
Binary file added assets/fighters/big_bass/bass_base_156_192.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 2 additions & 4 deletions assets/fighters/big_bass/big_bass.fighter.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
name: Big Bass

size: [130, 176]

hurtbox:
size: [96, 120]
offset: [0, -16]
Expand All @@ -16,8 +14,8 @@ hud:
image_size: [35, 35]

spritesheet:
image: [BigBass.png]
tile_size: [156, 176]
image: [bass_base_156_192.png]
tile_size: [156, 192]
columns: 15
rows: 3

Expand Down
Binary file removed assets/fighters/brute/Brute_Skin1.png
Binary file not shown.
Binary file removed assets/fighters/brute/Brute_Skin2.png
Binary file not shown.
Binary file removed assets/fighters/brute/Brute_Skin3.png
Binary file not shown.
7 changes: 3 additions & 4 deletions assets/fighters/brute/brute.fighter.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
name: Brute

size: [36, 58]

hurtbox:
size: [36, 58]
offset: [0, 0]
Expand All @@ -16,8 +14,9 @@ hud:
image_size: [35, 35]

spritesheet:
image: [Brute_Skin1.png, Brute_Skin2.png, Brute_Skin3.png]
tile_size: [64, 64]
image:
[brute_base_64_80.png, brute_eyepatch_64_80.png, brute_helmet_64_80.png]
tile_size: [64, 80]
columns: 8
rows: 6

Expand Down
Binary file added assets/fighters/brute/brute_base_64_80.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/fighters/brute/brute_eyepatch_64_80.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/fighters/brute/brute_helmet_64_80.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
7 changes: 1 addition & 6 deletions assets/fighters/dev/dev.fighter.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
name: Dev

size: [36, 48]

hurtbox:
size: [36, 48]
offset: [0, 0]
Expand All @@ -16,10 +14,7 @@ hud:
image_size: [35, 35]

spritesheet:
#right now load/spawn selects a spritesheet randomly from all available.
#want to change this so that individual animations can be specified to correspond to ranges and spritesheet
#or maybe not
image: [PlayerDev96x80.png]
image: [dev_base_96_80.png]
tile_size: [96, 80]
columns: 15
rows: 14
Expand Down
4 changes: 1 addition & 3 deletions assets/fighters/fishy/fishy.fighter.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
name: Fishy The Fearsome

size: [36, 48]

hurtbox:
size: [36, 48]
offset: [0, 0]
Expand All @@ -16,7 +14,7 @@ hud:
image_size: [35, 35]

spritesheet:
image: [PlayerFishy(96x80).png]
image: [fishy_base_96_80.png]
tile_size: [96, 80]
columns: 14
rows: 7
Expand Down
4 changes: 1 addition & 3 deletions assets/fighters/sharky/sharky.fighter.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
name: Scrumptious Sharky

size: [36, 48]

hurtbox:
size: [36, 48]
offset: [0, 0]
Expand All @@ -16,7 +14,7 @@ hud:
image_size: [35, 35]

spritesheet:
image: [PlayerSharky(96x80).png]
image: [sharky_base_96_80.png]
tile_size: [96, 80]
columns: 14
rows: 7
Expand Down
Binary file removed assets/fighters/slinger/Slinger_Skin1.png
Binary file not shown.
Binary file removed assets/fighters/slinger/Slinger_Skin2.png
Binary file not shown.
Binary file removed assets/fighters/slinger/Slinger_Skin3.png
Binary file not shown.
9 changes: 6 additions & 3 deletions assets/fighters/slinger/slinger.fighter.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
name: Slinger

size: [36, 48]

hurtbox:
size: [36, 48]
offset: [0, 0]
Expand All @@ -16,7 +14,12 @@ hud:
image_size: [35, 35]

spritesheet:
image: [Slinger_Skin1.png, Slinger_Skin2.png, Slinger_Skin3.png]
image:
[
slinger_cap_80_80.png,
slinger_headband_80_80.png,
slinger_goggles_80_80.png,
]
tile_size: [80, 80]
columns: 7
rows: 6
Expand Down
Binary file added assets/fighters/slinger/slinger_cap_80_80.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/fighters/slinger/slinger_goggles_80_80.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 3 additions & 1 deletion src/assets.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use bevy::{
};
use bevy_egui::egui;

use crate::metadata::*;
use crate::{consts::FOOT_PADDING, metadata::*};

/// Register game asset and loaders
pub fn register(app: &mut bevy::prelude::App) {
Expand Down Expand Up @@ -284,6 +284,8 @@ impl AssetLoader for FighterLoader {
.with_dependency(texture_path),
);
meta.spritesheet.atlas_handle.push(atlas_handle);
meta.center_y = meta.spritesheet.tile_size.y as f32 / 2.;
meta.collision_offset = meta.center_y - FOOT_PADDING;
}

load_context.set_default_asset(LoadedAsset::new(meta).with_dependencies(dependencies));
Expand Down
31 changes: 19 additions & 12 deletions src/attack.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ pub struct Attack {
pub velocity: Vec2,
}

#[derive(Component)]
pub struct Hurtbox;

/// A component that depawns an entity after collision.
#[derive(Component, Clone, Copy, Default, Reflect)]
pub struct Breakable {
Expand Down Expand Up @@ -113,31 +116,35 @@ fn attack_damage_system(
mut events: EventReader<CollisionEvent>,
mut damageables: Query<(&mut Health, &Damageable)>,
attacks: Query<&Attack>,
hurtboxes: Query<&Parent, With<Hurtbox>>,
mut event_writer: EventWriter<DamageEvent>,
) {
for event in events.iter() {
if let CollisionEvent::Started(e1, e2, _flags) = event {
let (attack_entity, damageable_entity) =
if attacks.contains(*e1) && damageables.contains(*e2) {
let (attack_entity, hurtbox_entity) =
if attacks.contains(*e1) && hurtboxes.contains(*e2) {
(*e1, *e2)
} else if attacks.contains(*e2) && damageables.contains(*e1) {
} else if attacks.contains(*e2) && hurtboxes.contains(*e1) {
(*e2, *e1)
} else {
continue;
};

let attack = attacks.get(attack_entity).unwrap();
let (mut health, damageable) = damageables.get_mut(damageable_entity).unwrap();
if let Ok(hurtbox_parent) = hurtboxes.get(hurtbox_entity) {
let hurtbox_parent_entity = hurtbox_parent.get();
let (mut health, damageable) = damageables.get_mut(hurtbox_parent_entity).unwrap();

if **damageable {
**health -= attack.damage;
if **damageable {
**health -= attack.damage;

event_writer.send(DamageEvent {
damageing_entity: attack_entity,
damage_velocity: attack.velocity,
damage: attack.damage,
damaged_entity: damageable_entity,
})
event_writer.send(DamageEvent {
damageing_entity: attack_entity,
damage_velocity: attack.velocity,
damage: attack.damage,
damaged_entity: hurtbox_parent_entity,
})
}
}
}
}
Expand Down
8 changes: 6 additions & 2 deletions src/consts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,15 @@ pub const ENEMY_MAX_ATTACK_DISTANCE: f32 = 100.;
pub const LEFT_BOUNDARY_MAX_DISTANCE: f32 = 380.;

pub const GROUND_Y: f32 = -120.;
pub const GROUND_HEIGHT: f32 = 150.;
pub const GROUND_HEIGHT: f32 = 100.;
pub const GROUND_OFFSET: f32 = 0.;

pub const CAMERA_SPEED: f32 = 0.8;

pub const MAX_Y: f32 = (GROUND_HEIGHT / 2.) + GROUND_Y;
pub const MIN_Y: f32 = -(GROUND_HEIGHT / 2.) + GROUND_Y;
// pub const MIN_Y: f32 = -(GROUND_HEIGHT / 2.) + GROUND_Y;
//TODO: figure out a better way to do this than tacking on an extra offset
pub const MIN_Y: f32 = -(GROUND_HEIGHT / 2.) + GROUND_Y - 50.;

//TODO: remove in favor of loading attack velocity from YAML
pub const ATTACK_VELOCITY: f32 = 80.0;
Expand All @@ -37,3 +39,5 @@ pub const THROW_ITEM_ROTATION_SPEED: f32 = -20.;
pub const THROW_ITEM_GRAVITY: f32 = 1200.0;

pub const PICK_ITEM_RADIUS: f32 = 24.;

pub const FOOT_PADDING: f32 = 16.;
34 changes: 28 additions & 6 deletions src/fighter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ use bevy::prelude::*;
use rand::prelude::SliceRandom;
use serde::Deserialize;

use crate::attack::Hurtbox;
use crate::consts::FOOT_PADDING;
use crate::metadata::ItemMeta;
use crate::{
animation::{AnimatedSpriteSheetBundle, Animation},
Expand All @@ -21,8 +23,8 @@ pub struct ActiveFighterBundle {
pub name: Name,
#[bundle]
pub animated_spritesheet_bundle: AnimatedSpriteSheetBundle,
#[bundle]
pub physics_bundle: PhysicsBundle,
// #[bundle]
// pub physics_bundle: PhysicsBundle,
pub stats: Stats,
pub ysort: YSort,
pub health: Health,
Expand Down Expand Up @@ -79,7 +81,14 @@ impl ActiveFighterBundle {
name: Name::new(fighter.name.clone()),
animated_spritesheet_bundle: AnimatedSpriteSheetBundle {
sprite_sheet: SpriteSheetBundle {
sprite: default(),
sprite: TextureAtlasSprite {
anchor: bevy::sprite::Anchor::Custom(Vec2::new(
0.,
//calculate anchor to align with feet
0.5 * FOOT_PADDING / fighter.center_y - 0.5,
)),
..default()
},
texture_atlas: fighter
.spritesheet
.atlas_handle
Expand All @@ -98,13 +107,26 @@ impl ActiveFighterBundle {
health: Health(fighter.stats.max_health),
inventory: default(),
damageable: default(),
physics_bundle: PhysicsBundle::new(&fighter.hurtbox, body_layers),
// physics_bundle: PhysicsBundle::new(&fighter.hurtbox, body_layers),
idling: Idling,
state_transition_intents: default(),
ysort: YSort(fighter.size.y / 2.),
// ysort: YSort(fighter.spritesheet.tile_size.y as f32 / 2.),
ysort: YSort(0.),
velocity: default(),
};
let hurtbox = commands
.spawn_bundle(PhysicsBundle::new(&fighter.hurtbox, body_layers))
.insert_bundle(TransformBundle::from_transform(Transform::from_xyz(
0.0,
fighter.collision_offset,
0.0,
)))
.insert(Hurtbox)
.id();

commands.entity(entity).insert_bundle(active_fighter_bundle);
commands
.entity(entity)
.insert_bundle(active_fighter_bundle)
.push_children(&[hurtbox]);
}
}
3 changes: 3 additions & 0 deletions src/fighter_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -574,6 +574,7 @@ fn flopping(
if facing.is_left() {
offset.x *= -1.0
}
offset.y += fighter.collision_offset;
let attack_frames = fighter.attack.frames;

// Spawn the attack entity
Expand Down Expand Up @@ -689,6 +690,7 @@ fn punching(
if facing.is_left() {
offset.x *= -1.0
}
offset.y += fighter.collision_offset;
let attack_frames = fighter.attack.frames;
// Spawn the attack entity
let attack_entity = commands
Expand Down Expand Up @@ -774,6 +776,7 @@ fn ground_slam(
if facing.is_left() {
offset.x *= -1.0
}
offset.y += fighter.collision_offset;
let attack_frames = fighter.attack.frames;
if !ground_slam.has_started {
ground_slam.has_started = true;
Expand Down
5 changes: 4 additions & 1 deletion src/metadata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,10 @@ impl LevelMeta {
#[uuid = "d5e040c4-3de7-4b8a-b6c2-27f82f58d8f0"]
pub struct FighterMeta {
pub name: String,
pub size: Vec2,
#[serde(skip)]
pub center_y: f32,
#[serde(skip)]
pub collision_offset: f32,
pub stats: Stats,
pub hud: FighterHudMeta,
pub spritesheet: FighterSpritesheetMeta,
Expand Down
2 changes: 1 addition & 1 deletion src/ui/debug_tools.rs
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ fn draw_ysort_lines(
for (ysort, fighter_meta, transform) in query.iter() {
//If the fighter meta is not loaded default to 16.0
let half_width = if let Some(meta) = fighter_assets.get(fighter_meta) {
meta.size.x / 2.0
meta.spritesheet.tile_size.x as f32 / 2.
} else {
16.0
};
Expand Down