Skip to content

Commit

Permalink
rewrite renderer again
Browse files Browse the repository at this point in the history
  • Loading branch information
BreakingLead committed Aug 30, 2024
1 parent 6b23725 commit 47d527e
Show file tree
Hide file tree
Showing 22 changed files with 441 additions and 156 deletions.
221 changes: 220 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions blockworld-client/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ slab = "0.4.9"
once_cell = "1.19.0"
bimap = "0.6.3"
enumflags2 = "0.7.10"
bevy_ecs = "0.14.1"

[[bin]]
name = "blockworld-client"
Expand Down
36 changes: 33 additions & 3 deletions blockworld-client/game/input_manager.rs
Original file line number Diff line number Diff line change
@@ -1,18 +1,46 @@
use std::collections::HashSet;

use glam::{vec2, Vec2};
use once_cell::sync::Lazy;
use winit::{
event::{ElementState, KeyEvent},
keyboard::Key,
event::{DeviceEvent, ElementState, KeyEvent},
keyboard::{Key, NamedKey},
};

use super::key_record::MovementRecord;

pub static mut GLOBAL_INPUT_MANAGER: Lazy<InputManager> = Lazy::new(|| InputManager::default());

/// Tracker for the pressing keys
#[derive(Default, Debug)]
pub struct InputManager {
pub pressing_keys: HashSet<Key>,
pressing_keys: HashSet<Key>,
}

impl InputManager {
pub fn to_key_record(&self) -> MovementRecord {
let mut s = MovementRecord::default();
if self.is_key_pressing(Key::Character("w".into())) {
s.forward = true;
}
if self.is_key_pressing(Key::Character("a".into())) {
s.left = true;
}
if self.is_key_pressing(Key::Character("s".into())) {
s.backward = true;
}
if self.is_key_pressing(Key::Character("d".into())) {
s.right = true;
}
if self.is_key_pressing(Key::Named(NamedKey::Space)) {
s.ascend = true;
}
if self.is_key_pressing(Key::Named(NamedKey::Shift)) {
s.descend = true;
}
s
}

pub fn is_key_pressing(&self, key: Key) -> bool {
self.pressing_keys.contains(&key)
}
Expand All @@ -28,4 +56,6 @@ impl InputManager {
}
}
}

pub fn handle_mouse_event(&mut self, event: &DeviceEvent) {}
}
Loading

0 comments on commit 47d527e

Please sign in to comment.