From fcc1e3cc23f050ca5b01d18fef6adcea8e93352f Mon Sep 17 00:00:00 2001 From: Gabriel Ravier Date: Sun, 15 Sep 2019 10:48:18 +0200 Subject: [PATCH] Added some common macro utilities used by most NPCs I'm pretty sure Pixel didn't actually use macros for this but I don't think just having this kind of stuff copied around everywhere is really great either Forgot to commit and push this yesterday Signed-off-by: Gabriel Ravier --- src/BossFrog.cpp | 14 +++----------- src/NpChar.h | 19 +++++++++++++++++++ 2 files changed, 22 insertions(+), 11 deletions(-) diff --git a/src/BossFrog.cpp b/src/BossFrog.cpp index 172c71c3..82541d2f 100644 --- a/src/BossFrog.cpp +++ b/src/BossFrog.cpp @@ -573,17 +573,9 @@ void ActBossChar_Frog(void) break; } - boss->ym += 0x40; - if (boss->ym > 0x5FF) - boss->ym = 0x5FF; - - boss->x += boss->xm; - boss->y += boss->ym; - - if (boss->direct == DIR_LEFT) - boss->rect = rcLeft[boss->ani_no]; - else - boss->rect = rcRight[boss->ani_no]; + NPC_DO_GRAVITY(boss, 0x40, 0x5FF); + NPC_UPDATE_POSITIONS_WITH_VELOCITIES(boss); + NPC_SET_RECT_FROM_LEFT_RIGHT(boss, rcLeft, rcRight); ActBossChar02_01(); ActBossChar02_02(); diff --git a/src/NpChar.h b/src/NpChar.h index 185a26b8..7fb14295 100644 --- a/src/NpChar.h +++ b/src/NpChar.h @@ -1,11 +1,30 @@ #pragma once +#include "CommonDefines.h" #include "WindowsWrapper.h" #include "Draw.h" #define NPC_MAX 0x200 +#define NPC_CAP_Y_VELOCITY(npc, maxYVel) \ + if (npc->ym > (maxYVel)) \ + npc->ym = (maxYVel) + +#define NPC_DO_GRAVITY(npc, ymAdd, maxYVel) \ + npc->ym += ymAdd; \ + NPC_CAP_Y_VELOCITY(npc, maxYVel) + +#define NPC_UPDATE_POSITIONS_WITH_VELOCITIES(npc) \ + npc->x += npc->xm; \ + npc->y = npc->ym; + +#define NPC_SET_RECT_FROM_LEFT_RIGHT(npc, rcLeft, rcRight) \ + if (npc->direct == DIR_LEFT) \ + npc->rect = rcLeft[npc->ani_no]; \ + else \ + npc->rect = rcRight[npc->ani_no]; + // Be careful when changing these: they're baked into the 'npc.tbl' file enum NPCFlags {