feat: add start menu with interactive button

- Add StartMenu as the default game state
- Create StartMenuUI and StartButton components
- Implement menu UI with BGLGA title and Start Game button
- Add button interaction system with hover effects
- Set up proper state transitions from menu to game
- Update TODO.md to mark task as completed

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
Harald Hoyer 2025-06-27 09:31:03 +02:00
parent aee3c9c91b
commit 28e4e53da9
4 changed files with 110 additions and 2 deletions

View file

@ -1,10 +1,11 @@
use bevy::prelude::*;
use crate::components::{Bullet, Enemy, GameOverUI}; // Import necessary components
use crate::components::{Bullet, Enemy, GameOverUI, StartMenuUI, StartButton}; // Import necessary components
// --- Game States ---
#[derive(Clone, Eq, PartialEq, Debug, Hash, Default, States)]
pub enum AppState {
#[default]
StartMenu,
Playing,
GameOver,
}
@ -65,4 +66,100 @@ pub fn cleanup_game_entities(
// for entity in player_query.iter() {
// commands.entity(entity).despawn();
// }
}
// --- Start Menu UI ---
pub fn setup_start_menu_ui(mut commands: Commands) {
println!("Entering StartMenu state. Setting up UI.");
// Root UI container
commands
.spawn((
NodeBundle {
style: Style {
width: Val::Percent(100.0),
height: Val::Percent(100.0),
align_items: AlignItems::Center,
justify_content: JustifyContent::Center,
flex_direction: FlexDirection::Column,
..default()
},
..default()
},
StartMenuUI,
))
.with_children(|parent| {
// Title
parent.spawn(TextBundle::from_section(
"BGLGA",
TextStyle {
font_size: 120.0,
color: Color::WHITE,
..default()
},
).with_style(Style {
margin: UiRect::bottom(Val::Px(50.0)),
..default()
}));
// Start Game Button
parent
.spawn((
ButtonBundle {
style: Style {
width: Val::Px(250.0),
height: Val::Px(80.0),
border: UiRect::all(Val::Px(2.0)),
justify_content: JustifyContent::Center,
align_items: AlignItems::Center,
..default()
},
border_color: BorderColor(Color::WHITE),
background_color: BackgroundColor(Color::rgb(0.1, 0.1, 0.5)),
..default()
},
StartButton,
))
.with_children(|parent| {
parent.spawn(TextBundle::from_section(
"Start Game",
TextStyle {
font_size: 40.0,
color: Color::WHITE,
..default()
},
));
});
});
}
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();
}
}
pub fn start_menu_button_system(
mut interaction_query: Query<
(&Interaction, &mut BackgroundColor),
(Changed<Interaction>, With<StartButton>),
>,
mut app_state: ResMut<NextState<AppState>>,
) {
for (interaction, mut color) in &mut interaction_query {
match *interaction {
Interaction::Pressed => {
println!("Start button pressed! Transitioning to Playing state.");
app_state.set(AppState::Playing);
}
Interaction::Hovered => {
color.0 = Color::rgb(0.2, 0.2, 0.7);
}
Interaction::None => {
color.0 = Color::rgb(0.1, 0.1, 0.5);
}
}
}
}