feat: Enhance enemy attack dive mechanics with swooping movement towards the center
This commit is contained in:
parent
45482f9e11
commit
6acfee2f95
|
@ -65,7 +65,7 @@ nix develop --command bash -c "cargo build"
|
||||||
* **Enemy Attack Dives:**
|
* **Enemy Attack Dives:**
|
||||||
* ~~Give enemies an `Attacking` state/component.~~ **(DONE)**
|
* ~~Give enemies an `Attacking` state/component.~~ **(DONE)**
|
||||||
* ~~Periodically trigger enemies in the formation to switch to the `Attacking` state.~~ **(DONE - Random selection after formation complete)**
|
* ~~Periodically trigger enemies in the formation to switch to the `Attacking` state.~~ **(DONE - Random selection after formation complete)**
|
||||||
* Define attack paths (swooping dives towards the player area). **(Basic downward dive implemented)**
|
* ~~Define attack paths (swooping dives towards the player area).~~ **(DONE - Basic swoop towards center implemented)**
|
||||||
* ~~Make enemies fire bullets (downwards or towards the player) during their dives.~~ **(DONE - Downward)**
|
* ~~Make enemies fire bullets (downwards or towards the player) during their dives.~~ **(DONE - Downward)**
|
||||||
* After an attack dive, enemies could return to their formation position or fly off-screen. **(Fly off-screen implemented)**
|
* After an attack dive, enemies could return to their formation position or fly off-screen. **(Fly off-screen implemented)**
|
||||||
* **Enemy Variety:**
|
* **Enemy Variety:**
|
||||||
|
|
26
src/main.rs
26
src/main.rs
|
@ -714,8 +714,30 @@ fn move_enemies(
|
||||||
for (entity, mut transform, state) in attacking_query.iter_mut() { // Get state from query
|
for (entity, mut transform, state) in attacking_query.iter_mut() { // Get state from query
|
||||||
// *** Explicitly check if the enemy is actually in the Attacking state ***
|
// *** Explicitly check if the enemy is actually in the Attacking state ***
|
||||||
if *state == EnemyState::Attacking {
|
if *state == EnemyState::Attacking {
|
||||||
// Move straight down ONLY if attacking
|
// --- Swooping Dive Logic ---
|
||||||
transform.translation.y -= attack_speed * time.delta_seconds();
|
let delta_seconds = time.delta_seconds();
|
||||||
|
let vertical_movement = attack_speed * delta_seconds;
|
||||||
|
|
||||||
|
// Horizontal movement: Move towards the center (x=0)
|
||||||
|
let horizontal_speed_factor = 0.5; // Adjust this to control the swoop intensity
|
||||||
|
let horizontal_movement = if transform.translation.x < 0.0 {
|
||||||
|
attack_speed * horizontal_speed_factor * delta_seconds
|
||||||
|
} else if transform.translation.x > 0.0 {
|
||||||
|
-attack_speed * horizontal_speed_factor * delta_seconds
|
||||||
|
} else {
|
||||||
|
0.0 // No horizontal movement if exactly at center
|
||||||
|
};
|
||||||
|
|
||||||
|
// Apply movement
|
||||||
|
transform.translation.y -= vertical_movement;
|
||||||
|
transform.translation.x += horizontal_movement;
|
||||||
|
|
||||||
|
// Ensure enemy doesn't overshoot the center horizontally if moving towards it
|
||||||
|
if (transform.translation.x - horizontal_movement < 0.0 && transform.translation.x > 0.0)
|
||||||
|
|| (transform.translation.x - horizontal_movement > 0.0 && transform.translation.x < 0.0)
|
||||||
|
{
|
||||||
|
transform.translation.x = 0.0;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
// Enemies that are InFormation but Without<FormationTarget> will now be ignored by this movement logic.
|
// Enemies that are InFormation but Without<FormationTarget> will now be ignored by this movement logic.
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue