From 9aad8dd13015ee6ac59e03afb7200f47eceb4af7 Mon Sep 17 00:00:00 2001 From: Harald Hoyer Date: Tue, 15 Apr 2025 12:28:17 +0200 Subject: [PATCH] refactor: improve code formatting and readability in components and resources --- src/components.rs | 12 ++++++------ src/resources.rs | 21 +++++++++++++++------ 2 files changed, 21 insertions(+), 12 deletions(-) diff --git a/src/components.rs b/src/components.rs index e19bbf9..adc5021 100644 --- a/src/components.rs +++ b/src/components.rs @@ -35,16 +35,16 @@ pub struct FormationTarget { // Enum defining different ways an enemy can attack #[derive(Component, Clone, Copy, PartialEq, Debug)] pub enum AttackPattern { - SwoopDive, // Original pattern: dive towards center, then off screen - DirectDive, // Dive straight down + SwoopDive, // Original pattern: dive towards center, then off screen + DirectDive, // Dive straight down Kamikaze(Vec3), // Dive towards a specific target location (e.g., player's last known position) - Needs target Vec3 - // Add more patterns later (e.g., FigureEight, Looping) + // Add more patterns later (e.g., FigureEight, Looping) } #[derive(Component, Clone, PartialEq, Debug)] // Added Debug derive pub enum EnemyState { - Entering, // Flying onto the screen towards formation target - InFormation, // Holding position in the formation + Entering, // Flying onto the screen towards formation target + InFormation, // Holding position in the formation Attacking(AttackPattern), // Diving towards the player using a specific pattern } @@ -53,4 +53,4 @@ pub struct EnemyBullet; // Game Over UI Component (might move to ui.rs later if more UI exists) #[derive(Component)] -pub struct GameOverUI; \ No newline at end of file +pub struct GameOverUI; diff --git a/src/resources.rs b/src/resources.rs index bd2970c..3483422 100644 --- a/src/resources.rs +++ b/src/resources.rs @@ -31,8 +31,10 @@ impl Default for FormationLayout { for i in 0..crate::constants::FORMATION_ENEMY_COUNT { let row = i / crate::constants::FORMATION_COLS; let col = i % crate::constants::FORMATION_COLS; - let target_x = (col as f32 - (crate::constants::FORMATION_COLS as f32 - 1.0) / 2.0) * crate::constants::FORMATION_X_SPACING; - let target_y = crate::constants::FORMATION_BASE_Y - (row as f32 * crate::constants::FORMATION_Y_SPACING); + let target_x = (col as f32 - (crate::constants::FORMATION_COLS as f32 - 1.0) / 2.0) + * crate::constants::FORMATION_X_SPACING; + let target_y = crate::constants::FORMATION_BASE_Y + - (row as f32 * crate::constants::FORMATION_Y_SPACING); positions.push(Vec3::new(target_x, target_y, 0.0)); } FormationLayout { @@ -81,15 +83,22 @@ impl Default for StageConfigurations { let count = 16; // Example: Fewer enemies in a circle for i in 0..count { let angle = (i as f32 / count as f32) * 2.0 * std::f32::consts::PI; - positions.push(Vec3::new(angle.cos() * radius, center_y + angle.sin() * radius, 0.0)); + positions.push(Vec3::new( + angle.cos() * radius, + center_y + angle.sin() * radius, + 0.0, + )); + } + FormationLayout { + name: "Circle".to_string(), + positions, } - FormationLayout { name: "Circle".to_string(), positions } }; let stage2 = StageConfig { formation_layout: stage2_layout, enemy_count: 16, attack_patterns: vec![AttackPattern::SwoopDive, AttackPattern::DirectDive], // Add direct dive - attack_dive_interval: 2.5, // Faster dives + attack_dive_interval: 2.5, // Faster dives enemy_speed_multiplier: 1.2, // Faster enemies enemy_shoot_interval: ENEMY_SHOOT_INTERVAL * 0.8, // Faster shooting }; @@ -122,4 +131,4 @@ pub struct FormationState { #[derive(Resource)] pub struct AttackDiveTimer { pub timer: Timer, -} \ No newline at end of file +}