Update dependencies (#272)
* Update dependencies - Closes #270 * Unify controls in Invaders example The fire button on gamepads was allowing trapid fire when holding the button. Keyboard controls required the fire key to be released between each shot fired. This commit fixes the difference by making the gamepad fire button act like the keyboard fire key.
This commit is contained in:
parent
2e7c822091
commit
5c1600926e
|
@ -18,4 +18,4 @@ log = "0.4"
|
||||||
pixels = { path = "../.." }
|
pixels = { path = "../.." }
|
||||||
randomize = "3.0"
|
randomize = "3.0"
|
||||||
winit = "0.26"
|
winit = "0.26"
|
||||||
winit_input_helper = "0.11"
|
winit_input_helper = "0.12"
|
||||||
|
|
|
@ -66,7 +66,7 @@ fn main() -> Result<(), Error> {
|
||||||
if input.key_pressed(VirtualKeyCode::P) {
|
if input.key_pressed(VirtualKeyCode::P) {
|
||||||
paused = !paused;
|
paused = !paused;
|
||||||
}
|
}
|
||||||
if input.key_pressed(VirtualKeyCode::Space) {
|
if input.key_pressed_os(VirtualKeyCode::Space) {
|
||||||
// Space is frame-step, so ensure we're paused
|
// Space is frame-step, so ensure we're paused
|
||||||
paused = true;
|
paused = true;
|
||||||
}
|
}
|
||||||
|
@ -127,7 +127,7 @@ fn main() -> Result<(), Error> {
|
||||||
if let Some(size) = input.window_resized() {
|
if let Some(size) = input.window_resized() {
|
||||||
pixels.resize_surface(size.width, size.height);
|
pixels.resize_surface(size.width, size.height);
|
||||||
}
|
}
|
||||||
if !paused || input.key_pressed(VirtualKeyCode::Space) {
|
if !paused || input.key_pressed_os(VirtualKeyCode::Space) {
|
||||||
life.update();
|
life.update();
|
||||||
}
|
}
|
||||||
window.request_redraw();
|
window.request_redraw();
|
||||||
|
|
|
@ -15,4 +15,4 @@ env_logger = "0.9"
|
||||||
log = "0.4"
|
log = "0.4"
|
||||||
pixels = { path = "../.." }
|
pixels = { path = "../.." }
|
||||||
winit = "0.26"
|
winit = "0.26"
|
||||||
winit_input_helper = "0.11"
|
winit_input_helper = "0.12"
|
||||||
|
|
|
@ -17,4 +17,4 @@ imgui-winit-support = { version = "0.8", default-features = false, features = ["
|
||||||
log = "0.4"
|
log = "0.4"
|
||||||
pixels = { path = "../.." }
|
pixels = { path = "../.." }
|
||||||
winit = "0.26"
|
winit = "0.26"
|
||||||
winit_input_helper = "0.11"
|
winit_input_helper = "0.12"
|
||||||
|
|
|
@ -12,7 +12,7 @@ default = ["optimize"]
|
||||||
[dependencies]
|
[dependencies]
|
||||||
byteorder = "1.3"
|
byteorder = "1.3"
|
||||||
env_logger = "0.9"
|
env_logger = "0.9"
|
||||||
game-loop = { version = "0.8", features = ["window"] }
|
game-loop = { version = "0.9", features = ["window"] }
|
||||||
getrandom = "0.2"
|
getrandom = "0.2"
|
||||||
gilrs = "0.8"
|
gilrs = "0.8"
|
||||||
log = "0.4"
|
log = "0.4"
|
||||||
|
@ -20,4 +20,4 @@ pixels = { path = "../.." }
|
||||||
randomize = "3.0"
|
randomize = "3.0"
|
||||||
simple-invaders = { path = "simple-invaders" }
|
simple-invaders = { path = "simple-invaders" }
|
||||||
winit = "0.26"
|
winit = "0.26"
|
||||||
winit_input_helper = "0.11"
|
winit_input_helper = "0.12"
|
||||||
|
|
|
@ -8,10 +8,7 @@ use pixels::{Error, Pixels, SurfaceTexture};
|
||||||
use simple_invaders::{Controls, Direction, World, FPS, HEIGHT, TIME_STEP, WIDTH};
|
use simple_invaders::{Controls, Direction, World, FPS, HEIGHT, TIME_STEP, WIDTH};
|
||||||
use std::{env, time::Duration};
|
use std::{env, time::Duration};
|
||||||
use winit::{
|
use winit::{
|
||||||
dpi::LogicalSize,
|
dpi::LogicalSize, event::VirtualKeyCode, event_loop::EventLoop, window::WindowBuilder,
|
||||||
event::{Event, VirtualKeyCode},
|
|
||||||
event_loop::EventLoop,
|
|
||||||
window::WindowBuilder,
|
|
||||||
};
|
};
|
||||||
use winit_input_helper::WinitInputHelper;
|
use winit_input_helper::WinitInputHelper;
|
||||||
|
|
||||||
|
@ -31,8 +28,6 @@ struct Game {
|
||||||
gamepad: Option<GamepadId>,
|
gamepad: Option<GamepadId>,
|
||||||
/// Game pause state.
|
/// Game pause state.
|
||||||
paused: bool,
|
paused: bool,
|
||||||
/// State for key edge detection.
|
|
||||||
held: [bool; 2],
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Game {
|
impl Game {
|
||||||
|
@ -45,14 +40,10 @@ impl Game {
|
||||||
gilrs: Gilrs::new().unwrap(), // XXX: Don't unwrap.
|
gilrs: Gilrs::new().unwrap(), // XXX: Don't unwrap.
|
||||||
gamepad: None,
|
gamepad: None,
|
||||||
paused: false,
|
paused: false,
|
||||||
held: [false; 2],
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn update_controls(&mut self, event: &Event<()>) {
|
fn update_controls(&mut self) {
|
||||||
// Let winit_input_helper collect events to build its state.
|
|
||||||
self.input.update(event);
|
|
||||||
|
|
||||||
// Pump the gilrs event loop and find an active gamepad
|
// Pump the gilrs event loop and find an active gamepad
|
||||||
while let Some(gilrs::Event { id, event, .. }) = self.gilrs.next_event() {
|
while let Some(gilrs::Event { id, event, .. }) = self.gilrs.next_event() {
|
||||||
let pad = self.gilrs.gamepad(id);
|
let pad = self.gilrs.gamepad(id);
|
||||||
|
@ -67,17 +58,11 @@ impl Game {
|
||||||
|
|
||||||
self.controls = {
|
self.controls = {
|
||||||
// Keyboard controls
|
// Keyboard controls
|
||||||
let held = [
|
|
||||||
self.input.key_held(VirtualKeyCode::Pause),
|
|
||||||
self.input.key_held(VirtualKeyCode::P),
|
|
||||||
];
|
|
||||||
|
|
||||||
let mut left = self.input.key_held(VirtualKeyCode::Left);
|
let mut left = self.input.key_held(VirtualKeyCode::Left);
|
||||||
let mut right = self.input.key_held(VirtualKeyCode::Right);
|
let mut right = self.input.key_held(VirtualKeyCode::Right);
|
||||||
let mut fire = self.input.key_held(VirtualKeyCode::Space);
|
let mut fire = self.input.key_pressed(VirtualKeyCode::Space);
|
||||||
let mut pause = (held[0] ^ self.held[0] & held[0]) | (held[1] ^ self.held[1] & held[1]);
|
let mut pause = self.input.key_pressed(VirtualKeyCode::Pause)
|
||||||
|
| self.input.key_pressed(VirtualKeyCode::P);
|
||||||
self.held = held;
|
|
||||||
|
|
||||||
// GamePad controls
|
// GamePad controls
|
||||||
if let Some(id) = self.gamepad {
|
if let Some(id) = self.gamepad {
|
||||||
|
@ -85,7 +70,9 @@ impl Game {
|
||||||
|
|
||||||
left |= gamepad.is_pressed(Button::DPadLeft);
|
left |= gamepad.is_pressed(Button::DPadLeft);
|
||||||
right |= gamepad.is_pressed(Button::DPadRight);
|
right |= gamepad.is_pressed(Button::DPadRight);
|
||||||
fire |= gamepad.is_pressed(Button::South);
|
fire |= gamepad.button_data(Button::South).map_or(false, |button| {
|
||||||
|
button.is_pressed() && button.counter() == self.gilrs.counter()
|
||||||
|
});
|
||||||
pause |= gamepad.button_data(Button::Start).map_or(false, |button| {
|
pause |= gamepad.button_data(Button::Start).map_or(false, |button| {
|
||||||
button.is_pressed() && button.counter() == self.gilrs.counter()
|
button.is_pressed() && button.counter() == self.gilrs.counter()
|
||||||
});
|
});
|
||||||
|
@ -166,8 +153,10 @@ fn main() -> Result<(), Error> {
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|g, event| {
|
|g, event| {
|
||||||
|
// Let winit_input_helper collect events to build its state.
|
||||||
|
if g.game.input.update(event) {
|
||||||
// Update controls
|
// Update controls
|
||||||
g.game.update_controls(&event);
|
g.game.update_controls();
|
||||||
|
|
||||||
// Close events
|
// Close events
|
||||||
if g.game.input.key_pressed(VirtualKeyCode::Escape) || g.game.input.quit() {
|
if g.game.input.key_pressed(VirtualKeyCode::Escape) || g.game.input.quit() {
|
||||||
|
@ -179,6 +168,7 @@ fn main() -> Result<(), Error> {
|
||||||
if let Some(size) = g.game.input.window_resized() {
|
if let Some(size) = g.game.input.window_resized() {
|
||||||
g.game.pixels.resize_surface(size.width, size.height);
|
g.game.pixels.resize_surface(size.width, size.height);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,4 +17,4 @@ env_logger = "0.9"
|
||||||
log = "0.4"
|
log = "0.4"
|
||||||
pixels = { path = "../.." }
|
pixels = { path = "../.." }
|
||||||
winit = "0.26"
|
winit = "0.26"
|
||||||
winit_input_helper = "0.11"
|
winit_input_helper = "0.12"
|
||||||
|
|
|
@ -15,7 +15,7 @@ log = "0.4"
|
||||||
pixels = { path = "../.." }
|
pixels = { path = "../.." }
|
||||||
wgpu = "0.12"
|
wgpu = "0.12"
|
||||||
winit = "0.26"
|
winit = "0.26"
|
||||||
winit_input_helper = "0.11"
|
winit_input_helper = "0.12"
|
||||||
|
|
||||||
[target.'cfg(target_arch = "wasm32")'.dependencies]
|
[target.'cfg(target_arch = "wasm32")'.dependencies]
|
||||||
console_error_panic_hook = "0.1"
|
console_error_panic_hook = "0.1"
|
||||||
|
|
|
@ -14,4 +14,4 @@ env_logger = "0.9"
|
||||||
log = "0.4"
|
log = "0.4"
|
||||||
pixels = { path = "../.." }
|
pixels = { path = "../.." }
|
||||||
winit = "0.26"
|
winit = "0.26"
|
||||||
winit_input_helper = "0.11"
|
winit_input_helper = "0.12"
|
||||||
|
|
|
@ -15,7 +15,7 @@ euclid = "0.22"
|
||||||
log = "0.4"
|
log = "0.4"
|
||||||
pixels = { path = "../.." }
|
pixels = { path = "../.." }
|
||||||
winit = "0.26"
|
winit = "0.26"
|
||||||
winit_input_helper = "0.11"
|
winit_input_helper = "0.12"
|
||||||
|
|
||||||
[dependencies.raqote]
|
[dependencies.raqote]
|
||||||
git = "https://github.com/jrmuizel/raqote.git"
|
git = "https://github.com/jrmuizel/raqote.git"
|
||||||
|
|
Loading…
Reference in a new issue