forked from DigitalExtinction/Game
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixes DigitalExtinction#262.
- Loading branch information
Showing
12 changed files
with
223 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -42,5 +42,8 @@ | |
"range": 50.0, | ||
"damage": 3.0, | ||
"recharge_interval": 2.5 | ||
}, | ||
"movement": { | ||
"max_heigth": 5.0 | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
use bevy::prelude::*; | ||
use de_core::{ | ||
objects::MovableSolid, | ||
stages::GameStage, | ||
state::{AppState, GameState}, | ||
}; | ||
use iyes_loopless::prelude::*; | ||
|
||
use crate::{ | ||
movement::DesiredVelocity, | ||
repulsion::{RepulsionLables, RepulsionVelocity}, | ||
MAX_ACCELERATION, MAX_VERTICAL_SPEED, | ||
}; | ||
|
||
pub(crate) struct AltitudePlugin; | ||
|
||
impl Plugin for AltitudePlugin { | ||
fn build(&self, app: &mut App) { | ||
app.add_system_to_stage( | ||
GameStage::PreMovement, | ||
setup_entities.run_in_state(AppState::InGame), | ||
) | ||
.add_system_set_to_stage( | ||
GameStage::Movement, | ||
SystemSet::new().with_system( | ||
update | ||
.run_in_state(GameState::Playing) | ||
.label(AltitudeLabels::Update) | ||
.after(RepulsionLables::Apply), | ||
), | ||
); | ||
} | ||
} | ||
|
||
#[derive(Copy, Clone, Hash, Debug, PartialEq, Eq, SystemLabel)] | ||
pub(crate) enum AltitudeLabels { | ||
Update, | ||
} | ||
|
||
#[derive(Component, Default)] | ||
pub(crate) struct DesiredClimbing(f32); | ||
|
||
impl DesiredClimbing { | ||
pub(crate) fn speed(&self) -> f32 { | ||
self.0 | ||
} | ||
|
||
pub(crate) fn set_speed(&mut self, speed: f32) { | ||
self.0 = speed; | ||
} | ||
} | ||
|
||
fn setup_entities( | ||
mut commands: Commands, | ||
objects: Query<Entity, (With<MovableSolid>, Without<DesiredClimbing>)>, | ||
) { | ||
for entity in objects.iter() { | ||
commands.entity(entity).insert(DesiredClimbing::default()); | ||
} | ||
} | ||
|
||
fn update( | ||
mut objects: Query<( | ||
&DesiredVelocity<RepulsionVelocity>, | ||
&mut DesiredClimbing, | ||
&Transform, | ||
)>, | ||
) { | ||
objects.par_for_each_mut(512, |(horizontal, mut climbing, transform)| { | ||
let desired_height = if horizontal.stationary() { | ||
0. | ||
} else { | ||
// TODO use max_height | ||
10. | ||
}; | ||
|
||
let remaining = desired_height - transform.translation.y; | ||
let desired = remaining.signum() | ||
* MAX_VERTICAL_SPEED.min((2. * remaining.abs() * MAX_ACCELERATION).sqrt()); | ||
|
||
// Avoid change detection when possible. | ||
if climbing.speed() != desired { | ||
climbing.set_speed(desired); | ||
} | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.