hide cursor

This commit is contained in:
LorrensP-2158466
2025-04-05 19:39:59 +02:00
parent 1328caab5c
commit e71e840d9f
3 changed files with 54 additions and 25 deletions

22
src/bevy_plugin.rs Normal file
View File

@@ -0,0 +1,22 @@
use bevy::{prelude::*, window::CursorOptions};
/// Overrides the default Bevy plugins and configures things like the screen settings.
pub(super) fn plugin(app: &mut App) {
app.add_plugins(
DefaultPlugins.set(WindowPlugin {
primary_window: Window {
title: "Among Me".into(),
// This will spawn an invisible window
// The window will be made visible in the make_visible() system after 3 frames.
// This is useful when you want to avoid the white window that shows up before the GPU is ready to render the app.
cursor_options: CursorOptions {
visible: false,
..default()
},
..default()
}
.into(),
..default()
}),
);
}

View File

@@ -1,25 +1,23 @@
use std::default;
use asset_loading::ImageAssets;
use bevy::prelude::*;
use player_plugin::PlayerPlugin;
use physics_plugin::PhysicsPlugin;
mod asset_loading;
mod player_plugin;
mod physics_plugin;
mod bevy_plugin;
mod level_instantiation;
mod main_menu;
mod physics_plugin;
mod player;
fn main() {
App::new()
.add_plugins((
DefaultPlugins,
bevy_plugin::plugin,
asset_loading::plugin,
PlayerPlugin,
player::plugin,
PhysicsPlugin,
level_instantiation::map_plugin,
main_menu::plugin
main_menu::plugin,
))
.init_state::<GameState>()
.add_systems(OnEnter(GameState::Playing), setup)

View File

@@ -1,5 +1,13 @@
use bevy::{prelude::*, render::view::RenderLayers, input::mouse::AccumulatedMouseMotion, pbr::NotShadowCaster};
use crate::{physics_plugin::{AccumulatedInput, PhysicalTranslation, PreviousPhysicalTranslation, Velocity}, GameState};
use crate::{
GameState,
physics_plugin::{
AccumulatedInput, PhysicalTranslation, PreviousPhysicalTranslation, Velocity,
},
};
use bevy::{
input::mouse::AccumulatedMouseMotion, pbr::NotShadowCaster, prelude::*,
render::view::RenderLayers,
};
#[derive(Debug, Component)]
pub struct Player;
@@ -8,26 +16,24 @@ pub struct Player;
pub struct CameraSensitivity(Vec2);
impl Default for CameraSensitivity {
fn default() -> Self {
Self(
Vec2::new(0.003, 0.002),
)
Self(Vec2::new(0.003, 0.002))
}
}
#[derive(Debug, Component)]
struct WorldModelCamera;
pub struct PlayerPlugin;
impl Plugin for PlayerPlugin {
fn build(&self, app: &mut App) {
app.add_systems(OnEnter(GameState::Playing), init_player)
.add_systems(Update, move_camera.run_if(in_state(GameState::Playing)))
.add_systems(RunFixedMainLoop, handle_input.in_set(RunFixedMainLoopSystem::BeforeFixedMainLoop).run_if(in_state(GameState::Playing)));
}
pub fn plugin(app: &mut App) {
app.add_systems(OnEnter(GameState::Playing), init_player)
.add_systems(Update, move_camera.run_if(in_state(GameState::Playing)))
.add_systems(
RunFixedMainLoop,
handle_input
.in_set(RunFixedMainLoopSystem::BeforeFixedMainLoop)
.run_if(in_state(GameState::Playing)),
);
}
/// Used implicitly by all entities without a `RenderLayers` component.
/// Our world model camera and all objects other than the player are on this layer.
/// The light source belongs to both layers.
@@ -92,7 +98,6 @@ pub fn init_player(
});
}
use std::f32::consts::FRAC_PI_2;
const PITCH_LIMIT: f32 = FRAC_PI_2 - 0.01;
@@ -141,8 +146,12 @@ pub fn handle_input(
input.x += right.x;
input.z += right.z;
}
if keyboard_input.pressed(KeyCode::Space) { input.y += 1.0; }
if keyboard_input.pressed(KeyCode::ShiftLeft) { input.y -= 1.0; }
if keyboard_input.pressed(KeyCode::Space) {
input.y += 1.0;
}
if keyboard_input.pressed(KeyCode::ShiftLeft) {
input.y -= 1.0;
}
velocity.0 = input.normalize_or_zero() * SPEED;
}
}