Skip to content

Commit

Permalink
Merge #270
Browse files Browse the repository at this point in the history
270: Beginning support for multiple attacks per fighter. r=odecay a=odecay

~This broke AI as of now, I must have missed some implications of the change, will take another look shortly.
Probably the using the last `AvailableAttack` can have already changed when we are checking its properties before attacks finish.~

Edit: Fixed, should be good to go.

Co-authored-by: otis <electricbuck@gmail.com>
  • Loading branch information
bors[bot] and odecay authored Nov 9, 2022
2 parents 0c6fd8d + 0db0ef3 commit e94722f
Show file tree
Hide file tree
Showing 16 changed files with 145 additions and 145 deletions.
22 changes: 11 additions & 11 deletions assets/fighters/bandit/bandit.fighter.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -42,17 +42,17 @@ spritesheet:
attacking:
frames: [14, 17]

attack:
name: "punch"
damage: 4
frames:
startup: 1
active: 2
recovery: 3
hitbox:
size: [36, 24]
offset: [24, 0]
hitstun_duration: 0.2
attacks:
- name: "punch"
damage: 4
frames:
startup: 1
active: 2
recovery: 3
hitbox:
size: [36, 24]
offset: [24, 0]
hitstun_duration: 0.2

audio:
effects:
Expand Down
22 changes: 11 additions & 11 deletions assets/fighters/big_bass/big_bass.fighter.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -41,17 +41,17 @@ spritesheet:
attacking:
frames: [30, 44]

attack:
name: "ground_slam"
damage: 35
frames:
startup: 5
active: 9
recovery: 14
hitbox:
size: [96, 32]
offset: [0, -69]
hitstun_duration: 0.2
attacks:
- name: "ground_slam"
damage: 35
frames:
startup: 5
active: 9
recovery: 14
hitbox:
size: [96, 32]
offset: [0, -69]
hitstun_duration: 0.2

audio:
effects:
Expand Down
22 changes: 11 additions & 11 deletions assets/fighters/brute/brute.fighter.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -42,17 +42,17 @@ spritesheet:
attacking:
frames: [16, 23]

attack:
name: "punch"
damage: 10
frames:
startup: 2
active: 3
recovery: 7
hitbox:
size: [36, 24]
offset: [24, 0]
hitstun_duration: 0.2
attacks:
- name: "punch"
damage: 10
frames:
startup: 2
active: 3
recovery: 7
hitbox:
size: [36, 24]
offset: [24, 0]
hitstun_duration: 0.2

audio:
effects: {}
26 changes: 13 additions & 13 deletions assets/fighters/dev/dev.fighter.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ hud:
spritesheet:
image: [dev_base_96_80.png]
tile_size: [96, 80]
columns: 15
rows: 14
columns: 14
rows: 15

animation_fps: 0.12
animations:
Expand All @@ -39,17 +39,17 @@ spritesheet:
attacking:
frames: [85, 90]

attack:
name: "punch"
damage: 35
frames:
startup: 1
active: 2
recovery: 4
hitbox:
size: [32, 32]
offset: [32, 0]
hitstun_duration: 0.2
attacks:
- name: "punch"
damage: 35
frames:
startup: 1
active: 2
recovery: 4
hitbox:
size: [32, 32]
offset: [32, 0]
hitstun_duration: 0.2

audio:
effects:
Expand Down
23 changes: 11 additions & 12 deletions assets/fighters/fishy/fishy.fighter.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -39,18 +39,17 @@ spritesheet:
attacking:
frames: [85, 90]

attack:
name: "flop"
damage: 35
frames:
startup: 1
active: 2
recovery: 4
hitbox:
size: [32, 32]
offset: [32, 0]
hitstun_duration: 0.2
# velocity: [20.0, 0.0]
attacks:
- name: "flop"
damage: 35
frames:
startup: 1
active: 2
recovery: 4
hitbox:
size: [32, 32]
offset: [32, 0]
hitstun_duration: 0.2

audio:
effects:
Expand Down
22 changes: 11 additions & 11 deletions assets/fighters/sharky/sharky.fighter.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -39,17 +39,17 @@ spritesheet:
attacking:
frames: [85, 90]

attack:
name: "flop"
damage: 35
frames:
startup: 1
active: 2
recovery: 4
hitbox:
size: [32, 32]
offset: [32, 0]
hitstun_duration: 0.2
attacks:
- name: "flop"
damage: 35
frames:
startup: 1
active: 2
recovery: 4
hitbox:
size: [32, 32]
offset: [32, 0]
hitstun_duration: 0.2

audio:
effects:
Expand Down
22 changes: 11 additions & 11 deletions assets/fighters/slinger/slinger.fighter.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -46,17 +46,17 @@ spritesheet:
attacking:
frames: [14, 18]
# this should be changed to a ranged attack
attack:
name: "punch"
damage: 7
frames:
startup: 1
active: 2
recovery: 3
hitbox:
size: [36, 24]
offset: [24, 0]
hitstun_duration: 0.2
attacks:
- name: "punch"
damage: 7
frames:
startup: 1
active: 2
recovery: 3
hitbox:
size: [36, 24]
offset: [24, 0]
hitstun_duration: 0.2

audio:
effects: {}
3 changes: 2 additions & 1 deletion assets/levels/1_beach/beach.level.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ parallax_background:
transition_factor: 0.9

players:
- fighter: /fighters/fishy/fishy.fighter.yaml
# - fighter: /fighters/fishy/fishy.fighter.yaml
- fighter: /fighters/dev/dev.fighter.yaml
location: [0, 0, 0]
- fighter: /fighters/sharky/sharky.fighter.yaml
location: [-70, 30, 0]
Expand Down
25 changes: 6 additions & 19 deletions src/attack.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,8 @@ use serde::Deserialize;
use crate::{
animation::Animation,
damage::{DamageEvent, Damageable, Health},
fighter_state::MeleeWeapon,
fighter::AvailableAttacks,
item::Drop,
metadata::FighterMeta,
GameState,
};

Expand Down Expand Up @@ -89,30 +88,18 @@ pub struct AttackFrames {

fn activate_hitbox(
attack_query: Query<(Entity, &AttackFrames, &Parent), Without<Collider>>,
fighter_query: Query<(
&Animation,
Option<&Handle<FighterMeta>>,
Option<&MeleeWeapon>,
)>,
fighter_query: Query<(&Animation, &AvailableAttacks)>,
mut commands: Commands,
fighter_assets: Res<Assets<FighterMeta>>,
) {
for (entity, attack_frames, parent) in attack_query.iter() {
if let Ok((animation, fighter_meta, melee_weapon)) = fighter_query.get(**parent) {
if let Ok((animation, available_attacks)) = fighter_query.get(**parent) {
if animation.current_frame >= attack_frames.startup
&& animation.current_frame <= attack_frames.active
{
if let Some(fighter_meta) = fighter_meta {
if let Some(fighter_data) = fighter_assets.get(fighter_meta) {
commands.entity(entity).insert(Collider::cuboid(
fighter_data.attack.hitbox.size.x / 2.,
fighter_data.attack.hitbox.size.y / 2.,
));
}
} else if let Some(melee_weapon) = melee_weapon {
if let Some(attack) = available_attacks.0.last() {
commands.entity(entity).insert(Collider::cuboid(
melee_weapon.attack.hitbox.size.x / 2.,
melee_weapon.attack.hitbox.size.y / 2.,
attack.hitbox.size.x / 2.,
attack.hitbox.size.y / 2.,
));
}
}
Expand Down
6 changes: 5 additions & 1 deletion src/enemy_ai.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,15 @@ use crate::{
Stats,
};

//maybe implement as plugin

/// A place that an enemy fighter is going to move to, in an attempt to attack a player.
///
/// The attack distance is for randomization purposes, and it's the distance that triggers the
/// attack. More precisely, it's the max distance - if the enemy finds itself at a smaller distance,
/// it will attack.
#[derive(Component)]
#[derive(Component, Reflect, Default)]
#[reflect(Component)]
#[component(storage = "SparseSet")]
pub struct EnemyTarget {
pub position: Vec2,
Expand Down Expand Up @@ -136,6 +139,7 @@ pub fn emit_enemy_intents(
Facing::Left
};

// make them attack with their first available attack??
// And attack!
if maybe_boss.is_some() {
intents.push_back(StateTransition::new(
Expand Down
7 changes: 6 additions & 1 deletion src/fighter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use crate::{
damage::{Damageable, Health},
enemy::Enemy,
fighter_state::{Idling, StateTransitionIntents},
metadata::FighterMeta,
metadata::{AttackMeta, FighterMeta},
movement::LinearVelocity,
player::Player,
};
Expand Down Expand Up @@ -42,8 +42,12 @@ pub struct ActiveFighterBundle {
/// Fighters start off idling, but this component may be removed when the fighter state changes.
pub idling: Idling,
pub velocity: LinearVelocity,
pub available_attacks: AvailableAttacks,
}

#[derive(Component)]
pub struct AvailableAttacks(pub Vec<AttackMeta>);

#[derive(Component, Deserialize, Clone, Debug, Reflect)]
#[reflect(Component)]
#[serde(deny_unknown_fields)]
Expand Down Expand Up @@ -121,6 +125,7 @@ impl ActiveFighterBundle {
// ysort: YSort(fighter.spritesheet.tile_size.y as f32 / 2.),
ysort: YSort(consts::FIGHTERS_Z),
velocity: default(),
available_attacks: AvailableAttacks(fighter.attacks.clone()),
};
let hurtbox = commands
.spawn_bundle(PhysicsBundle::new(&fighter.hurtbox, body_layers))
Expand Down
Loading

0 comments on commit e94722f

Please sign in to comment.