2024-10-06 15:46:32 +02:00
|
|
|
use bevy::prelude::*;
|
|
|
|
use std::f64::consts::PI;
|
2024-10-07 11:03:05 +02:00
|
|
|
//use bevy::input::mouse::MouseMotion;
|
2024-10-06 15:46:32 +02:00
|
|
|
use crate::Player;
|
|
|
|
use crate::GameState;
|
|
|
|
use crate::GameOver;
|
|
|
|
use crate::StartMenu;
|
2024-10-06 17:16:03 +02:00
|
|
|
use crate::PlayerState;
|
|
|
|
|
2024-10-07 11:03:05 +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) {
|
2024-10-07 11:03:05 +02:00
|
|
|
commands.spawn((AudioBundle {
|
2024-10-06 17:36:58 +02:00
|
|
|
source: asset_server.load("Banjo.ogg"),
|
|
|
|
settings: PlaybackSettings::LOOP,
|
2024-10-07 11:03:05 +02:00
|
|
|
}, 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
|
|
|
|
|
|
|
pub fn setup(mut commands: Commands, _asset_server: Res<AssetServer>) {
|
|
|
|
let container_node = NodeBundle {
|
|
|
|
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-06 15:46:32 +02:00
|
|
|
..default()
|
|
|
|
},
|
|
|
|
..default()
|
|
|
|
};
|
|
|
|
|
|
|
|
let container = commands.spawn(container_node).id();
|
|
|
|
|
|
|
|
let top_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()
|
|
|
|
};
|
|
|
|
|
|
|
|
let bottom_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()
|
|
|
|
};
|
|
|
|
|
|
|
|
let top_text_node = TextBundle::from_section(
|
2024-10-07 09:28:32 +02:00
|
|
|
"Astraea",
|
2024-10-06 15:46:32 +02:00
|
|
|
top_text_style,
|
|
|
|
);
|
|
|
|
|
|
|
|
let bottom_text_node = TextBundle::from_section(
|
2024-10-07 09:28:32 +02:00
|
|
|
"Press Space to Begin",
|
2024-10-06 15:46:32 +02:00
|
|
|
bottom_text_style,
|
|
|
|
);
|
|
|
|
|
|
|
|
let top_text = commands.spawn((top_text_node, StartMenu)).id();
|
|
|
|
let bottom_text = commands.spawn((bottom_text_node, StartMenu)).id();
|
|
|
|
|
|
|
|
commands.entity(container).push_children(&[top_text, bottom_text]);
|
|
|
|
|
|
|
|
commands.spawn((
|
|
|
|
Camera3dBundle {
|
|
|
|
transform: Transform::from_xyz(0.0, 0.0, 0.0),
|
|
|
|
..default()
|
|
|
|
},
|
|
|
|
Player {
|
|
|
|
target_rotation: None,
|
|
|
|
target_cons_name: None,
|
|
|
|
score: 0,
|
|
|
|
health: 3,
|
2024-10-06 17:16:03 +02:00
|
|
|
state: PlayerState::Playing,
|
2024-10-06 15:46:32 +02:00
|
|
|
},
|
|
|
|
GameOver,
|
|
|
|
));
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn player_interact(
|
|
|
|
keys: Res<ButtonInput<KeyCode>>,
|
|
|
|
mut game_state: ResMut<NextState<GameState>>,
|
2024-10-07 11:03:05 +02:00
|
|
|
mut player_query: Query<(&mut Player, &mut Transform)>,
|
|
|
|
//commands: Commands,
|
|
|
|
//mut evr_motion: EventReader<MouseMotion>,
|
|
|
|
//asset_server: Res<AssetServer>,
|
|
|
|
//mut audio_query: Query<&mut AudioPlayer>,
|
2024-10-06 15:46:32 +02:00
|
|
|
) {
|
|
|
|
if keys.just_pressed(KeyCode::Space) {
|
|
|
|
info!("start space");
|
|
|
|
game_state.set(GameState::Game);
|
|
|
|
}
|
|
|
|
|
|
|
|
if let Ok((_player, mut transform)) = player_query.get_single_mut() {
|
2024-10-07 11:03:05 +02:00
|
|
|
// for _ev in evr_motion.read() {
|
|
|
|
// if let Err(_) = audio_query.get_single_mut() {
|
|
|
|
// audio_setup(asset_server, commands);
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
|
2024-10-06 15:46:32 +02:00
|
|
|
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
|
|
|
}
|
|
|
|
}
|