feat: fullscreen toggle key

This commit is contained in:
Ryan Walters
2025-09-11 09:09:35 -05:00
parent 36e9de1a1f
commit 126b6ff378
7 changed files with 37 additions and 3 deletions

2
Cargo.lock generated
View File

@@ -711,7 +711,7 @@ checksum = "42f5e15c9953c5e4ccceeb2e7382a716482c34515315f7b03532b8b4e8393d2d"
[[package]]
name = "pacman"
version = "0.80.0"
version = "0.80.1"
dependencies = [
"anyhow",
"bevy_ecs",

View File

@@ -1,6 +1,6 @@
[package]
name = "pacman"
version = "0.80.0"
version = "0.80.1"
authors = ["Xevion"]
edition = "2021"
rust-version = "1.86.0"

View File

@@ -32,7 +32,7 @@ The game includes all the original features you'd expect from Pac-Man:
- [x] Classic maze navigation with tunnels and dot collection
- [ ] Four ghosts with their unique AI behaviors (Blinky, Pinky, Inky, and Clyde)
- [x] Power pellets that allow Pac-Man to eat ghosts
- [ ] Fruit bonuses that appear periodically
- [x] Fruit bonuses that appear periodically
- [ ] Progressive difficulty with faster ghosts and shorter power pellet duration
- [x] Authentic sound effects and sprites

View File

@@ -19,7 +19,10 @@ pub enum GameCommand {
/// Restart the current level with fresh entity positions and items
ResetLevel,
/// Pause or resume game ticking logic
/// TODO: Display pause state, fix debug rendering pause distress
TogglePause,
/// Toggle fullscreen mode (desktop only)
ToggleFullscreen,
}
/// Global events that flow through the ECS event system to coordinate game behavior.

View File

@@ -489,6 +489,8 @@ impl Game {
}),
player_control_system,
pause_system,
#[cfg(not(target_os = "emscripten"))]
profile(SystemId::Input, systems::handle_fullscreen_command),
)
.chain();

View File

@@ -90,6 +90,8 @@ impl Default for Bindings {
{
key_bindings.insert(Keycode::Escape, GameCommand::Exit);
key_bindings.insert(Keycode::Q, GameCommand::Exit);
// Desktop-only fullscreen toggle
key_bindings.insert(Keycode::F, GameCommand::ToggleFullscreen);
}
let movement_keys = HashSet::from([

View File

@@ -21,6 +21,12 @@ use bevy_ecs::{
};
use crate::events::{GameCommand, GameEvent};
#[cfg(not(target_os = "emscripten"))]
use bevy_ecs::system::NonSendMut;
#[cfg(not(target_os = "emscripten"))]
use sdl2::render::Canvas;
#[cfg(not(target_os = "emscripten"))]
use sdl2::video::{FullscreenType, Window};
#[derive(Resource, Clone)]
pub struct PlayerAnimation(pub DirectionalAnimation);
@@ -73,6 +79,27 @@ pub fn handle_pause_command(
}
}
#[cfg(not(target_os = "emscripten"))]
pub fn handle_fullscreen_command(mut events: EventReader<GameEvent>, mut canvas: NonSendMut<&mut Canvas<Window>>) {
for event in events.read() {
if let GameEvent::Command(GameCommand::ToggleFullscreen) = event {
let window = canvas.window_mut();
let current = window.fullscreen_state();
let target = match current {
FullscreenType::Off => FullscreenType::Desktop,
_ => FullscreenType::Off,
};
if let Err(e) = window.set_fullscreen(target) {
tracing::warn!(error = ?e, "Failed to toggle fullscreen");
} else {
let on = matches!(target, FullscreenType::Desktop | FullscreenType::True);
info!(fullscreen = on, "Toggled fullscreen");
}
}
}
}
pub trait TooSimilar {
fn too_similar(&self, other: &Self) -> bool;
}