Pacman update (#2837)

This commit is contained in:
Totoo 2025-10-21 07:37:26 +02:00 committed by GitHub
parent 7041d507ca
commit 60a5222058
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 169 additions and 55 deletions

View file

@ -23,11 +23,24 @@
#include "pacman.hpp" #include "pacman.hpp"
#include <memory> #include <memory>
void notouch(int, int, uint32_t) {
// do nothing
}
void nothing() {
// do nothing
}
bool noencoder(int32_t) {
return false;
}
bool nokeyboard(uint8_t) {
return false;
}
const standalone_application_api_t* _api; const standalone_application_api_t* _api;
extern "C" { extern "C" {
__attribute__((section(".standalone_application_information"), used)) standalone_application_information_t _standalone_application_information = { __attribute__((section(".standalone_application_information"), used)) standalone_application_information_t _standalone_application_information = {
/*.header_version = */ 1, /*.header_version = */ 2,
/*.app_name = */ "Pac-Man", /*.app_name = */ "Pac-Man",
/*.bitmap_data = */ { /*.bitmap_data = */ {
@ -70,18 +83,17 @@ __attribute__((section(".standalone_application_information"), used)) standalone
/*.initialize_app = */ initialize, /*.initialize_app = */ initialize,
/*.on_event = */ on_event, /*.on_event = */ on_event,
/*.shutdown = */ shutdown, /*.shutdown = */ shutdown,
/*PaintViewMirror */ NULL, /*PaintViewMirror */ nothing,
/*OnTouchEvent */ NULL, /*OnTouchEvent */ notouch,
/*OnFocus */ NULL, /*OnFocus */ nothing,
/*OnKeyEvent */ NULL, /*OnKeyEvent */ on_key_event,
/*OnEncoder */ NULL, /*OnEncoder */ noencoder,
/*OnKeyboard */ NULL}; /*OnKeyboard */ nokeyboard};
} }
/* Implementing abort() eliminates requirement for _getpid(), _kill(), _exit(). */ /* Implementing abort() eliminates requirement for _getpid(), _kill(), _exit(). */
extern "C" void abort() { extern "C" void abort() {
while (true) while (true);
;
} }
// replace memory allocations to use heap from chibios // replace memory allocations to use heap from chibios

View file

@ -39,8 +39,36 @@ void initialize(const standalone_application_api_t& api) {
_api = &api; _api = &api;
} }
bool on_key_event(uint8_t key_val) {
ui::KeyEvent key = (ui::KeyEvent)key_val;
if (key == ui::KeyEvent::Right) {
but_RIGHT = true;
but_LEFT = false;
but_DOWN = false;
but_UP = false;
} else if (key == ui::KeyEvent::Left) {
but_LEFT = true;
but_RIGHT = false;
but_DOWN = false;
but_UP = false;
} else if (key == ui::KeyEvent::Down) {
but_DOWN = true;
but_RIGHT = false;
but_LEFT = false;
but_UP = false;
} else if (key == ui::KeyEvent::Up) {
but_UP = true;
but_RIGHT = false;
but_LEFT = false;
but_DOWN = false;
} else if (key == ui::KeyEvent::Select) {
but_A = true;
}
return true;
}
void on_event(const uint32_t& events) { void on_event(const uint32_t& events) {
static bool wait_for_button_release{false}; // static bool wait_for_button_release{false};
if (!_playfield) { if (!_playfield) {
_playfield = std::make_unique<Playfield>(); _playfield = std::make_unique<Playfield>();
@ -48,29 +76,30 @@ void on_event(const uint32_t& events) {
} }
if (events & 1) { if (events & 1) {
auto switches_raw = _api->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)); /*
auto switches_debounced = _api->get_switches_state(); auto switches_raw = _api->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));
auto switches_debounced = _api->get_switches_state();
// For the Select (Start/Pause) button, wait for release to avoid repeat // For the Select (Start/Pause) button, wait for release to avoid repeat
uint8_t buttons_to_wait_for = (1 << (int)Switch::Sel); uint8_t buttons_to_wait_for = (1 << (int)Switch::Sel);
if (wait_for_button_release) { if (wait_for_button_release) {
if ((switches_debounced & buttons_to_wait_for) == 0) if ((switches_debounced & buttons_to_wait_for) == 0)
wait_for_button_release = false; wait_for_button_release = false;
switches_debounced &= ~buttons_to_wait_for; switches_debounced &= ~buttons_to_wait_for;
} else { } else {
if (switches_debounced & buttons_to_wait_for) if (switches_debounced & buttons_to_wait_for)
wait_for_button_release = true; wait_for_button_release = true;
} }
// For the directional buttons, use the raw inputs for fastest response time // For the directional buttons, use the raw inputs for fastest response time
but_RIGHT = (switches_raw & (1 << (int)Switch::Right)) != 0; but_RIGHT = (switches_raw & (1 << (int)Switch::Right)) != 0;
but_LEFT = (switches_raw & (1 << (int)Switch::Left)) != 0; but_LEFT = (switches_raw & (1 << (int)Switch::Left)) != 0;
but_DOWN = (switches_raw & (1 << (int)Switch::Down)) != 0; but_DOWN = (switches_raw & (1 << (int)Switch::Down)) != 0;
but_UP = (switches_raw & (1 << (int)Switch::Up)) != 0; but_UP = (switches_raw & (1 << (int)Switch::Up)) != 0;
// For the pause button, use the debounced input to avoid glitches, and OR in the value to make sure that we don't clear it before it's seen
but_A |= (switches_debounced & (1 << (int)Switch::Sel)) != 0;
// For the pause button, use the debounced input to avoid glitches, and OR in the value to make sure that we don't clear it before it's seen
but_A |= (switches_debounced & (1 << (int)Switch::Sel)) != 0;
*/
_playfield->Step(); _playfield->Step();
} }
} }

View file

@ -26,6 +26,7 @@
void initialize(const standalone_application_api_t& api); void initialize(const standalone_application_api_t& api);
void on_event(const uint32_t& events); void on_event(const uint32_t& events);
bool on_key_event(uint8_t key_val);
void shutdown(); void shutdown();
extern const standalone_application_api_t* _api; extern const standalone_application_api_t* _api;

View file

@ -133,39 +133,111 @@ const byte _initSprites[] =
// Ghost colors // Ghost colors
const byte _palette2[] = const byte _palette2[] =
{ {
0, 11, 1, 15, // BINKY red 0,
0, 11, 3, 15, // PINKY pink 11,
0, 11, 5, 15, // INKY cyan 1,
0, 11, 7, 15, // CLYDE brown 15, // BINKY red
0, 11, 9, 9, // PACMAN yellow 0,
0, 11, 15, 15, // FRIGHTENED 11,
0, 11, 0, 15, // DEADEYES 3,
15, // PINKY pink
0,
11,
5,
15, // INKY cyan
0,
11,
7,
15, // CLYDE brown
0,
11,
9,
9, // PACMAN yellow
0,
11,
15,
15, // FRIGHTENED
0,
11,
0,
15, // DEADEYES
0, 1, 15, 2, // cherry 0,
0, 1, 15, 12, // strawberry 1,
0, 7, 2, 12, // peach 15,
0, 9, 15, 0, // bell 2, // cherry
0,
1,
15,
12, // strawberry
0,
7,
2,
12, // peach
0,
9,
15,
0, // bell
0, 15, 1, 2, // apple 0,
0, 12, 15, 5, // grape 15,
0, 11, 9, 1, // galaxian 1,
0, 5, 15, 15, // key 2, // apple
0,
12,
15,
5, // grape
0,
11,
9,
1, // galaxian
0,
5,
15,
15, // key
}; };
const byte _paletteIcon2[] = const byte _paletteIcon2[] =
{ {
0, 9, 9, 9, // PACMAN 0,
9,
9,
9, // PACMAN
0, 2, 15, 1, // cherry 0,
0, 12, 15, 1, // strawberry 2,
0, 12, 2, 7, // peach 15,
0, 0, 15, 9, // bell 1, // cherry
0,
12,
15,
1, // strawberry
0,
12,
2,
7, // peach
0,
0,
15,
9, // bell
0, 2, 15, 1, // apple 0,
0, 12, 15, 5, // grape 2,
0, 1, 9, 11, // galaxian 15,
0, 5, 15, 15, // key 1, // apple
0,
12,
15,
5, // grape
0,
1,
9,
11, // galaxian
0,
5,
15,
15, // key
}; };
#define PACMANICON 1 #define PACMANICON 1
@ -571,7 +643,7 @@ class Playfield {
} }
#endif #endif
x += (240 - 224) / 2; x += (*(_api->screen_width) - 224) / 2;
y += (320 - 288) / 2 + 8; y += (320 - 288) / 2 + 8;
// Should be a direct Graphics call // Should be a direct Graphics call