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

Re-enebled boss ai, unique groundslam attack #235

Merged
merged 1 commit into from
Aug 22, 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
2 changes: 1 addition & 1 deletion assets/fighters/big_bass/big_bass.fighter.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Bandit
name: Big Bass

size: [130, 176]

Expand Down
2 changes: 1 addition & 1 deletion assets/levels/1_beach/beach.level.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ enemies:
trip_point_x: 300
- fighter: /fighters/big_bass/big_bass.fighter.yaml
location: [600, 20, 0]
trip_point_x: 700
trip_point_x: 400
boss: true

- fighter: &brute /fighters/brute/brute.fighter.yaml
Expand Down
28 changes: 19 additions & 9 deletions src/enemy_ai.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@ use rand::Rng;
use crate::{
animation::Facing,
consts::{self, ENEMY_MAX_ATTACK_DISTANCE, ENEMY_MIN_ATTACK_DISTANCE, ENEMY_TARGET_MAX_OFFSET},
enemy::{Enemy, TripPointX},
fighter_state::{Idling, Moving, Punching, StateTransition, StateTransitionIntents},
enemy::{Boss, Enemy, TripPointX},
fighter_state::{
GroundSlam, Idling, Moving, Punching, StateTransition, StateTransitionIntents,
},
player::Player,
Stats,
};
Expand Down Expand Up @@ -108,13 +110,14 @@ pub fn emit_enemy_intents(
&EnemyTarget,
&mut Facing,
&mut StateTransitionIntents,
Option<&Boss>,
),
// All enemies that are either moving or idling
(With<Enemy>, Or<(With<Idling>, With<Moving>)>),
>,
mut commands: Commands,
) {
for (entity, transform, stats, target, mut facing, mut intents) in &mut query {
for (entity, transform, stats, target, mut facing, mut intents, maybe_boss) in &mut query {
let position = transform.translation.truncate();
let velocity = (target.position - position).normalize() * stats.movement_speed;

Expand All @@ -134,12 +137,19 @@ pub fn emit_enemy_intents(
};

// And attack!
intents.push_back(StateTransition::new(
Punching::default(),
Punching::PRIORITY,
false,
));

if maybe_boss.is_some() {
intents.push_back(StateTransition::new(
GroundSlam::default(),
GroundSlam::PRIORITY,
false,
))
} else {
intents.push_back(StateTransition::new(
Punching::default(),
Punching::PRIORITY,
false,
));
}
// If we aren't near our target yet
} else {
// Face the cirection we're moving
Expand Down
27 changes: 17 additions & 10 deletions src/fighter_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -237,13 +237,12 @@ pub struct GroundSlam {
}
impl GroundSlam {
pub const PRIORITY: i32 = 30;
//TODO: return to change assets and this to "flopping"
//TODO: return to change assets and this to "ground_slam"?
pub const ANIMATION: &'static str = "attacking";
}

#[derive(Component, Reflect, Default, Debug)]
#[component(storage = "SparseSet")]

pub struct Punching {
pub has_started: bool,
pub is_finished: bool,
Expand Down Expand Up @@ -301,6 +300,7 @@ fn collect_player_actions(
false,
));
}

// Trigger grab/throw
if action_state.just_pressed(PlayerAction::Throw) {
if inventory.is_some() {
Expand Down Expand Up @@ -447,9 +447,9 @@ fn transition_from_punching(

fn transition_from_ground_slam(
mut commands: Commands,
mut fighters: Query<(Entity, &mut StateTransitionIntents, &Flopping)>,
mut fighters: Query<(Entity, &mut StateTransitionIntents, &GroundSlam)>,
) {
'entity: for (entity, mut transition_intents, flopping) in &mut fighters {
'entity: for (entity, mut transition_intents, ground_slam) in &mut fighters {
// Transition to any higher priority states
let current_state_removed = transition_intents
.transition_to_higher_priority_states::<GroundSlam>(
Expand All @@ -464,7 +464,7 @@ fn transition_from_ground_slam(
}

// If we're done flopping
if flopping.is_finished {
if ground_slam.is_finished {
// Go back to idle
commands
.entity(entity)
Expand Down Expand Up @@ -817,22 +817,29 @@ fn ground_slam(

if !animation.is_finished() {
// Do a forward jump thing
//TODO: Fix hacky way to get a forward jump

// Control x movement
if animation.current_frame < attack_frames.startup {
if facing.is_left() {
velocity.x -= 150.0;
velocity.x -= 50.0;
} else {
velocity.x += 150.0;
velocity.x += 50.0;
}
}

// Control y movement
// TODO: Attack moves up and down the same amount, fixed distance, but it would be
// nice to be able to tune the speed of the fall so it feels more impactful yet
// doesnt have a "snap/reset effect" at the end of animation while still landing at
// the same Y as started(?)
// it might be nice to store movement properties as metadata attached to frame
// ranges or individual frames?
if animation.current_frame < attack_frames.startup {
velocity.y += 270.0;
let v_per_frame = 800.0 / attack_frames.startup as f32;
velocity.y += v_per_frame;
} else if animation.current_frame < attack_frames.active {
velocity.y -= 180.0;
let v_per_frame = 800.0 / (attack_frames.active - attack_frames.startup) as f32;
velocity.y -= v_per_frame;
}

// If the animation is finished
Expand Down