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