Fixed Pacman pause button (#1894)

This commit is contained in:
Mark Thompson 2024-02-14 14:43:31 -06:00 committed by GitHub
parent 936e8279f9
commit 8725b01995
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -25,19 +25,31 @@ void PacmanView::focus() {
void PacmanView::paint(Painter& painter) {
(void)painter;
static Playfield _game;
static bool wait_for_button_release{false};
if (!initialized) {
initialized = true;
_game.Init();
}
auto switches_debounced = get_switches_state().to_ulong();
auto switches_raw = swizzled_switches() & ((1 << (int)Switch::Right) | (1 << (int)Switch::Left) | (1 << (int)Switch::Down) | (1 << (int)Switch::Up) | (1 << (int)Switch::Sel) | (1 << (int)Switch::Dfu));
but_RIGHT = (switches_debounced & 0x01) == 0x01;
but_LEFT = (switches_debounced & 0x02) == 0x02;
but_DOWN = (switches_debounced & 0x04) == 0x04;
but_UP = (switches_debounced & 0x08) == 0x08;
but_A = (switches_debounced & 0x10) == 0x10;
// For the Select (Start/Pause) button, wait for release to avoid repeat
uint8_t buttons_to_wait_for = (1 << (int)Switch::Sel);
if (wait_for_button_release) {
if ((switches_raw & buttons_to_wait_for) == 0)
wait_for_button_release = false;
switches_raw &= ~buttons_to_wait_for;
} else {
if (switches_raw & buttons_to_wait_for)
wait_for_button_release = true;
}
but_RIGHT = (switches_raw & (1 << (int)Switch::Right)) != 0;
but_LEFT = (switches_raw & (1 << (int)Switch::Left)) != 0;
but_DOWN = (switches_raw & (1 << (int)Switch::Down)) != 0;
but_UP = (switches_raw & (1 << (int)Switch::Up)) != 0;
but_A = (switches_raw & (1 << (int)Switch::Sel)) != 0;
_game.Step();
}