From 4b93e78dd9b301f2172e847db8e1b52cd6f292be Mon Sep 17 00:00:00 2001 From: sommermoregentraum Date: Sun, 7 Jan 2024 23:55:45 +0800 Subject: [PATCH] make pacman's face (mouse) face to the dir which he hits the wall (#1735) --- .../application/external/pacman/playfield.hpp | 28 ++++++++++++++----- 1 file changed, 21 insertions(+), 7 deletions(-) diff --git a/firmware/application/external/pacman/playfield.hpp b/firmware/application/external/pacman/playfield.hpp index 7c35b615..e1b02628 100644 --- a/firmware/application/external/pacman/playfield.hpp +++ b/firmware/application/external/pacman/playfield.hpp @@ -205,11 +205,13 @@ class Sprite { byte who; byte _speed; byte dir; + byte lastDir; byte phase; // Sprite bits byte palette2; // 4->16 color map index byte bits; // index of sprite bits + signed char sy; void Init(const byte* s) { @@ -274,9 +276,17 @@ class Sprite { f = pgm_read_byte(_pacLeftAnim + f); else if (dir == MRight) f = pgm_read_byte(_pacRightAnim + f); - else + else if (dir == MDown || dir == MUp) f = pgm_read_byte(_pacVAnim + f); - if (dir == MUp) + else if (dir == MStopped) { + if (lastDir == MLeft) + f = pgm_read_byte(_pacLeftAnim + f); + else if (lastDir == MRight) + f = pgm_read_byte(_pacRightAnim + f); + else if (lastDir == MDown || lastDir == MUp) + f = pgm_read_byte(_pacVAnim + f); + } + if ((dir == MUp) || (dir == MStopped && lastDir == MUp)) sy = -1; bits = f + PACMANSPRITE; } @@ -838,15 +848,19 @@ class Playfield { else if (DEMO == 0 && s->who == PACMAN && choice[3] < 0x7FFF && but_RIGHT) dir = MRight; - else if (DEMO == 0 && choice[0] < 0x7FFF && s->who == PACMAN && dir == MUp) + else if (DEMO == 0 && choice[0] < 0x7FFF && s->who == PACMAN && dir == MUp) { dir = MUp; - else if (DEMO == 0 && choice[1] < 0x7FFF && s->who == PACMAN && dir == MLeft) + s->lastDir = MUp; + } else if (DEMO == 0 && choice[1] < 0x7FFF && s->who == PACMAN && dir == MLeft) { dir = MLeft; - else if (DEMO == 0 && choice[2] < 0x7FFF && s->who == PACMAN && dir == MDown) + s->lastDir = MLeft; + } else if (DEMO == 0 && choice[2] < 0x7FFF && s->who == PACMAN && dir == MDown) { dir = MDown; - else if (DEMO == 0 && choice[3] < 0x7FFF && s->who == PACMAN && dir == MRight) + s->lastDir = MDown; + } else if (DEMO == 0 && choice[3] < 0x7FFF && s->who == PACMAN && dir == MRight) { dir = MRight; - else if ((DEMO == 0 && s->who != PACMAN) || DEMO == 1) { + s->lastDir = MRight; + } else if ((DEMO == 0 && s->who != PACMAN) || DEMO == 1) { // Don't choose opposite of current direction? int16_t dist = choice[4 - dir]; // favor current direction