-
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.
- Loading branch information
Showing
19 changed files
with
704 additions
and
487 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
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,12 @@ | ||
use bevy::prelude::*; | ||
|
||
#[derive(Component)] | ||
pub struct Enemy { | ||
pub speed: f32, | ||
} | ||
|
||
impl Default for Enemy { | ||
fn default() -> Self { | ||
Self { speed: 0.01 } | ||
} | ||
} |
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,24 @@ | ||
use crate::AppState; | ||
use bevy::{animation::animate_targets, prelude::*}; | ||
use systems::*; | ||
|
||
pub mod components; | ||
pub mod resources; | ||
mod systems; | ||
|
||
pub struct EnemyPlugin; | ||
|
||
impl Plugin for EnemyPlugin { | ||
fn build(&self, app: &mut App) { | ||
app.add_systems( | ||
Update, | ||
enemies_once_loaded | ||
.before(animate_targets) | ||
.run_if(in_state(AppState::Game)), | ||
) | ||
.add_systems( | ||
Update, | ||
(enemies_update, enemies_animation).run_if(in_state(AppState::Game)), | ||
); | ||
} | ||
} |
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,8 @@ | ||
use bevy::prelude::*; | ||
|
||
#[derive(Resource)] | ||
pub struct Animations { | ||
pub animations: Vec<AnimationNodeIndex>, | ||
#[allow(dead_code)] | ||
pub graph: Handle<AnimationGraph>, | ||
} |
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,73 @@ | ||
use super::{components::Enemy, resources::Animations}; | ||
use crate::game::player::components::Player; | ||
use avian3d::prelude::*; | ||
use bevy::prelude::*; | ||
use std::time::Duration; | ||
|
||
pub fn enemies_once_loaded( | ||
mut commands: Commands, | ||
animations: Res<Animations>, | ||
mut players: Query<(Entity, &mut AnimationPlayer), Added<AnimationPlayer>>, | ||
) { | ||
for (entity, mut player) in &mut players { | ||
let mut transitions = AnimationTransitions::new(); | ||
|
||
// Make sure to start the animation via the `AnimationTransitions` | ||
// component. The `AnimationTransitions` component wants to manage all | ||
// the animations and will get confused if the animations are started | ||
// directly via the `AnimationPlayer`. | ||
transitions | ||
.play(&mut player, animations.animations[0], Duration::ZERO) | ||
.repeat(); | ||
|
||
commands | ||
.entity(entity) | ||
.insert(animations.graph.clone()) | ||
.insert(transitions); | ||
} | ||
} | ||
|
||
pub fn enemies_update( | ||
mut e_query: Query<(&mut Transform, &mut LinearVelocity, &Visibility, &Enemy), Without<Player>>, | ||
p_query: Query<&Transform, (With<Player>, Without<Enemy>)>, | ||
) { | ||
if let Ok(p_transform) = p_query.get_single() { | ||
for (mut e_transform, mut linear_velocity, visibility, enemy) in &mut e_query { | ||
if *visibility != Visibility::Hidden { | ||
e_transform.look_at(p_transform.translation, Vec3::Y); | ||
let direction = p_transform.translation - e_transform.translation; | ||
if direction.length() > 1.5 { | ||
let movement_direction = direction.normalize(); | ||
linear_velocity.0 += movement_direction * enemy.speed; | ||
} | ||
// BlurTimer = 200; | ||
} | ||
} | ||
} | ||
} | ||
|
||
pub fn enemies_animation( | ||
mut animation_players: Query< | ||
( | ||
&mut AnimationPlayer, | ||
&mut AnimationTransitions, | ||
&LinearVelocity, | ||
), | ||
With<Enemy>, | ||
>, | ||
animations: Res<Animations>, | ||
) { | ||
for (mut player, mut transitions, linear_velocity) in &mut animation_players { | ||
let current_animation = if linear_velocity.length() > 0.0 { | ||
animations.animations[1] | ||
} else { | ||
animations.animations[0] | ||
}; | ||
|
||
if !player.is_playing_animation(current_animation) { | ||
transitions | ||
.play(&mut player, current_animation, Duration::ZERO) | ||
.repeat(); | ||
} | ||
} | ||
} |
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,4 @@ | ||
use bevy::prelude::*; | ||
|
||
#[derive(Component)] | ||
pub struct Glimpse; |
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,14 @@ | ||
use crate::AppState; | ||
use bevy::prelude::*; | ||
use systems::update_glimpses; | ||
|
||
pub mod components; | ||
mod systems; | ||
|
||
pub struct GlimpsePlugin; | ||
|
||
impl Plugin for GlimpsePlugin { | ||
fn build(&self, app: &mut App) { | ||
app.add_systems(Update, update_glimpses.run_if(in_state(AppState::Game))); | ||
} | ||
} |
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,31 @@ | ||
use super::components::Glimpse; | ||
use crate::{game::player::components::Player, resources::AudioAssets}; | ||
use bevy::prelude::*; | ||
|
||
#[allow(clippy::type_complexity)] | ||
pub fn update_glimpses( | ||
mut commands: Commands, | ||
audio_assets: Res<AudioAssets>, | ||
g_query: Query<(&Transform, Entity), (With<Glimpse>, Without<Player>)>, | ||
p_query: Query<(&Player, &Transform), Without<Glimpse>>, | ||
) { | ||
for (player, p_transform) in &p_query { | ||
for (g_transform, g_entity) in &g_query { | ||
if player.floor_index - 1 == ((-g_transform.translation.y - 0.5) / 2.0) as usize | ||
&& p_transform.translation.distance(Vec3::new( | ||
g_transform.translation.x, | ||
g_transform.translation.y, | ||
g_transform.translation.z, | ||
)) < 2.3 | ||
{ | ||
// TODO: Make a 3d audio | ||
commands.spawn(AudioBundle { | ||
source: audio_assets.no_sfx.clone(), | ||
settings: PlaybackSettings::DESPAWN, | ||
}); | ||
|
||
commands.entity(g_entity).despawn(); | ||
} | ||
} | ||
} | ||
} |
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 |
---|---|---|
@@ -1,8 +1,5 @@ | ||
use bevy::prelude::*; | ||
|
||
#[derive(Component)] | ||
pub struct Glimpse; | ||
|
||
#[derive(Component)] | ||
pub struct FloorLabelUi; | ||
|
||
|
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,20 @@ | ||
use crate::AppState; | ||
use bevy::prelude::*; | ||
use resources::ObjectPool; | ||
use systems::*; | ||
|
||
pub mod components; | ||
pub mod resources; | ||
pub mod systems; | ||
|
||
pub const FLOOR_AMOUNT: usize = 210; | ||
|
||
pub struct MapPlugin; | ||
|
||
impl Plugin for MapPlugin { | ||
fn build(&self, app: &mut App) { | ||
app.insert_resource(ObjectPool::default()) | ||
.add_systems(OnEnter(AppState::Game), spawn_map) | ||
.add_systems(Update, update_floors.run_if(in_state(AppState::Game))); | ||
} | ||
} |
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.