use crate::{ game::{GameState, WorldEntity}, maze::{self, Maze}, settings::Settings, }; use bevy::{ input::mouse::AccumulatedMouseMotion, prelude::*, window::{CursorGrabMode, CursorOptions}, }; #[derive(Component)] pub struct Player { pub yaw: f32, pub pitch: f32, pub distance: f32, } pub const SPAWN_YAW: f32 = std::f32::consts::FRAC_PI_2; pub fn spawn(mut commands: Commands, maze: Res, settings: Res) { commands.spawn(( WorldEntity, Player { yaw: SPAWN_YAW, pitch: 0., distance: 0., }, Camera3d::default(), bevy::render::view::NoIndirectDrawing, bevy::core_pipeline::tonemapping::Tonemapping::None, if settings.low { Msaa::Off } else { Msaa::Sample4 }, Projection::Perspective(PerspectiveProjection { fov: 80_f32.to_radians(), near: 0.05, far: 90., ..default() }), Transform::from_translation(maze::position(maze.spawn()) + Vec3::Y * 1.15) .with_rotation(Quat::from_rotation_y(SPAWN_YAW)), )); } pub fn cursor(state: Res>, mut windows: Query<(&Window, &mut CursorOptions)>) { for (window, mut c) in &mut windows { let grab = *state.get() == GameState::Playing && window.focused; c.visible = !grab; c.grab_mode = if grab { CursorGrabMode::Locked } else { CursorGrabMode::None }; } } pub fn move_player( time: Res