diff --git a/README.md b/README.md index 40ade1c..0aa2adf 100644 --- a/README.md +++ b/README.md @@ -82,6 +82,8 @@ ______ - Rust格式化: `cargo fmt` - clippy提交检查:`cargo clippy --locked --workspace --all-targets --all-features -- --deny warnings` - 本地开发运行:`cargo run` +- Powershell打开调试日志:`$env:RUST_LOG="debug"` +- Powershell打开追踪日志:`$env:RUST_BACKTRACE=1; cargo run` # 4. 发布 [Itch.io](https://cloudhu.itch.io/skywalker2088) diff --git a/assets/data/consumables.ron b/assets/data/consumables.ron index edc316c..3973a5d 100644 --- a/assets/data/consumables.ron +++ b/assets/data/consumables.ron @@ -8,7 +8,7 @@ acceleration: (8.0, 8.0), deceleration: (5.0, 5.0), speed: (0.0, 120.0), - z_level: 15.0, + z_level: 915.0, initial_motion: ( random_linvel: Some(((-100, 50), (100, 100))), random_angvel: Some((-3.0, 3.0)), @@ -33,7 +33,7 @@ acceleration: (8.0, 8.0), deceleration: (5.0, 5.0), speed: (0.0, 120.0), - z_level: 15.0, + z_level: 915.0, initial_motion: ( random_linvel: Some(((-100, 50), (100, 100))), random_angvel: Some((-3.0, 3.0)), @@ -58,7 +58,7 @@ acceleration: (8.0, 8.0), deceleration: (5.0, 5.0), speed: (0.0, 120.0), - z_level: 15.0, + z_level: 915.0, initial_motion: ( random_linvel: Some(((-120, 50), (120, 120))), random_angvel: Some((-5.0, 5.0)), @@ -83,7 +83,7 @@ acceleration: (8.0, 8.0), deceleration: (5.0, 5.0), speed: (0.0, 120.0), - z_level: 15.0, + z_level: 915.0, initial_motion: ( random_linvel: Some(((-100, 50), (100, 100))), random_angvel: Some((-3.0, 3.0)), @@ -108,7 +108,7 @@ acceleration: (8.0, 8.0), deceleration: (5.0, 5.0), speed: (0.0, 120.0), - z_level: 15.0, + z_level: 915.0, initial_motion: ( random_linvel: Some(((-100, 50), (100, 100))), random_angvel: Some((-3.0, 3.0)), diff --git a/assets/data/effects.ron b/assets/data/effects.ron index 13ba508..04342d9 100644 --- a/assets/data/effects.ron +++ b/assets/data/effects.ron @@ -2,7 +2,7 @@ AllyBlastExplosion: ( effect_type: AllyBlastExplosion, effect_behaviors_data: [FadeOutAndDespawnAfterAnimation], - z_level: 10.0, + z_level: 909.0, animation: ( direction: Forward, frame_duration: 0.1, @@ -17,7 +17,7 @@ EnemyBlastExplosion: ( effect_type: EnemyBlastExplosion, effect_behaviors_data: [FadeOutAndDespawnAfterAnimation], - z_level: 10.5, + z_level: 909.5, animation: ( direction: Forward, frame_duration: 0.1, @@ -32,7 +32,7 @@ AllyBlastDespawn: ( effect_type: AllyBlastDespawn, effect_behaviors_data: [FadeOutAndDespawnAfterAnimation], - z_level: 9.0, + z_level: 909.0, animation: ( direction: Forward, frame_duration: 0.1, @@ -47,7 +47,7 @@ EnemyBlastDespawn: ( effect_type: EnemyBlastDespawn, effect_behaviors_data: [FadeOutAndDespawnAfterAnimation], - z_level: 9.0, + z_level: 909.0, animation: ( direction: Forward, frame_duration: 0.1, @@ -62,7 +62,7 @@ MobExplosion: ( effect_type: MobExplosion, effect_behaviors_data: [FadeOutAndDespawnAfterAnimation], - z_level: -5.0, + z_level: 904.0, animation: ( direction: Forward, frame_duration: 0.1, @@ -77,7 +77,7 @@ ConsumableDespawn: ( effect_type: ConsumableDespawn, effect_behaviors_data: [FadeOutAndDespawnAfterAnimation], - z_level: 9.0, + z_level: 909.0, animation: ( direction: Forward, frame_duration: 0.05, @@ -92,7 +92,7 @@ BarrierGlow: ( effect_type: BarrierGlow, effect_behaviors_data: [], - z_level: 25.0, + z_level: 925.0, animation: ( direction: PingPong(Forward), frame_duration: 0.2, @@ -107,7 +107,7 @@ AllyBulletDespawn: ( effect_type: AllyBulletDespawn, effect_behaviors_data: [FadeOutAndDespawnAfterAnimation], - z_level: 9.0, + z_level: 909.0, animation: ( direction: Forward, frame_duration: 0.1, @@ -122,7 +122,7 @@ EnemyBulletDespawn: ( effect_type: EnemyBulletDespawn, effect_behaviors_data: [FadeOutAndDespawnAfterAnimation], - z_level: 9.0, + z_level: 909.0, animation: ( direction: Forward, frame_duration: 0.1, @@ -137,7 +137,7 @@ AllyBulletExplosion: ( effect_type: AllyBulletExplosion, effect_behaviors_data: [FadeOutAndDespawnAfterAnimation], - z_level: 9.0, + z_level: 909.0, animation: ( direction: Forward, frame_duration: 0.1, @@ -152,7 +152,7 @@ EnemyBulletExplosion: ( effect_type: EnemyBulletExplosion, effect_behaviors_data: [FadeOutAndDespawnAfterAnimation], - z_level: 9.0, + z_level: 909.0, animation: ( direction: Forward, frame_duration: 0.1, @@ -167,7 +167,7 @@ Text(DamageDealt): ( effect_type: Text(DamageDealt), effect_behaviors_data: [FadeOut(0.55)], - z_level: 10.0, + z_level: 909.0, animation: ( direction: None, frame_duration: 0.1, @@ -182,7 +182,7 @@ Text(ConsumableCollected(Money1)): ( effect_type: Text(ConsumableCollected(Money1)), effect_behaviors_data: [FadeOut(0.55)], - z_level: 10.0, + z_level: 909.0, animation: ( direction: None, frame_duration: 0.1, @@ -197,7 +197,7 @@ Text(ConsumableCollected(Money3)): ( effect_type: Text(ConsumableCollected(Money3)), effect_behaviors_data: [FadeOut(0.55)], - z_level: 10.0, + z_level: 909.0, animation: ( direction: None, frame_duration: 0.1, @@ -212,7 +212,7 @@ Text(ConsumableCollected(HealthWrench)): ( effect_type: Text(ConsumableCollected(HealthWrench)), effect_behaviors_data: [FadeOut(0.55)], - z_level: 10.0, + z_level: 909.0, animation: ( direction: None, frame_duration: 0.1, @@ -227,7 +227,7 @@ Text(ConsumableCollected(Armor)): ( effect_type: Text(ConsumableCollected(Armor)), effect_behaviors_data: [FadeOut(0.55)], - z_level: 10.0, + z_level: 909.0, animation: ( direction: None, frame_duration: 0.1, @@ -242,7 +242,7 @@ Text(ConsumableCollected(GainProjectiles)): ( effect_type: Text(ConsumableCollected(GainProjectiles)), effect_behaviors_data: [FadeOut(0.55)], - z_level: 10.0, + z_level: 909.0, animation: ( direction: None, frame_duration: 0.1, diff --git a/assets/data/items.ron b/assets/data/items.ron index a31f56e..fb08af3 100644 --- a/assets/data/items.ron +++ b/assets/data/items.ron @@ -7,7 +7,7 @@ acceleration: (8.0, 8.0), deceleration: (5.0, 5.0), speed: (0.0, 120.0), - z_level: 15.0, + z_level: 915.0, initial_motion: ( random_linvel: Some(((-100, 50),(100, 100))), random_angvel: Some((-3.0, 3.0)), diff --git a/assets/data/mob_segments.ron b/assets/data/mob_segments.ron index 6167ff3..3821869 100644 --- a/assets/data/mob_segments.ron +++ b/assets/data/mob_segments.ron @@ -17,7 +17,7 @@ defense_interaction: Some(Heal(10)), health: 60, consumable_drops: Nothing, - z_level: 5.0, + z_level: 705.0, anchor_point: (0.0, -30.0), behaviors: [ReceiveDamageOnImpact, DieAtZeroHealth], ), @@ -38,7 +38,7 @@ defense_interaction: Some(Heal(10)), health: 60, consumable_drops: Standard, - z_level: 5.0, + z_level: 705.0, anchor_point: (0.0, -30.0), behaviors: [DealDamageToPlayerOnImpact, ReceiveDamageOnImpact, DieAtZeroHealth], ), @@ -59,7 +59,7 @@ defense_interaction: Some(Heal(10)), health: 60, consumable_drops: Standard, - z_level: 5.0, + z_level: 705.0, anchor_point: (0.0, -30.0), behaviors: [DealDamageToPlayerOnImpact, ReceiveDamageOnImpact, DieAtZeroHealth], mob_segment_anchor_points: Some([( @@ -88,7 +88,7 @@ collision_sound: Squishy, health: 35, consumable_drops: Standard, - z_level: 4.9, + z_level: 704.9, anchor_point: (0.0, 40.0), behaviors: [ DealDamageToPlayerOnImpact, @@ -119,7 +119,7 @@ collision_sound: Squishy, health: 35, consumable_drops: Standard, - z_level: 4.9, + z_level: 704.9, anchor_point: (0.0, 40.0), behaviors: [ DealDamageToPlayerOnImpact, @@ -150,7 +150,7 @@ collision_sound: Squishy, health: 35, consumable_drops: Standard, - z_level: 4.9, + z_level: 704.9, anchor_point: (0.0, 40.0), behaviors: [ DealDamageToPlayerOnImpact, @@ -181,7 +181,7 @@ health: 450, density: 2.3, consumable_drops: Standard, - z_level: 4.9, + z_level: 704.9, anchor_point: (0.0, -51.0), behaviors: [ DealDamageToPlayerOnImpact, @@ -229,7 +229,7 @@ health: 450, density: 2.3, consumable_drops: Standard, - z_level: 5.1, + z_level: 705.1, anchor_point: (-75.0, 48.0), behaviors: [], mob_segment_anchor_points: Some([ @@ -265,7 +265,7 @@ health: 450, density: 2.3, consumable_drops: Standard, - z_level: 5.1, + z_level: 705.1, anchor_point: (75.0, 48.0), behaviors: [], mob_segment_anchor_points: Some([ @@ -306,7 +306,7 @@ health: 650, density: 2.3, consumable_drops: Standard, - z_level: 5.2, + z_level: 705.2, anchor_point: (-28.0, 80.0), behaviors: [], mob_segment_anchor_points: Some([ @@ -361,7 +361,7 @@ health: 650, density: 2.3, consumable_drops: Standard, - z_level: 5.2, + z_level: 705.2, anchor_point: (28.0, 80.0), behaviors: [], mob_segment_anchor_points: Some([ @@ -411,7 +411,7 @@ health: 700, density: 2.3, consumable_drops: Standard, - z_level: 5.3, + z_level: 705.3, anchor_point: (42.0, -23.0), behaviors: [], ), @@ -437,7 +437,7 @@ health: 700, density: 2.3, consumable_drops: Standard, - z_level: 5.3, + z_level: 705.3, anchor_point: (-42.0, -23.0), behaviors: [], ), @@ -463,7 +463,7 @@ health: 725, density: 3.3, consumable_drops: Standard, - z_level: 5.1, + z_level: 705.1, anchor_point: (0.0, -51.0), behaviors: [ DealDamageToPlayerOnImpact, @@ -511,7 +511,7 @@ health: 725, density: 3.3, consumable_drops: Standard, - z_level: 5.0, + z_level: 705.0, anchor_point: (-75.0, 48.0), behaviors: [], mob_segment_anchor_points: Some([ @@ -547,7 +547,7 @@ health: 725, density: 3.3, consumable_drops: Standard, - z_level: 5.0, + z_level: 705.0, anchor_point: (75.0, 48.0), behaviors: [], mob_segment_anchor_points: Some([ @@ -588,7 +588,7 @@ health: 1050, density: 3.3, consumable_drops: Standard, - z_level: 5.1, + z_level: 705.1, anchor_point: (-28.0, 80.0), behaviors: [], mob_segment_anchor_points: Some([ @@ -666,7 +666,7 @@ health: 1050, density: 3.3, consumable_drops: Standard, - z_level: 5.1, + z_level: 705.1, anchor_point: (28.0, 80.0), behaviors: [], mob_segment_anchor_points: Some([ @@ -754,7 +754,7 @@ health: 1100, density: 3.3, consumable_drops: Standard, - z_level: 5.3, + z_level: 705.3, anchor_point: (50.0, 0.0), behaviors: [], ), @@ -795,7 +795,7 @@ health: 1100, density: 3.3, consumable_drops: Standard, - z_level: 5.3, + z_level: 705.3, anchor_point: (-50.0, 0.0), behaviors: [], ), @@ -821,7 +821,7 @@ health: 1000, density: 3.6, consumable_drops: Standard, - z_level: 5.1, + z_level: 705.1, anchor_point: (0.0, -51.0), behaviors: [ DealDamageToPlayerOnImpact, @@ -869,7 +869,7 @@ health: 1000, density: 3.6, consumable_drops: Standard, - z_level: 5.0, + z_level: 705.0, anchor_point: (-75.0, 48.0), behaviors: [], mob_segment_anchor_points: Some([ @@ -905,7 +905,7 @@ health: 1000, density: 3.6, consumable_drops: Standard, - z_level: 5.0, + z_level: 705.0, anchor_point: (75.0, 48.0), behaviors: [], mob_segment_anchor_points: Some([ @@ -946,7 +946,7 @@ health: 1450, density: 3.6, consumable_drops: Standard, - z_level: 5.1, + z_level: 705.1, anchor_point: (-28.0, 80.0), behaviors: [], mob_segment_anchor_points: Some([ @@ -1029,7 +1029,7 @@ health: 1450, density: 3.6, consumable_drops: Standard, - z_level: 5.1, + z_level: 705.1, anchor_point: (28.0, 80.0), behaviors: [], mob_segment_anchor_points: Some([ @@ -1122,7 +1122,7 @@ health: 1500, density: 3.6, consumable_drops: Standard, - z_level: 5.3, + z_level: 705.3, anchor_point: (50.0, 0.0), behaviors: [], ), @@ -1163,7 +1163,7 @@ health: 1500, density: 3.6, consumable_drops: Standard, - z_level: 5.3, + z_level: 705.3, anchor_point: (-50.0, 0.0), behaviors: [], ), diff --git a/assets/data/mobs.ron b/assets/data/mobs.ron index f9cdc07..4d0898c 100644 --- a/assets/data/mobs.ron +++ b/assets/data/mobs.ron @@ -175,7 +175,7 @@ rotation: 0.0, ) ], - z_level: 5.0, + z_level: 705.0, consumable_drops: Boss, health: 2400, density: 3.8, @@ -396,7 +396,7 @@ rotation: 0.0, ) ], - z_level: 5.0, + z_level: 705.0, consumable_drops: Boss, health: 1800, density: 3.5, @@ -617,7 +617,7 @@ rotation: 0.0, ) ], - z_level: 5.0, + z_level: 705.0, consumable_drops: Boss, health: 1200, density: 2.7, @@ -683,7 +683,7 @@ rotation: 0.0, ), ], - z_level: 5.0, + z_level: 705.0, consumable_drops: Standard, health: 40, animation: ( @@ -738,7 +738,7 @@ rotation: 0.0, ), ], - z_level: 5.0, + z_level: 705.0, consumable_drops: Standard, health: 40, animation: ( @@ -788,7 +788,7 @@ rotation: 0.0, ) ], - z_level: 5.0, + z_level: 705.0, consumable_drops: Standard, health: 30, animation: ( @@ -829,7 +829,7 @@ rotation: 0.0, ) ], - z_level: 5.0, + z_level: 705.0, consumable_drops: Standard, health: 20, animation: ( @@ -893,7 +893,7 @@ rotation: 0.0, ) ], - z_level: 5.0, + z_level: 705.0, consumable_drops: Standard, health: 50, animation: ( @@ -1134,7 +1134,7 @@ rotation: 0.0, ) ], - z_level: 6.0, + z_level: 506.0, health: 80, animation: ( direction: None, @@ -1179,7 +1179,7 @@ rotation: 0.0, ) ], - z_level: 6.0, + z_level: 506.0, health: 80, animation: ( direction: None, @@ -1224,7 +1224,7 @@ rotation: 0.0, ) ], - z_level: 6.0, + z_level: 506.0, health: 80, animation: ( direction: None, @@ -1275,7 +1275,7 @@ rotation: 0.0, ) ], - z_level: 5.0, + z_level: 705.0, consumable_drops: Standard, health: 50, animation: ( @@ -1323,7 +1323,7 @@ rotation: 0.0, ) ], - z_level: 5.0, + z_level: 705.0, health: 15, animation: ( direction: Forward, @@ -1363,7 +1363,7 @@ rotation: 0.0, ) ], - z_level: 5.0, + z_level: 705.0, consumable_drops: Standard, health: 20, animation: ( @@ -1426,7 +1426,7 @@ rotation: 0.0, ) ], - z_level: 5.0, + z_level: 705.0, consumable_drops: Standard, health: 20, animation: ( @@ -1478,7 +1478,7 @@ can_rotate: true, speed: (0.0, 75.0), collision_damage: 7, - z_level: 4.0, + z_level: 504.0, consumable_drops: MoneyAsteroid, initial_motion: ( random_angvel: Some((-1.0, 1.0)), @@ -1512,7 +1512,7 @@ rotation: 0.0, ) ], - z_level: 5.0, + z_level: 705.0, consumable_drops: Nothing, health: 15, animation: ( diff --git a/assets/data/projectiles.ron b/assets/data/projectiles.ron index 77bce9e..e175a97 100644 --- a/assets/data/projectiles.ron +++ b/assets/data/projectiles.ron @@ -3,7 +3,7 @@ projectile_type: Blast(Enemy), spawnable_behaviors: [], projectile_behaviors: [ExplodeOnIntersection, DealDamageOnIntersection], - z_level: 20.0, + z_level: 300.0, animation: ( direction: None, frame_duration: 1.0 @@ -26,7 +26,7 @@ spawnable_behaviors: [], projectile_behaviors: [ExplodeOnIntersection, DealDamageOnIntersection], collider_dimensions: (1.5, 1.5), - z_level: 20.0, + z_level: 300.0, animation: ( direction: None, frame_duration: 1.0 @@ -49,7 +49,7 @@ spawnable_behaviors: [], projectile_behaviors: [ExplodeOnIntersection, DealDamageOnIntersection], collider_dimensions: (1.5, 1.5), - z_level: 19.0, + z_level: 319.0, animation: ( direction: None, frame_duration: 1.0 @@ -72,7 +72,7 @@ spawnable_behaviors: [], projectile_behaviors: [DealDamageOnContact, ExplodeOnContact], collider_dimensions: (1.5, 1.5), - z_level: 20.0, + z_level: 320.0, animation: ( direction: None, frame_duration: 1.0 @@ -95,7 +95,7 @@ spawnable_behaviors: [], projectile_behaviors: [DealDamageOnContact, ExplodeOnContact], collider_dimensions: (1.5, 1.5), - z_level: 20.0, + z_level: 320.0, animation: ( direction: None, frame_duration: 1.0 @@ -118,7 +118,7 @@ spawnable_behaviors: [], projectile_behaviors: [DealDamageOnContact, ExplodeOnContact], collider_dimensions: (1.5, 1.5), - z_level: 19.0, + z_level: 319.0, animation: ( direction: None, frame_duration: 1.0 diff --git a/src/animation/mod.rs b/src/animation/mod.rs index a164d4a..e2a9d12 100644 --- a/src/animation/mod.rs +++ b/src/animation/mod.rs @@ -1,8 +1,8 @@ //! Exposes a component to tag animatable sprite sheets, along with the plugin with associated //! systems to animate + clean up 2D sprite-based animations. -use crate::assets::game_assets::AppStates; use crate::components::events::AnimationCompletedEvent; -use crate::gameplay::GameStates; +use crate::components::states::AppStates; +use crate::components::states::GameStates; use bevy::{ app::{App, Plugin, Update}, asset::Assets, diff --git a/src/arena/barrier.rs b/src/arena/barrier.rs index defb555..e694a79 100644 --- a/src/arena/barrier.rs +++ b/src/arena/barrier.rs @@ -1,6 +1,6 @@ -use crate::assets::game_assets::AppStates; use crate::collision::{HORIZONTAL_BARRIER_COLLIDER_GROUP, SPAWNABLE_COLLIDER_GROUP}; use crate::components::spawnable::EffectType; +use crate::components::states::AppStates; use crate::options::resources::GameParametersResource; use crate::spawnable::SpawnEffectEvent; use bevy::prelude::{ @@ -18,61 +18,61 @@ use std::f32::consts::FRAC_PI_2; pub struct ArenaBarrierComponent; /// Spawns arena barriers arranged in a centered rectangle -pub(super) fn spawn_barriers_system( - mut commands: Commands, - mut spawn_effect: EventWriter, - game_parameters: Res, -) { - // TODO: move hard coded values to data file - // spawn horizontal barriers at top and bottom of arena - spawn_spawnables_pass_barrier(&mut commands, Vec2::new(0.0, 360.0), 1000.0, 30.0); - spawn_spawnables_pass_barrier(&mut commands, Vec2::new(0.0, -360.0), 1000.0, 30.0); +// pub(super) fn spawn_barriers_system( +// mut commands: Commands, +// mut spawn_effect: EventWriter, +// game_parameters: Res, +// ) { +// TODO: move hard coded values to data file +// spawn horizontal barriers at top and bottom of arena +// spawn_spawnables_pass_barrier(&mut commands, Vec2::new(0.0, 360.0), 1000.0, 30.0); +// spawn_spawnables_pass_barrier(&mut commands, Vec2::new(0.0, -360.0), 1000.0, 30.0); +// +// // spawn vertical barriers at right and left of arena +// spawn_barrier(&mut commands, Vec2::new(500.0, 0.0), 30.0, 10000.0); +// spawn_barrier(&mut commands, Vec2::new(-500.0, 0.0), 30.0, 10000.0); +// +// // spawn horizontal barriers +// spawn_barrier(&mut commands, Vec2::new(0.0, 2250.0), 3000.0, 30.0); - // spawn vertical barriers at right and left of arena - spawn_barrier(&mut commands, Vec2::new(500.0, 0.0), 30.0, 10000.0); - spawn_barrier(&mut commands, Vec2::new(-500.0, 0.0), 30.0, 10000.0); - - // spawn horizontal barriers - spawn_barrier(&mut commands, Vec2::new(0.0, 2250.0), 3000.0, 30.0); - - // spawn barrier glow effect - spawn_effect.send(SpawnEffectEvent { - effect_type: EffectType::BarrierGlow, - transform: Transform { - translation: Vec3::new(0.0, -355.0, 1.0), - scale: Vec3::new(10.0, game_parameters.sprite_scale, 1.0), - ..Default::default() - }, - ..Default::default() - }); - spawn_effect.send(SpawnEffectEvent { - effect_type: EffectType::BarrierGlow, - transform: Transform { - translation: Vec3::new(0.0, 355.0, 1.0), - scale: Vec3::new(10.0, game_parameters.sprite_scale, 1.0), - ..Default::default() - }, - ..Default::default() - }); - spawn_effect.send(SpawnEffectEvent { - effect_type: EffectType::BarrierGlow, - transform: Transform { - translation: Vec3::new(495.0, 0.0, 1.0), - scale: Vec3::new(7.3, game_parameters.sprite_scale, 1.0), - rotation: Quat::from_rotation_z(FRAC_PI_2), - }, - ..Default::default() - }); - spawn_effect.send(SpawnEffectEvent { - effect_type: EffectType::BarrierGlow, - transform: Transform { - translation: Vec3::new(-495.0, 0.0, 1.0), - scale: Vec3::new(7.3, game_parameters.sprite_scale, 1.0), - rotation: Quat::from_rotation_z(FRAC_PI_2), - }, - ..Default::default() - }); -} +// spawn barrier glow effect +// spawn_effect.send(SpawnEffectEvent { +// effect_type: EffectType::BarrierGlow, +// transform: Transform { +// translation: Vec3::new(0.0, -355.0, 1.0), +// scale: Vec3::new(10.0, game_parameters.sprite_scale, 1.0), +// ..Default::default() +// }, +// ..Default::default() +// }); +// spawn_effect.send(SpawnEffectEvent { +// effect_type: EffectType::BarrierGlow, +// transform: Transform { +// translation: Vec3::new(0.0, 355.0, 1.0), +// scale: Vec3::new(10.0, game_parameters.sprite_scale, 1.0), +// ..Default::default() +// }, +// ..Default::default() +// }); +// spawn_effect.send(SpawnEffectEvent { +// effect_type: EffectType::BarrierGlow, +// transform: Transform { +// translation: Vec3::new(495.0, 0.0, 1.0), +// scale: Vec3::new(7.3, game_parameters.sprite_scale, 1.0), +// rotation: Quat::from_rotation_z(FRAC_PI_2), +// }, +// ..Default::default() +// }); +// spawn_effect.send(SpawnEffectEvent { +// effect_type: EffectType::BarrierGlow, +// transform: Transform { +// translation: Vec3::new(-495.0, 0.0, 1.0), +// scale: Vec3::new(7.3, game_parameters.sprite_scale, 1.0), +// rotation: Quat::from_rotation_z(FRAC_PI_2), +// }, +// ..Default::default() +// }); +// } /// Spawns an arena barrier fn spawn_barrier(commands: &mut Commands, position: Vec2, width: f32, height: f32) { diff --git a/src/arena/gate.rs b/src/arena/gate.rs index 6194352..c1d31a0 100644 --- a/src/arena/gate.rs +++ b/src/arena/gate.rs @@ -1,5 +1,5 @@ -use crate::assets::game_assets::AppStates; use crate::components::events::MobReachedBottomGateEvent; +use crate::components::states::AppStates; use crate::spawnable::{MobComponent, MobSegmentComponent, SpawnableComponent}; use bevy::prelude::StateScoped; use bevy::{ diff --git a/src/arena/mod.rs b/src/arena/mod.rs index b7e9dfd..c32ea57 100644 --- a/src/arena/mod.rs +++ b/src/arena/mod.rs @@ -1,11 +1,11 @@ //! Exposes a plugin that renders a rectangular boundary that the player cannot cross, but mobs //! can. Also handles sending events when mobs reach the botton of the screen. -use crate::assets::game_assets::AppStates; use crate::assets::game_assets::GameEnterSet; use crate::components::events::MobReachedBottomGateEvent; -use crate::gameplay::GameStates; -use barrier::spawn_barriers_system; +use crate::components::states::AppStates; +use crate::components::states::GameStates; +// use barrier::spawn_barriers_system; use bevy::{ app::{App, Plugin, Update}, prelude::{in_state, IntoSystemConfigs, OnEnter}, @@ -28,7 +28,7 @@ impl Plugin for ArenaPlugin { app.add_systems( OnEnter(AppStates::Game), - (spawn_barriers_system, spawn_despawn_gates_system).in_set(GameEnterSet::BuildLevel), + spawn_despawn_gates_system.in_set(GameEnterSet::BuildLevel), //TODO: spawn_barriers_system ); app.add_systems( diff --git a/src/assets/game_assets.rs b/src/assets/game_assets.rs index 3111f9c..cddb241 100644 --- a/src/assets/game_assets.rs +++ b/src/assets/game_assets.rs @@ -6,6 +6,7 @@ use crate::assets::mob::MobAssets; use crate::assets::player_assets::PlayerAssets; use crate::assets::projectile::ProjectileAssets; use crate::assets::ui::UiAssets; +use crate::components::states::AppStates; use bevy::app::App; use bevy::asset::Handle; use bevy::prelude::*; @@ -79,8 +80,6 @@ pub struct Music { } pub(super) fn plugin(app: &mut App) { - app.init_state::(); - app.enable_state_scoped_entities::(); app.add_loading_state( LoadingState::new(AppStates::LoadingAssets) .continue_to_state(AppStates::MainMenu) @@ -176,21 +175,6 @@ pub enum GameUpdateSet { Cleanup, } -/// The game's main screen states. -#[derive(States, Debug, Hash, PartialEq, Eq, Clone, Default)] -pub enum AppStates { - #[default] - Splash, - LoadingAssets, - MainMenu, - CharacterSelection, - InitializeRun, - Credits, - Game, - GameOver, - Victory, -} - // setup rapier fn setup_physics(mut rapier_config: ResMut) { rapier_config.timestep_mode = TimestepMode::Fixed { diff --git a/src/audio.rs b/src/audio.rs index 037de0a..6ba29ea 100644 --- a/src/audio.rs +++ b/src/audio.rs @@ -18,7 +18,7 @@ pub(super) fn plugin(app: &mut App) { app.add_systems( Update, (play_sound_effect_system, change_bg_music_system) - .run_if(resource_added::), + .run_if(resource_exists::), ); } @@ -81,7 +81,7 @@ fn change_bg_music_system( stop_command.fade_out(AudioTween::new(fade_out, AudioEasing::Linear)); } } - + // info!("play_sound_effect_system: change_bg_music_event"); // play music if provided a type if let Some(bg_music_type) = event.bg_music_type.clone() { let mut start_command = diff --git a/src/camera/mod.rs b/src/camera/mod.rs index f48cbec..1b4a0df 100644 --- a/src/camera/mod.rs +++ b/src/camera/mod.rs @@ -3,8 +3,8 @@ use self::screen_shake::{ add_trauma_system, screen_shake_on_player_damage_system, screen_shake_system, }; -use crate::assets::game_assets::AppStates; use crate::components::events::ScreenShakeEvent; +use crate::components::states::AppStates; use crate::options::resources::GameParametersResource; use crate::util::RenderLayer; use bevy::app::{App, Plugin, Startup, Update}; diff --git a/src/camera/screen_shake.rs b/src/camera/screen_shake.rs index 46abec4..81a306d 100644 --- a/src/camera/screen_shake.rs +++ b/src/camera/screen_shake.rs @@ -1,7 +1,6 @@ //! Shake the screen when the player receives damage. There is some randomness in the initial //! jolt, with the camera eventually moving back to the original location (centered) -use crate::components::events::ScreenShakeEvent; -use crate::components::health::DamageDealtEvent; +use crate::components::events::{ScreenShakeEvent, TakeDamageEvent}; use crate::components::player::PlayerComponent; use bevy::{ core_pipeline::{core_2d::Camera2d, core_3d::Camera3d}, @@ -84,12 +83,12 @@ fn get_random_shake(screen_shake: &ScreenShakeComponent) -> f32 { /// Trigger a screen shake whenever the player receives nonzero damage. pub(super) fn screen_shake_on_player_damage_system( - mut damage_dealt_events: EventReader, + mut damage_dealt_events: EventReader, player_query: Query>, mut screen_shake_event_writer: EventWriter, ) { for event in damage_dealt_events.read() { - if player_query.contains(event.target) && event.damage > 0 { + if player_query.contains(event.target) && event.damage.amount > 0 { screen_shake_event_writer.send(ScreenShakeEvent { trauma: 0.23 }); } } diff --git a/src/collision/mod.rs b/src/collision/mod.rs index 20cb843..e6fede9 100644 --- a/src/collision/mod.rs +++ b/src/collision/mod.rs @@ -1,7 +1,7 @@ -use crate::assets::game_assets::AppStates; use crate::assets::game_assets::GameUpdateSet; use crate::components::spawnable::Faction; -use crate::gameplay::GameStates; +use crate::components::states::AppStates; +use crate::components::states::GameStates; use bevy::{ app::{App, Plugin, Update}, prelude::{in_state, Entity, Event, IntoSystemConfigs}, diff --git a/src/components/events.rs b/src/components/events.rs index 660325e..046d627 100644 --- a/src/components/events.rs +++ b/src/components/events.rs @@ -1,3 +1,4 @@ +use crate::components::health::Damage; use crate::components::objectives::DefenseInteraction; use crate::components::player::PlayerInput; use crate::components::spawnable::{MobSegmentType, MobType}; @@ -47,3 +48,9 @@ pub struct PlayerJoinEvent { pub player_idx: u8, pub input: PlayerInput, } + +#[derive(Event)] +pub struct TakeDamageEvent { + pub target: Entity, + pub damage: Damage, +} diff --git a/src/components/game.rs b/src/components/game.rs new file mode 100644 index 0000000..4c51b36 --- /dev/null +++ b/src/components/game.rs @@ -0,0 +1,13 @@ +use bevy::math::Vec2; +use bevy::prelude::{Component, Timer}; + +#[derive(Component)] +pub struct ShouldDespawn; + +#[derive(Component)] +pub struct ExplosionRender { + pub origin: Vec2, + pub radius: f32, + pub ttl: Timer, + pub fade_out: bool, +} diff --git a/src/components/health.rs b/src/components/health.rs index 5ca23a3..e8f45c4 100644 --- a/src/components/health.rs +++ b/src/components/health.rs @@ -26,12 +26,6 @@ pub struct Seeker(pub Entity); #[derive(Reflect, Component)] pub struct Owner(pub Entity); -#[derive(Event)] -pub struct DamageDealtEvent { - pub damage: usize, - pub target: Entity, -} - #[derive(Component)] pub struct HealthComponent { /// Current health value @@ -170,3 +164,18 @@ impl HealthComponent { self.health = self.max_health; } } + +#[derive(Component, Copy, Clone)] +pub struct Damage { + pub amount: usize, + pub is_crit: bool, +} + +impl Damage { + pub fn from_amount(amount: usize) -> Self { + Self { + amount, + is_crit: false, + } + } +} diff --git a/src/components/mod.rs b/src/components/mod.rs index 1351e13..6648821 100644 --- a/src/components/mod.rs +++ b/src/components/mod.rs @@ -2,9 +2,11 @@ pub mod abilities; pub mod audio; pub mod character; pub mod events; +pub mod game; pub mod health; pub mod input; pub mod objectives; pub mod player; pub mod spawnable; +pub mod states; pub mod weapon; diff --git a/src/components/states.rs b/src/components/states.rs new file mode 100644 index 0000000..8842510 --- /dev/null +++ b/src/components/states.rs @@ -0,0 +1,27 @@ +use bevy::prelude::States; + +/// The game's gameplay states. +#[derive(Debug, Clone, Copy, Default, Eq, PartialEq, Hash, States)] +pub enum GameStates { + #[default] + Playing, + Selection, + Paused, + GameOver, + Victory, +} + +/// The game's states. +#[derive(States, Debug, Hash, PartialEq, Eq, Clone, Default)] +pub enum AppStates { + #[default] + Splash, + LoadingAssets, + MainMenu, + CharacterSelection, + InitializeRun, + Credits, + Game, + GameOver, + Victory, +} diff --git a/src/dev_tools.rs b/src/dev_tools.rs index a401bea..59551fa 100644 --- a/src/dev_tools.rs +++ b/src/dev_tools.rs @@ -1,7 +1,7 @@ //! Development tools for the game. This plugin is only enabled in dev builds. -use crate::assets::game_assets::AppStates; -use crate::gameplay::GameStates; +use crate::components::states::AppStates; +use crate::components::states::GameStates; use bevy::{ dev_tools::{ states::log_transitions, diff --git a/src/enemy/mod.rs b/src/enemy/mod.rs index bdb5037..7468095 100644 --- a/src/enemy/mod.rs +++ b/src/enemy/mod.rs @@ -5,9 +5,10 @@ mod final_boss; mod mothership; use bevy::prelude::*; -use crate::assets::game_assets::AppStates; use crate::assets::game_assets::Fonts; use crate::components::player::PlayerComponent; +use crate::components::states::AppStates; +use crate::components::states::GameStates; use crate::enemy::drone::spawn_drone; use crate::enemy::drone_boss::spawn_drone_boss; use crate::enemy::fighter::spawn_fighter; @@ -15,7 +16,6 @@ use crate::enemy::final_boss::spawn_final_boss; use crate::enemy::mothership::spawn_mothership; use crate::gameplay::gamelogic::{game_not_paused, GameTime}; use crate::gameplay::physics::Physics; -use crate::gameplay::GameStates; use crate::ship::engine::{Engine, EngineMethod}; use crate::util::{Math, RenderLayer}; use rand::Rng; diff --git a/src/gameplay/control.rs b/src/gameplay/control.rs index 0dc46ee..5ec535d 100644 --- a/src/gameplay/control.rs +++ b/src/gameplay/control.rs @@ -1,9 +1,9 @@ use crate::components::player::PlayerComponent; +use crate::components::states::{AppStates, GameStates}; use crate::{ gameplay::{ gamelogic::{game_not_paused, PlayerLevel}, loot::Cargo, - GameStates, }, ship::engine::Engine, AppSet, @@ -11,7 +11,6 @@ use crate::{ use bevy::input::mouse::MouseWheel; use bevy::prelude::*; use bevy::window::WindowMode; -use crate::assets::game_assets::AppStates; pub(super) fn plugin(app: &mut App) { app.add_systems( @@ -52,7 +51,7 @@ pub fn player_control( .cursor_position() .and_then(|cursor| camera.viewport_to_world(camera_transform, cursor)) .map(|ray| ray.origin.truncate()); - // println!("Player controlled at {:?}", engine.target); + debug!("Player controlled at {:?}", engine.target); } else { engine.target = None; } diff --git a/src/gameplay/effects.rs b/src/gameplay/effects.rs index 301d81f..3264fb6 100644 --- a/src/gameplay/effects.rs +++ b/src/gameplay/effects.rs @@ -1,4 +1,4 @@ -use crate::assets::game_assets::AppStates; +use crate::components::states::AppStates; use crate::gameplay::gamelogic::game_not_paused; use crate::util::Colour; use crate::AppSet; diff --git a/src/gameplay/gamelogic.rs b/src/gameplay/gamelogic.rs index 7295379..e9f03cf 100644 --- a/src/gameplay/gamelogic.rs +++ b/src/gameplay/gamelogic.rs @@ -1,13 +1,13 @@ -use crate::assets::game_assets::AppStates; use crate::assets::game_assets::Fonts; -use crate::components::health::{DamageDealtEvent, HealthComponent}; +use crate::components::events::TakeDamageEvent; +use crate::components::game::{ExplosionRender, ShouldDespawn}; +use crate::components::health::HealthComponent; use crate::components::player::{PlayerComponent, PlayersResource}; use crate::components::spawnable::{EffectType, TextEffectType}; +use crate::components::states::*; use crate::gameplay::effects::{FloatingText, HitFlash}; use crate::gameplay::loot::{DropsLoot, IsLoot, Points, WorthPoints}; use crate::gameplay::physics::{Collider, Physics}; -use crate::gameplay::GameStates; -use crate::ship::bullet::{ExplosionRender, ShouldDespawn}; use crate::spawnable::SpawnEffectEvent; use crate::util::{Colour, Math, RenderLayer}; use crate::AppSet; @@ -63,18 +63,6 @@ impl PlayerLevel { } } -#[derive(Component, Copy, Clone)] -pub struct Damage { - pub amount: usize, - pub is_crit: bool, -} - -#[derive(Event)]//TODO:replace DamageDealtEvent -pub struct TakeDamageEvent { - pub entity: Entity, - pub damage: Damage, -} - #[derive(PartialEq)] pub enum Allegiance { Friend, @@ -101,17 +89,16 @@ impl Default for WillTarget { pub(super) fn plugin(app: &mut App) { app.add_event::() - .add_event::() .add_systems(OnEnter(AppStates::Game), setup_new_game); app.add_systems(OnExit(AppStates::Game), reset_game); app.add_systems( Update, ( - game_time_system, + // game_time_system, camera_follow.before(ParallaxSystems), - combat_system, + shield_recharge_system, take_damage_events, - death_system, + drop_loot_system, ) .chain() .in_set(AppSet::TickTimers) @@ -180,14 +167,12 @@ pub fn camera_follow( } } -pub fn combat_system( - mut commands: Commands, +pub fn shield_recharge_system( time: Res