astraea/src/start_state.rs

100 lines
2.8 KiB
Rust
Raw Normal View History

2024-10-06 15:46:32 +02:00
use bevy::prelude::*;
use std::f64::consts::PI;
//use bevy::input::mouse::MouseMotion;
2024-10-06 15:46:32 +02:00
use crate::GameState;
use crate::StartMenu;
2024-10-07 17:57:44 +02:00
use crate::Player;
2024-10-06 17:16:03 +02:00
#[derive(Component)]
struct AudioPlayer;
2024-10-06 17:16:03 +02:00
pub fn audio_setup(asset_server: Res<AssetServer>, mut commands: Commands) {
commands.spawn((AudioBundle {
2024-10-06 17:36:58 +02:00
source: asset_server.load("Banjo.ogg"),
settings: PlaybackSettings::LOOP,
}, AudioPlayer));
2024-10-06 17:36:58 +02:00
info!("audio started");
2024-10-06 17:16:03 +02:00
}
2024-10-06 15:46:32 +02:00
2024-10-07 17:57:44 +02:00
pub fn setup(
mut commands: Commands,
) {
2024-10-07 19:49:50 +02:00
let main_container_node = NodeBundle {
2024-10-06 15:46:32 +02:00
style: Style {
2024-10-07 09:28:32 +02:00
width: Val::Percent(100.0),
height: Val::Percent(100.0),
flex_direction: FlexDirection::Column,
justify_content: JustifyContent::Center,
align_items: AlignItems::Center,
2024-10-07 19:49:50 +02:00
2024-10-06 15:46:32 +02:00
..default()
},
..default()
};
2024-10-07 19:49:50 +02:00
let main_container = commands.spawn(main_container_node).id();
2024-10-06 15:46:32 +02:00
2024-10-07 19:49:50 +02:00
let title_text_style = TextStyle {
2024-10-07 09:28:32 +02:00
font_size: 50.0,
2024-10-06 15:46:32 +02:00
color: Color::WHITE,
// font: asset_server.load("fonts/FiraSans-Bold.ttf"), // Load font if needed
..default()
};
2024-10-07 19:49:50 +02:00
let start_text_style = TextStyle {
2024-10-07 09:28:32 +02:00
font_size: 30.0,
2024-10-06 15:46:32 +02:00
color: Color::WHITE,
// font: asset_server.load("fonts/FiraSans-Regular.ttf"), // Load font if needed
..default()
};
2024-10-07 19:49:50 +02:00
let explo_text_style = TextStyle {
font_size: 30.0,
color: Color::srgb(0.4,0.4,0.4),
// font: asset_server.load("fonts/FiraSans-Regular.ttf"), // Load font if needed
..default()
};
let title_text_node = TextBundle::from_section(
2024-10-07 09:28:32 +02:00
"Astraea",
2024-10-07 19:49:50 +02:00
title_text_style,
2024-10-06 15:46:32 +02:00
);
2024-10-07 19:49:50 +02:00
let start_text_node = TextBundle::from_section(
2024-10-07 09:28:32 +02:00
"Press Space to Begin",
2024-10-07 19:49:50 +02:00
start_text_style,
2024-10-06 15:46:32 +02:00
);
2024-10-07 19:49:50 +02:00
let explo_text_node = TextBundle::from_section(
"Press E to Explore",
explo_text_style,
);
let title_text = commands.spawn((title_text_node, StartMenu)).id();
let start_text = commands.spawn((start_text_node, StartMenu)).id();
let explo_text = commands.spawn((explo_text_node, StartMenu)).id();
2024-10-06 15:46:32 +02:00
2024-10-07 19:49:50 +02:00
commands.entity(main_container).push_children(&[title_text, start_text, explo_text]);
2024-10-06 15:46:32 +02:00
}
pub fn player_interact(
keys: Res<ButtonInput<KeyCode>>,
mut game_state: ResMut<NextState<GameState>>,
mut player_query: Query<(&mut Player, &mut Transform)>,
2024-10-06 15:46:32 +02:00
) {
if keys.just_pressed(KeyCode::Space) {
game_state.set(GameState::Game);
}
2024-10-07 19:49:50 +02:00
if keys.just_pressed(KeyCode::KeyE) {
game_state.set(GameState::Explo);
}
2024-10-06 15:46:32 +02:00
if let Ok((_player, mut transform)) = player_query.get_single_mut() {
let mut rotation = Quat::IDENTITY;
2024-10-07 09:28:32 +02:00
rotation *= Quat::from_rotation_y((PI / 6000.0) as f32);
rotation *= Quat::from_rotation_x((-PI / 2000.0) as f32);
transform.rotation *= rotation;
2024-10-06 15:46:32 +02:00
}
}