mirror of
https://github.com/griffi-gh/kubi.git
synced 2024-11-14 03:18:41 -06:00
pl ctl
This commit is contained in:
parent
36cec2b1e5
commit
93b99d2306
|
@ -19,6 +19,7 @@ pub struct Inputs {
|
|||
pub look: Vec2,
|
||||
pub action_a: bool,
|
||||
pub action_b: bool,
|
||||
pub jump: bool,
|
||||
}
|
||||
|
||||
#[derive(Unique, Clone, Copy, Default, Debug)]
|
||||
|
@ -186,6 +187,7 @@ fn update_input_state (
|
|||
inputs.look += raw_inputs.mouse_delta.as_vec2();
|
||||
inputs.action_a |= raw_inputs.button_state[0];
|
||||
inputs.action_b |= raw_inputs.button_state[1];
|
||||
inputs.jump |= raw_inputs.button_state[2];
|
||||
}
|
||||
|
||||
fn update_input_state_gamepad (
|
||||
|
@ -198,9 +200,11 @@ fn update_input_state_gamepad (
|
|||
let left_stick = vec2(gamepad.value(Axis::LeftStickX), gamepad.value(Axis::LeftStickY));
|
||||
let right_stick = vec2(gamepad.value(Axis::RightStickX), -gamepad.value(Axis::RightStickY));
|
||||
inputs.movement += left_stick;
|
||||
inputs.look += right_stick;
|
||||
inputs.action_a |= gamepad.is_pressed(Button::South);
|
||||
//HACK: for now, we multiply look by 2 to make it feel more responsive
|
||||
inputs.look += right_stick * 2.;
|
||||
inputs.action_a |= gamepad.is_pressed(Button::West);
|
||||
inputs.action_b |= gamepad.is_pressed(Button::East);
|
||||
inputs.jump |= gamepad.is_pressed(Button::South);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -23,7 +23,7 @@ pub(crate) mod settings;
|
|||
pub(crate) mod camera;
|
||||
pub(crate) mod events;
|
||||
pub(crate) mod input;
|
||||
pub(crate) mod fly_controller;
|
||||
pub(crate) mod player_controller;
|
||||
pub(crate) mod block_placement;
|
||||
pub(crate) mod delta_time;
|
||||
pub(crate) mod cursor_lock;
|
||||
|
@ -57,7 +57,7 @@ use events::{
|
|||
player_actions::generate_move_events,
|
||||
};
|
||||
use input::{init_input, process_inputs};
|
||||
use fly_controller::update_controllers;
|
||||
use player_controller::update_player_controllers;
|
||||
use rendering::{
|
||||
Renderer,
|
||||
RenderTarget,
|
||||
|
@ -133,7 +133,7 @@ fn update() -> Workload {
|
|||
update_loaded_world_around_player,
|
||||
).into_sequential_workload().run_if(is_ingame_or_loading),
|
||||
(
|
||||
update_controllers,
|
||||
update_player_controllers,
|
||||
update_client_physics_late,
|
||||
generate_move_events,
|
||||
update_raycasts,
|
||||
|
|
|
@ -12,7 +12,7 @@ use kubi_shared::{
|
|||
use crate::{
|
||||
camera::Camera,
|
||||
client_physics::ClPhysicsActor,
|
||||
fly_controller::FlyController,
|
||||
player_controller::PlayerController,
|
||||
transform::Transform,
|
||||
world::raycast::LookingAtBlock
|
||||
};
|
||||
|
@ -31,7 +31,7 @@ pub fn spawn_player (
|
|||
Health::new(PLAYER_HEALTH),
|
||||
Transform::default(),
|
||||
Camera::default(),
|
||||
FlyController,
|
||||
PlayerController::DEFAULT_FPS_CTL,
|
||||
LookingAtBlock::default(),
|
||||
PlayerHolding(Some(Block::Cobblestone)),
|
||||
Username("LocalPlayer".into()),
|
||||
|
@ -53,7 +53,7 @@ pub fn spawn_local_player_multiplayer (
|
|||
init.health,
|
||||
Transform(Mat4::from_rotation_translation(init.direction, init.position)),
|
||||
Camera::default(),
|
||||
FlyController,
|
||||
PlayerController::DEFAULT_FPS_CTL,
|
||||
LookingAtBlock::default(),
|
||||
PlayerHolding::default(),
|
||||
),(
|
||||
|
|
|
@ -3,10 +3,31 @@ use shipyard::{Component, View, ViewMut, IntoIter, UniqueView, Workload, IntoWor
|
|||
use std::f32::consts::PI;
|
||||
use crate::{transform::Transform, input::Inputs, settings::GameSettings, delta_time::DeltaTime};
|
||||
|
||||
#[derive(Component)]
|
||||
pub struct FlyController;
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
|
||||
pub enum PlayerControllerType {
|
||||
FlyCam,
|
||||
FpsCtl,
|
||||
}
|
||||
|
||||
pub fn update_controllers() -> Workload {
|
||||
#[derive(Component)]
|
||||
pub struct PlayerController {
|
||||
pub control_type: PlayerControllerType,
|
||||
pub speed: f32,
|
||||
}
|
||||
|
||||
impl PlayerController {
|
||||
pub const DEFAULT_FLY_CAM: Self = Self {
|
||||
control_type: PlayerControllerType::FlyCam,
|
||||
speed: 30.,
|
||||
};
|
||||
|
||||
pub const DEFAULT_FPS_CTL: Self = Self {
|
||||
control_type: PlayerControllerType::FpsCtl,
|
||||
speed: 10.,
|
||||
};
|
||||
}
|
||||
|
||||
pub fn update_player_controllers() -> Workload {
|
||||
(
|
||||
update_look,
|
||||
update_movement
|
||||
|
@ -16,7 +37,7 @@ pub fn update_controllers() -> Workload {
|
|||
const MAX_PITCH: f32 = PI/2. - 0.05;
|
||||
|
||||
fn update_look(
|
||||
controllers: View<FlyController>,
|
||||
controllers: View<PlayerController>,
|
||||
mut transforms: ViewMut<Transform, track::All>,
|
||||
inputs: UniqueView<Inputs>,
|
||||
settings: UniqueView<GameSettings>,
|
||||
|
@ -36,13 +57,13 @@ fn update_look(
|
|||
}
|
||||
|
||||
fn update_movement(
|
||||
controllers: View<FlyController>,
|
||||
controllers: View<PlayerController>,
|
||||
mut transforms: ViewMut<Transform, track::All>,
|
||||
inputs: UniqueView<Inputs>,
|
||||
dt: UniqueView<DeltaTime>,
|
||||
) {
|
||||
if inputs.movement == Vec2::ZERO { return }
|
||||
let movement = inputs.movement * 30. * dt.0.as_secs_f32();
|
||||
let movement = inputs.movement * dt.0.as_secs_f32();
|
||||
for (_, mut transform) in (&controllers, &mut transforms).iter() {
|
||||
let (scale, rotation, mut translation) = transform.0.to_scale_rotation_translation();
|
||||
let rotation_norm = rotation.normalize();
|
Loading…
Reference in a new issue