chore(deps): upgrade Bevy 0.13 → 0.18
Three major versions of breaking changes: - Bundles → Required Components (SpriteBundle, NodeBundle, ButtonBundle, TextBundle, Camera2dBundle removed; spawn tuples of components instead) - Style merged into Node; TextStyle split into TextFont + TextColor - Color API: rgb/rgba → srgb/srgba; Color::Rgba pattern matching replaced with .alpha()/.set_alpha(); .r()/.g()/.b() → .to_srgba().red/green/blue - Time: delta_seconds() → delta_secs(); elapsed_seconds() → elapsed_secs() - Query: get_single()/get_single_mut() → single()/single_mut() (now Result) - Timer::finished() → Timer::is_finished() - despawn_recursive() removed (despawn() is now recursive); despawn_descendants() removed — replaced with Children query iteration - BorderColor(c) → BorderColor::all(c) - WindowResolution: From<(f32,f32)> removed → cast to (u32,u32) - flake.nix: added wayland to runtime libs (default-on in 0.18) Tests pass (8/8), clippy clean, headless render verified showing start menu, button, starfield, and player ship. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
parent
7a4305677b
commit
b2b564f690
11 changed files with 2746 additions and 1028 deletions
3367
Cargo.lock
generated
3367
Cargo.lock
generated
File diff suppressed because it is too large
Load diff
|
|
@ -4,5 +4,5 @@ version = "0.1.0"
|
|||
edition = "2021"
|
||||
|
||||
[dependencies]
|
||||
bevy = "0.13"
|
||||
bevy = "0.18"
|
||||
fastrand = "2.0.1"
|
||||
|
|
|
|||
|
|
@ -26,6 +26,7 @@
|
|||
libxi
|
||||
libxkbcommon
|
||||
libxcb
|
||||
wayland
|
||||
vulkan-loader
|
||||
glfw
|
||||
];
|
||||
|
|
|
|||
|
|
@ -19,7 +19,7 @@ pub fn move_bullets(
|
|||
mut commands: Commands,
|
||||
) {
|
||||
for (entity, mut transform) in query.iter_mut() {
|
||||
transform.translation.y += BULLET_SPEED * time.delta_seconds();
|
||||
transform.translation.y += BULLET_SPEED * time.delta_secs();
|
||||
|
||||
if transform.translation.y > WINDOW_HEIGHT / 2.0 + BULLET_SIZE.y {
|
||||
commands.entity(entity).despawn();
|
||||
|
|
@ -65,7 +65,7 @@ pub fn move_enemy_bullets(
|
|||
mut query: Query<(Entity, &mut Transform), With<EnemyBullet>>,
|
||||
) {
|
||||
for (entity, mut transform) in query.iter_mut() {
|
||||
transform.translation.y -= ENEMY_BULLET_SPEED * time.delta_seconds();
|
||||
transform.translation.y -= ENEMY_BULLET_SPEED * time.delta_secs();
|
||||
|
||||
// Despawn if off screen (bottom)
|
||||
if transform.translation.y < -WINDOW_HEIGHT / 2.0 - ENEMY_BULLET_SIZE.y {
|
||||
|
|
@ -84,7 +84,7 @@ pub fn check_enemy_bullet_player_collisions(
|
|||
player_query: Query<(Entity, &Transform), (With<Player>, Without<Invincible>)>,
|
||||
enemy_bullet_query: Query<(Entity, &Transform), With<EnemyBullet>>,
|
||||
) {
|
||||
if let Ok((player_entity, player_transform)) = player_query.get_single() {
|
||||
if let Ok((player_entity, player_transform)) = player_query.single() {
|
||||
for (bullet_entity, bullet_transform) in enemy_bullet_query.iter() {
|
||||
let distance = player_transform
|
||||
.translation
|
||||
|
|
|
|||
|
|
@ -37,12 +37,12 @@ pub const ENEMY_BULLET_PLAYER_COLLISION_THRESHOLD: f32 =
|
|||
// Tractor beam constants
|
||||
pub const TRACTOR_BEAM_WIDTH: f32 = 20.0;
|
||||
pub const TRACTOR_BEAM_DURATION: f32 = 3.0;
|
||||
pub const TRACTOR_BEAM_COLOR: Color = Color::rgba(0.5, 0.0, 0.8, 0.6);
|
||||
pub const TRACTOR_BEAM_COLOR: Color = Color::srgba(0.5, 0.0, 0.8, 0.6);
|
||||
pub const CAPTURE_DURATION: f32 = 10.0; // How long the player stays captured
|
||||
// Tractor beam visual constants
|
||||
pub const BEAM_GLOW_WIDTH: f32 = 40.0;
|
||||
pub const BEAM_GLOW_COLOR: Color = Color::rgba(0.3, 0.0, 0.5, 0.25);
|
||||
pub const BEAM_CORE_COLOR: Color = Color::rgba(0.7, 0.2, 1.0, 0.7);
|
||||
pub const BEAM_GLOW_COLOR: Color = Color::srgba(0.3, 0.0, 0.5, 0.25);
|
||||
pub const BEAM_CORE_COLOR: Color = Color::srgba(0.7, 0.2, 1.0, 0.7);
|
||||
pub const BEAM_PULSE_FREQ: f32 = 3.0;
|
||||
pub const BEAM_PULSE_AMPLITUDE: f32 = 0.15;
|
||||
|
||||
|
|
@ -58,4 +58,4 @@ pub const STAR_Z_DEPTH: f32 = -10.0; // Behind all game entities
|
|||
pub const EXPLOSION_DURATION: f32 = 0.4;
|
||||
pub const EXPLOSION_BASE_SIZE: Vec2 = Vec2::new(15.0, 15.0);
|
||||
pub const EXPLOSION_MAX_SIZE: Vec2 = Vec2::new(50.0, 50.0);
|
||||
pub const EXPLOSION_COLOR: Color = Color::rgba(1.0, 0.6, 0.1, 1.0);
|
||||
pub const EXPLOSION_COLOR: Color = Color::srgba(1.0, 0.6, 0.1, 1.0);
|
||||
|
|
|
|||
114
src/enemy.rs
114
src/enemy.rs
|
|
@ -78,20 +78,17 @@ pub fn spawn_enemies(
|
|||
|
||||
// Determine sprite color based on type
|
||||
let sprite_color = match enemy_type {
|
||||
EnemyType::Grunt => Color::rgb(1.0, 0.2, 0.2),
|
||||
EnemyType::Boss => Color::rgb(0.8, 0.2, 1.0),
|
||||
EnemyType::Grunt => Color::srgb(1.0, 0.2, 0.2),
|
||||
EnemyType::Boss => Color::srgb(0.8, 0.2, 1.0),
|
||||
};
|
||||
|
||||
commands.spawn((
|
||||
SpriteBundle {
|
||||
sprite: Sprite {
|
||||
Sprite {
|
||||
color: sprite_color,
|
||||
custom_size: Some(ENEMY_SIZE),
|
||||
..default()
|
||||
},
|
||||
transform: Transform::from_translation(Vec3::new(spawn_x, spawn_y, 0.0)),
|
||||
..default()
|
||||
},
|
||||
Transform::from_translation(Vec3::new(spawn_x, spawn_y, 0.0)),
|
||||
Enemy {
|
||||
enemy_type,
|
||||
// Use shoot interval from stage config
|
||||
|
|
@ -154,7 +151,7 @@ pub fn move_enemies(
|
|||
// Calculate speeds for this frame
|
||||
let base_speed = ENEMY_SPEED * speed_multiplier;
|
||||
let attack_speed = base_speed * 1.5; // Attackers are faster
|
||||
let arrival_threshold = base_speed * time.delta_seconds() * 1.1; // Threshold for reaching formation target
|
||||
let arrival_threshold = base_speed * time.delta_secs() * 1.1; // Threshold for reaching formation target
|
||||
|
||||
// --- Handle Entering Enemies ---
|
||||
for (entity, mut transform, target, mut state) in entering_query.iter_mut() {
|
||||
|
|
@ -183,7 +180,7 @@ pub fn move_enemies(
|
|||
);
|
||||
} else {
|
||||
// Move towards target using base_speed
|
||||
let move_delta = direction.normalize() * base_speed * time.delta_seconds();
|
||||
let move_delta = direction.normalize() * base_speed * time.delta_secs();
|
||||
transform.translation += move_delta;
|
||||
}
|
||||
}
|
||||
|
|
@ -202,12 +199,12 @@ pub fn move_enemies(
|
|||
// ... existing patterns ...
|
||||
AttackPattern::SwoopDive => {
|
||||
// ... existing code ...
|
||||
let vertical_movement = attack_speed * time.delta_seconds();
|
||||
let vertical_movement = attack_speed * time.delta_secs();
|
||||
let horizontal_speed_factor = 0.5;
|
||||
let horizontal_movement = if transform.translation.x < 0.0 {
|
||||
attack_speed * horizontal_speed_factor * time.delta_seconds()
|
||||
attack_speed * horizontal_speed_factor * time.delta_secs()
|
||||
} else if transform.translation.x > 0.0 {
|
||||
-attack_speed * horizontal_speed_factor * time.delta_seconds()
|
||||
-attack_speed * horizontal_speed_factor * time.delta_secs()
|
||||
} else {
|
||||
0.0
|
||||
};
|
||||
|
|
@ -225,7 +222,7 @@ pub fn move_enemies(
|
|||
}
|
||||
}
|
||||
AttackPattern::DirectDive => {
|
||||
transform.translation.y -= attack_speed * time.delta_seconds();
|
||||
transform.translation.y -= attack_speed * time.delta_secs();
|
||||
}
|
||||
AttackPattern::Kamikaze(target) => {
|
||||
// Copy the target value rather than dereferencing
|
||||
|
|
@ -233,11 +230,11 @@ pub fn move_enemies(
|
|||
let target_pos = *target; // Dereference here
|
||||
let direction = target_pos - transform.translation;
|
||||
let distance = direction.length();
|
||||
let kamikaze_threshold = attack_speed * time.delta_seconds() * 1.1; // Threshold to stop near target
|
||||
let kamikaze_threshold = attack_speed * time.delta_secs() * 1.1; // Threshold to stop near target
|
||||
|
||||
if distance > kamikaze_threshold {
|
||||
let move_delta =
|
||||
direction.normalize() * attack_speed * time.delta_seconds();
|
||||
direction.normalize() * attack_speed * time.delta_secs();
|
||||
transform.translation += move_delta;
|
||||
} else {
|
||||
// Optionally stop or continue past target - for now, just stop moving towards it
|
||||
|
|
@ -247,7 +244,7 @@ pub fn move_enemies(
|
|||
// New CaptureBeam pattern - Bosses behave differently
|
||||
AttackPattern::CaptureBeam => {
|
||||
// For Grunt enemies, just do a direct dive (fallback)
|
||||
transform.translation.y -= attack_speed * time.delta_seconds();
|
||||
transform.translation.y -= attack_speed * time.delta_secs();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -261,7 +258,7 @@ pub fn move_enemies(
|
|||
if transform.translation.y > target_y {
|
||||
// Move down to position
|
||||
transform.translation.y -=
|
||||
attack_speed * 0.8 * time.delta_seconds();
|
||||
attack_speed * 0.8 * time.delta_secs();
|
||||
} else {
|
||||
// Once in position, stay there briefly before activating beam
|
||||
// Check if this boss already has a TractorBeam component
|
||||
|
|
@ -293,11 +290,11 @@ pub fn move_enemies(
|
|||
if direction.length() > 0.0 {
|
||||
let normalized_dir = direction.normalize();
|
||||
transform.translation +=
|
||||
normalized_dir * attack_speed * time.delta_seconds();
|
||||
normalized_dir * attack_speed * time.delta_secs();
|
||||
}
|
||||
}
|
||||
AttackPattern::DirectDive => {
|
||||
transform.translation.y -= attack_speed * time.delta_seconds();
|
||||
transform.translation.y -= attack_speed * time.delta_secs();
|
||||
}
|
||||
AttackPattern::Kamikaze(target) => {
|
||||
// Convert the target to a value type
|
||||
|
|
@ -306,12 +303,12 @@ pub fn move_enemies(
|
|||
|
||||
// If very close to target, just move straight down
|
||||
if direction.length() < 50.0 {
|
||||
transform.translation.y -= attack_speed * time.delta_seconds();
|
||||
transform.translation.y -= attack_speed * time.delta_secs();
|
||||
} else {
|
||||
// Move toward target
|
||||
let normalized_dir = direction.normalize();
|
||||
transform.translation +=
|
||||
normalized_dir * attack_speed * time.delta_seconds();
|
||||
normalized_dir * attack_speed * time.delta_secs();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -334,7 +331,7 @@ pub fn move_enemies(
|
|||
} else {
|
||||
// Move towards formation position
|
||||
let move_delta =
|
||||
direction.normalize() * return_speed * time.delta_seconds();
|
||||
direction.normalize() * return_speed * time.delta_secs();
|
||||
transform.translation += move_delta;
|
||||
}
|
||||
}
|
||||
|
|
@ -463,7 +460,7 @@ pub fn trigger_attack_dives(
|
|||
|
||||
// If Kamikaze, get player position (if player exists)
|
||||
if let AttackPattern::Kamikaze(_) = selected_pattern {
|
||||
if let Ok(player_transform) = player_query.get_single() {
|
||||
if let Ok(player_transform) = player_query.single() {
|
||||
selected_pattern = AttackPattern::Kamikaze(player_transform.translation);
|
||||
} else {
|
||||
// Fallback if player doesn't exist (e.g., just died)
|
||||
|
|
@ -496,21 +493,18 @@ pub fn enemy_shoot(
|
|||
if matches!(state, EnemyState::Attacking(_)) {
|
||||
// Use matches! macro
|
||||
enemy.shoot_cooldown.tick(time.delta());
|
||||
if enemy.shoot_cooldown.finished() {
|
||||
if enemy.shoot_cooldown.is_finished() {
|
||||
// println!("Enemy {:?} firing!", transform.translation); // Less verbose logging
|
||||
let bullet_start_pos = transform.translation
|
||||
- Vec3::Y * (ENEMY_SIZE.y / 2.0 + ENEMY_BULLET_SIZE.y / 2.0);
|
||||
|
||||
commands.spawn((
|
||||
SpriteBundle {
|
||||
sprite: Sprite {
|
||||
color: Color::rgb(1.0, 0.5, 0.5),
|
||||
Sprite {
|
||||
color: Color::srgb(1.0, 0.5, 0.5),
|
||||
custom_size: Some(ENEMY_BULLET_SIZE),
|
||||
..default()
|
||||
},
|
||||
transform: Transform::from_translation(bullet_start_pos),
|
||||
..default()
|
||||
},
|
||||
Transform::from_translation(bullet_start_pos),
|
||||
EnemyBullet,
|
||||
));
|
||||
|
||||
|
|
@ -546,6 +540,7 @@ pub fn boss_capture_attack(
|
|||
mut boss_query: Query<(Entity, &Transform, &mut TractorBeam)>,
|
||||
player_query: Query<(Entity, &Transform), (With<Player>, Without<Captured>)>, // Only target non-captured players
|
||||
enemy_query: Query<&EnemyState, With<Enemy>>,
|
||||
children_query: Query<&Children>,
|
||||
) {
|
||||
for (boss_entity, boss_transform, mut tractor_beam) in boss_query.iter_mut() {
|
||||
// Tick the beam timer
|
||||
|
|
@ -553,7 +548,7 @@ pub fn boss_capture_attack(
|
|||
|
||||
// If player exists and beam is not active yet, set player as target
|
||||
if !tractor_beam.active && tractor_beam.target.is_none() {
|
||||
if let Ok((player_entity, _)) = player_query.get_single() {
|
||||
if let Ok((player_entity, _)) = player_query.single() {
|
||||
tractor_beam.target = Some(player_entity);
|
||||
tractor_beam.active = true;
|
||||
println!(
|
||||
|
|
@ -566,33 +561,27 @@ pub fn boss_capture_attack(
|
|||
commands.entity(boss_entity).with_children(|parent| {
|
||||
// Outer glow layer (wide, dim)
|
||||
parent.spawn((
|
||||
SpriteBundle {
|
||||
sprite: Sprite {
|
||||
Sprite {
|
||||
color: BEAM_GLOW_COLOR,
|
||||
custom_size: Some(Vec2::new(BEAM_GLOW_WIDTH, beam_height)),
|
||||
..default()
|
||||
},
|
||||
transform: Transform::from_xyz(0.0, -beam_height / 2.0, -0.5),
|
||||
..default()
|
||||
},
|
||||
Transform::from_xyz(0.0, -beam_height / 2.0, -0.5),
|
||||
TractorBeamSprite,
|
||||
));
|
||||
// Inner core layer (narrow, bright, shorter)
|
||||
let core_height = beam_height * 0.6;
|
||||
parent.spawn((
|
||||
SpriteBundle {
|
||||
sprite: Sprite {
|
||||
Sprite {
|
||||
color: BEAM_CORE_COLOR,
|
||||
custom_size: Some(Vec2::new(TRACTOR_BEAM_WIDTH, core_height)),
|
||||
..default()
|
||||
},
|
||||
transform: Transform::from_xyz(
|
||||
Transform::from_xyz(
|
||||
0.0,
|
||||
-core_height / 2.0 - beam_height * 0.2,
|
||||
-0.3,
|
||||
),
|
||||
..default()
|
||||
},
|
||||
TractorBeamSprite,
|
||||
));
|
||||
});
|
||||
|
|
@ -601,7 +590,7 @@ pub fn boss_capture_attack(
|
|||
|
||||
// If beam is active, check if player is in beam's path
|
||||
if tractor_beam.active {
|
||||
if let Ok((player_entity, player_transform)) = player_query.get_single() {
|
||||
if let Ok((player_entity, player_transform)) = player_query.single() {
|
||||
// Check if player is roughly under the boss
|
||||
if (player_transform.translation.x - boss_transform.translation.x).abs()
|
||||
< tractor_beam.width / 2.0
|
||||
|
|
@ -622,14 +611,16 @@ pub fn boss_capture_attack(
|
|||
commands.entity(boss_entity).remove::<TractorBeam>();
|
||||
|
||||
// Change boss state to returning with captive
|
||||
if let Ok(enemy) = enemy_query.get(boss_entity) {
|
||||
if let EnemyState::Attacking(_) = enemy {
|
||||
if let Ok(EnemyState::Attacking(_)) = enemy_query.get(boss_entity) {
|
||||
commands
|
||||
.entity(boss_entity)
|
||||
.insert(EnemyState::ReturningWithCaptive);
|
||||
|
||||
// Clean up the beam visual
|
||||
commands.entity(boss_entity).despawn_descendants();
|
||||
if let Ok(children) = children_query.get(boss_entity) {
|
||||
for child in children.iter() {
|
||||
commands.entity(child).despawn();
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
|
@ -638,16 +629,19 @@ pub fn boss_capture_attack(
|
|||
}
|
||||
|
||||
// If beam timer finishes and player wasn't captured, end the beam attack
|
||||
if tractor_beam.timer.finished() {
|
||||
if tractor_beam.timer.is_finished() {
|
||||
println!("Boss {:?} tractor beam expired", boss_entity);
|
||||
commands.entity(boss_entity).remove::<TractorBeam>();
|
||||
|
||||
// Clean up the beam visual
|
||||
commands.entity(boss_entity).despawn_descendants();
|
||||
if let Ok(children) = children_query.get(boss_entity) {
|
||||
for child in children.iter() {
|
||||
commands.entity(child).despawn();
|
||||
}
|
||||
}
|
||||
|
||||
// Boss returns to formation after failed capture
|
||||
if let Ok(enemy_state) = enemy_query.get(boss_entity) {
|
||||
if let EnemyState::Attacking(_) = enemy_state {
|
||||
if let Ok(EnemyState::Attacking(_)) = enemy_query.get(boss_entity) {
|
||||
commands
|
||||
.entity(boss_entity)
|
||||
.insert(EnemyState::ReturningWithCaptive);
|
||||
|
|
@ -655,7 +649,6 @@ pub fn boss_capture_attack(
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Update tractor beam visual: pulse opacity and update beam height.
|
||||
pub fn update_tractor_beam_visual(
|
||||
|
|
@ -666,33 +659,20 @@ pub fn update_tractor_beam_visual(
|
|||
) {
|
||||
for (boss_entity, boss_transform, _tractor_beam) in boss_query.iter() {
|
||||
let current_beam_height = calculate_beam_height(boss_transform.translation.y);
|
||||
let time_secs = time.elapsed_seconds();
|
||||
let time_secs = time.elapsed_secs();
|
||||
|
||||
if let Ok(child_entities) = children.get(boss_entity) {
|
||||
for child in child_entities {
|
||||
if let Ok((mut sprite, mut transform)) = sprite_query.get_mut(*child) {
|
||||
// Update color pulse
|
||||
if let Color::Rgba {
|
||||
red,
|
||||
green,
|
||||
blue,
|
||||
mut alpha,
|
||||
} = sprite.color
|
||||
{
|
||||
let base_alpha = alpha;
|
||||
alpha = beam_pulse_alpha(
|
||||
let base_alpha = sprite.color.alpha();
|
||||
let new_alpha = beam_pulse_alpha(
|
||||
base_alpha,
|
||||
time_secs,
|
||||
BEAM_PULSE_FREQ,
|
||||
BEAM_PULSE_AMPLITUDE,
|
||||
);
|
||||
sprite.color = Color::Rgba {
|
||||
red,
|
||||
green,
|
||||
blue,
|
||||
alpha,
|
||||
};
|
||||
}
|
||||
sprite.color.set_alpha(new_alpha);
|
||||
|
||||
// Update size and position
|
||||
let current_width = sprite.custom_size.map(|s| s.x).unwrap_or(0.0);
|
||||
|
|
|
|||
|
|
@ -16,39 +16,35 @@ pub enum AppState {
|
|||
pub fn setup_game_over_ui(mut commands: Commands) {
|
||||
println!("Entering GameOver state. Setting up UI.");
|
||||
commands.spawn((
|
||||
TextBundle::from_section(
|
||||
"GAME OVER",
|
||||
TextStyle {
|
||||
Text::new("GAME OVER"),
|
||||
TextFont {
|
||||
font_size: 100.0,
|
||||
color: Color::WHITE,
|
||||
..default()
|
||||
},
|
||||
)
|
||||
.with_style(Style {
|
||||
TextColor(Color::WHITE),
|
||||
Node {
|
||||
position_type: PositionType::Absolute,
|
||||
align_self: AlignSelf::Center,
|
||||
justify_self: JustifySelf::Center,
|
||||
top: Val::Percent(40.0),
|
||||
..default()
|
||||
}),
|
||||
},
|
||||
GameOverUI,
|
||||
));
|
||||
commands.spawn((
|
||||
TextBundle::from_section(
|
||||
"Press R to Restart",
|
||||
TextStyle {
|
||||
Text::new("Press R to Restart"),
|
||||
TextFont {
|
||||
font_size: 32.0,
|
||||
color: Color::WHITE,
|
||||
..default()
|
||||
},
|
||||
)
|
||||
.with_style(Style {
|
||||
TextColor(Color::WHITE),
|
||||
Node {
|
||||
position_type: PositionType::Absolute,
|
||||
align_self: AlignSelf::Center,
|
||||
justify_self: JustifySelf::Center,
|
||||
top: Val::Percent(55.0),
|
||||
..default()
|
||||
}),
|
||||
},
|
||||
RestartMessage,
|
||||
));
|
||||
}
|
||||
|
|
@ -60,10 +56,10 @@ pub fn cleanup_game_over_ui(
|
|||
) {
|
||||
println!("Exiting GameOver state. Cleaning up UI.");
|
||||
for entity in query.iter() {
|
||||
commands.entity(entity).despawn_recursive();
|
||||
commands.entity(entity).despawn();
|
||||
}
|
||||
for entity in restart_query.iter() {
|
||||
commands.entity(entity).despawn_recursive();
|
||||
commands.entity(entity).despawn();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -76,8 +72,6 @@ pub fn cleanup_game_entities(
|
|||
enemy_bullet_query: Query<Entity, With<crate::components::EnemyBullet>>,
|
||||
enemy_query: Query<Entity, With<Enemy>>,
|
||||
restart_message_query: Query<Entity, With<crate::components::RestartMessage>>,
|
||||
// Optionally despawn player too, or handle separately if needed for restart
|
||||
// player_query: Query<Entity, With<Player>>,
|
||||
) {
|
||||
println!("Exiting Playing state. Cleaning up game entities.");
|
||||
for entity in bullet_query.iter() {
|
||||
|
|
@ -92,9 +86,6 @@ pub fn cleanup_game_entities(
|
|||
for entity in restart_message_query.iter() {
|
||||
commands.entity(entity).despawn();
|
||||
}
|
||||
// for entity in player_query.iter() {
|
||||
// commands.entity(entity).despawn();
|
||||
// }
|
||||
}
|
||||
|
||||
// --- Start Menu UI ---
|
||||
|
|
@ -102,11 +93,9 @@ pub fn cleanup_game_entities(
|
|||
pub fn setup_start_menu_ui(mut commands: Commands) {
|
||||
println!("Entering StartMenu state. Setting up UI.");
|
||||
|
||||
// Root UI container
|
||||
commands
|
||||
.spawn((
|
||||
NodeBundle {
|
||||
style: Style {
|
||||
Node {
|
||||
width: Val::Percent(100.0),
|
||||
height: Val::Percent(100.0),
|
||||
align_items: AlignItems::Center,
|
||||
|
|
@ -114,32 +103,28 @@ pub fn setup_start_menu_ui(mut commands: Commands) {
|
|||
flex_direction: FlexDirection::Column,
|
||||
..default()
|
||||
},
|
||||
..default()
|
||||
},
|
||||
StartMenuUI,
|
||||
))
|
||||
.with_children(|parent| {
|
||||
// Title
|
||||
parent.spawn(
|
||||
TextBundle::from_section(
|
||||
"BGLGA",
|
||||
TextStyle {
|
||||
parent.spawn((
|
||||
Text::new("BGLGA"),
|
||||
TextFont {
|
||||
font_size: 120.0,
|
||||
color: Color::WHITE,
|
||||
..default()
|
||||
},
|
||||
)
|
||||
.with_style(Style {
|
||||
TextColor(Color::WHITE),
|
||||
Node {
|
||||
margin: UiRect::bottom(Val::Px(50.0)),
|
||||
..default()
|
||||
}),
|
||||
);
|
||||
},
|
||||
));
|
||||
|
||||
// Start Game Button
|
||||
parent
|
||||
.spawn((
|
||||
ButtonBundle {
|
||||
style: Style {
|
||||
Button,
|
||||
Node {
|
||||
width: Val::Px(250.0),
|
||||
height: Val::Px(80.0),
|
||||
border: UiRect::all(Val::Px(2.0)),
|
||||
|
|
@ -147,20 +132,18 @@ pub fn setup_start_menu_ui(mut commands: Commands) {
|
|||
align_items: AlignItems::Center,
|
||||
..default()
|
||||
},
|
||||
border_color: BorderColor(Color::WHITE),
|
||||
background_color: BackgroundColor(Color::rgb(0.1, 0.1, 0.5)),
|
||||
..default()
|
||||
},
|
||||
BorderColor::all(Color::WHITE),
|
||||
BackgroundColor(Color::srgb(0.1, 0.1, 0.5)),
|
||||
StartButton,
|
||||
))
|
||||
.with_children(|parent| {
|
||||
parent.spawn(TextBundle::from_section(
|
||||
"Start Game",
|
||||
TextStyle {
|
||||
parent.spawn((
|
||||
Text::new("Start Game"),
|
||||
TextFont {
|
||||
font_size: 40.0,
|
||||
color: Color::WHITE,
|
||||
..default()
|
||||
},
|
||||
TextColor(Color::WHITE),
|
||||
));
|
||||
});
|
||||
});
|
||||
|
|
@ -169,7 +152,7 @@ pub fn setup_start_menu_ui(mut commands: Commands) {
|
|||
pub fn cleanup_start_menu_ui(mut commands: Commands, query: Query<Entity, With<StartMenuUI>>) {
|
||||
println!("Exiting StartMenu state. Cleaning up UI.");
|
||||
for entity in query.iter() {
|
||||
commands.entity(entity).despawn_recursive();
|
||||
commands.entity(entity).despawn();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -187,10 +170,10 @@ pub fn start_menu_button_system(
|
|||
app_state.set(AppState::Playing);
|
||||
}
|
||||
Interaction::Hovered => {
|
||||
color.0 = Color::rgb(0.2, 0.2, 0.7);
|
||||
color.0 = Color::srgb(0.2, 0.2, 0.7);
|
||||
}
|
||||
Interaction::None => {
|
||||
color.0 = Color::rgb(0.1, 0.1, 0.5);
|
||||
color.0 = Color::srgb(0.1, 0.1, 0.5);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,3 +1,5 @@
|
|||
#![allow(clippy::type_complexity)]
|
||||
|
||||
use bevy::prelude::*;
|
||||
use std::time::Duration;
|
||||
|
||||
|
|
@ -42,11 +44,11 @@ use starfield::scroll_starfield;
|
|||
|
||||
pub fn run() {
|
||||
App::new()
|
||||
.insert_resource(ClearColor(Color::rgb(0.0, 0.0, 0.1)))
|
||||
.insert_resource(ClearColor(Color::srgb(0.0, 0.0, 0.1)))
|
||||
.add_plugins(DefaultPlugins.set(WindowPlugin {
|
||||
primary_window: Some(Window {
|
||||
title: "BGLGA".into(),
|
||||
resolution: (WINDOW_WIDTH, WINDOW_HEIGHT).into(),
|
||||
resolution: (WINDOW_WIDTH as u32, WINDOW_HEIGHT as u32).into(),
|
||||
resizable: false,
|
||||
..default()
|
||||
}),
|
||||
|
|
|
|||
|
|
@ -14,19 +14,16 @@ use crate::systems::spawn_explosion;
|
|||
// Helper to spawn player (used in setup and respawn)
|
||||
pub fn spawn_player_ship(commands: &mut Commands) {
|
||||
commands.spawn((
|
||||
SpriteBundle {
|
||||
sprite: Sprite {
|
||||
color: Color::rgb(0.0, 0.5, 1.0),
|
||||
Sprite {
|
||||
color: Color::srgb(0.0, 0.5, 1.0),
|
||||
custom_size: Some(PLAYER_SIZE),
|
||||
..default()
|
||||
},
|
||||
transform: Transform::from_translation(Vec3::new(
|
||||
Transform::from_translation(Vec3::new(
|
||||
0.0,
|
||||
-WINDOW_HEIGHT / 2.0 + PLAYER_SIZE.y / 2.0 + 20.0,
|
||||
0.0,
|
||||
)),
|
||||
..default()
|
||||
},
|
||||
Player {
|
||||
speed: PLAYER_SPEED,
|
||||
shoot_cooldown: Timer::new(Duration::from_secs_f32(0.3), TimerMode::Once),
|
||||
|
|
@ -48,7 +45,7 @@ pub fn move_player(
|
|||
time: Res<Time>,
|
||||
) {
|
||||
// Using get_single_mut handles the case where player might not exist yet (or was just destroyed)
|
||||
if let Ok((mut transform, player)) = query.get_single_mut() {
|
||||
if let Ok((mut transform, player)) = query.single_mut() {
|
||||
let mut direction = 0.0;
|
||||
|
||||
if keyboard_input.pressed(KeyCode::KeyA) || keyboard_input.pressed(KeyCode::ArrowLeft) {
|
||||
|
|
@ -59,7 +56,7 @@ pub fn move_player(
|
|||
direction += 1.0;
|
||||
}
|
||||
|
||||
transform.translation.x += direction * player.speed * time.delta_seconds();
|
||||
transform.translation.x += direction * player.speed * time.delta_secs();
|
||||
let half_player_width = PLAYER_SIZE.x / 2.0;
|
||||
transform.translation.x = transform.translation.x.clamp(
|
||||
-WINDOW_WIDTH / 2.0 + half_player_width,
|
||||
|
|
@ -124,7 +121,7 @@ pub fn handle_captured_player(
|
|||
}
|
||||
|
||||
// If capture duration expires, player escapes but loses a life
|
||||
if captured.timer.finished() {
|
||||
if captured.timer.is_finished() {
|
||||
println!("Player escaped from capture after timer expired!");
|
||||
commands.entity(entity).remove::<Captured>();
|
||||
lose_life_and_respawn(
|
||||
|
|
@ -175,12 +172,12 @@ pub fn player_shoot(
|
|||
mut commands: Commands,
|
||||
time: Res<Time>,
|
||||
) {
|
||||
if let Ok((player_transform, mut player)) = query.get_single_mut() {
|
||||
if let Ok((player_transform, mut player)) = query.single_mut() {
|
||||
player.shoot_cooldown.tick(time.delta());
|
||||
|
||||
if (keyboard_input.just_pressed(KeyCode::Space)
|
||||
|| keyboard_input.just_pressed(KeyCode::ArrowUp))
|
||||
&& player.shoot_cooldown.finished()
|
||||
&& player.shoot_cooldown.is_finished()
|
||||
{
|
||||
player.shoot_cooldown.reset();
|
||||
|
||||
|
|
@ -188,15 +185,12 @@ pub fn player_shoot(
|
|||
+ Vec3::Y * (PLAYER_SIZE.y / 2.0 + BULLET_SIZE.y / 2.0);
|
||||
|
||||
commands.spawn((
|
||||
SpriteBundle {
|
||||
sprite: Sprite {
|
||||
color: Color::rgb(1.0, 1.0, 1.0),
|
||||
Sprite {
|
||||
color: Color::srgb(1.0, 1.0, 1.0),
|
||||
custom_size: Some(BULLET_SIZE),
|
||||
..default()
|
||||
},
|
||||
transform: Transform::from_translation(bullet_start_pos),
|
||||
..default()
|
||||
},
|
||||
Transform::from_translation(bullet_start_pos),
|
||||
Bullet,
|
||||
));
|
||||
}
|
||||
|
|
@ -217,7 +211,7 @@ pub fn check_player_enemy_collisions(
|
|||
enemy_query: Query<(Entity, &Transform), With<Enemy>>,
|
||||
) {
|
||||
// This system only runs if player exists and is not invincible, due to run_if
|
||||
if let Ok((player_entity, player_transform)) = player_query.get_single() {
|
||||
if let Ok((player_entity, player_transform)) = player_query.single() {
|
||||
for (enemy_entity, enemy_transform) in enemy_query.iter() {
|
||||
let distance = player_transform
|
||||
.translation
|
||||
|
|
@ -285,7 +279,7 @@ pub fn manage_invincibility(
|
|||
};
|
||||
}
|
||||
|
||||
if invincible.timer.finished() {
|
||||
if invincible.timer.is_finished() {
|
||||
println!("Invincibility finished.");
|
||||
commands.entity(entity).remove::<Invincible>();
|
||||
// Ensure player is visible when invincibility ends
|
||||
|
|
|
|||
|
|
@ -13,26 +13,23 @@ pub fn spawn_starfield(commands: &mut Commands) {
|
|||
let brightness = fastrand::f32() * 0.5 + 0.5; // 0.5 to 1.0
|
||||
|
||||
commands.spawn((
|
||||
SpriteBundle {
|
||||
sprite: Sprite {
|
||||
color: Color::rgb(brightness, brightness, brightness),
|
||||
Sprite {
|
||||
color: Color::srgb(brightness, brightness, brightness),
|
||||
custom_size: Some(Vec2::new(size, size)),
|
||||
..default()
|
||||
},
|
||||
transform: Transform::from_translation(Vec3::new(
|
||||
Transform::from_translation(Vec3::new(
|
||||
fastrand::f32() * WINDOW_WIDTH - WINDOW_WIDTH / 2.0,
|
||||
fastrand::f32() * WINDOW_HEIGHT - WINDOW_HEIGHT / 2.0,
|
||||
STAR_Z_DEPTH,
|
||||
)),
|
||||
..default()
|
||||
},
|
||||
Star { speed },
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
pub fn scroll_starfield(mut star_query: Query<(&mut Transform, &Star)>, time: Res<Time>) {
|
||||
let dt = time.delta_seconds();
|
||||
let dt = time.delta_secs();
|
||||
let half_height = WINDOW_HEIGHT / 2.0;
|
||||
let half_width = WINDOW_WIDTH / 2.0;
|
||||
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@ use crate::starfield::spawn_starfield;
|
|||
|
||||
// --- Setup ---
|
||||
pub fn setup(mut commands: Commands) {
|
||||
commands.spawn(Camera2dBundle::default());
|
||||
commands.spawn(Camera2d);
|
||||
spawn_starfield(&mut commands);
|
||||
spawn_player_ship(&mut commands);
|
||||
}
|
||||
|
|
@ -26,43 +26,35 @@ pub fn should_respawn_player(lives: Res<PlayerLives>, player_query: Query<&Playe
|
|||
player_query.is_empty() && lives.count > 0
|
||||
}
|
||||
|
||||
// Moved is_formation_complete to enemy.rs as it's closely related to enemy logic
|
||||
|
||||
// --- General Systems ---
|
||||
|
||||
// Update Window Title with Lives, Score, and Stage
|
||||
pub fn update_window_title(
|
||||
lives: Res<PlayerLives>,
|
||||
score: Res<Score>,
|
||||
stage: Res<CurrentStage>, // Add CurrentStage resource
|
||||
stage: Res<CurrentStage>,
|
||||
mut windows: Query<&mut Window>,
|
||||
) {
|
||||
// Update if lives, score, or stage changed
|
||||
if lives.is_changed() || score.is_changed() || stage.is_changed() {
|
||||
let mut window = windows.single_mut();
|
||||
if let Ok(mut window) = windows.single_mut() {
|
||||
window.title = format!(
|
||||
"Galaga :: Stage: {} Lives: {} Score: {}",
|
||||
stage.number, lives.count, score.value
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// --- Explosion Systems ---
|
||||
|
||||
pub fn spawn_explosion(commands: &mut Commands, position: Vec3) {
|
||||
commands.spawn((
|
||||
SpriteBundle {
|
||||
sprite: Sprite {
|
||||
Sprite {
|
||||
color: EXPLOSION_COLOR,
|
||||
custom_size: Some(EXPLOSION_BASE_SIZE),
|
||||
..default()
|
||||
},
|
||||
transform: Transform {
|
||||
translation: position,
|
||||
..default()
|
||||
},
|
||||
..default()
|
||||
},
|
||||
Transform::from_translation(position),
|
||||
Explosion {
|
||||
timer: Timer::new(std::time::Duration::from_secs_f32(EXPLOSION_DURATION), TimerMode::Once),
|
||||
},
|
||||
|
|
@ -80,17 +72,15 @@ pub fn animate_explosion(
|
|||
let progress = explosion.timer.elapsed_secs() / EXPLOSION_DURATION;
|
||||
let clamped_progress = progress.min(1.0);
|
||||
|
||||
// Scale from base to max size
|
||||
let scale_x = EXPLOSION_BASE_SIZE.x + (EXPLOSION_MAX_SIZE.x - EXPLOSION_BASE_SIZE.x) * clamped_progress;
|
||||
let scale_y = EXPLOSION_BASE_SIZE.y + (EXPLOSION_MAX_SIZE.y - EXPLOSION_BASE_SIZE.y) * clamped_progress;
|
||||
sprite.custom_size = Some(Vec2::new(scale_x, scale_y));
|
||||
|
||||
// Fade alpha from 1.0 to 0.0
|
||||
let alpha = 1.0 - clamped_progress;
|
||||
let base = EXPLOSION_COLOR;
|
||||
sprite.color = Color::rgba(base.r(), base.g(), base.b(), alpha);
|
||||
let base = EXPLOSION_COLOR.to_srgba();
|
||||
sprite.color = Color::srgba(base.red, base.green, base.blue, alpha);
|
||||
|
||||
if explosion.timer.finished() {
|
||||
if explosion.timer.is_finished() {
|
||||
commands.entity(entity).despawn();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue