From 0dde0cb6ef8a3b6e07018491b22cc39577069243 Mon Sep 17 00:00:00 2001 From: cellos51 Date: Sat, 9 Aug 2025 15:14:57 -0400 Subject: [PATCH] Took Copilot's advice and defined some magic numbers --- source/affine_background.c | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/source/affine_background.c b/source/affine_background.c index 0b49cd2..7bdf945 100644 --- a/source/affine_background.c +++ b/source/affine_background.c @@ -7,6 +7,10 @@ BG_AFFINE bgaff; AFF_SRC_EX asx = {32<<8, 64<<8, 120, 80, 0x0100, 0x0100, 0}; static uint timer = 0; +#define TOP_SCANLINE_OFFSET 228 +#define ANIMATION_SPEED_DIVISOR 16 + + void affine_background_init() { memcpy32_tile8_with_palette_offset((u32*)&tile8_mem[AFFINE_BG_CBB], (const u32*)affine_background_gfxTiles, affine_background_gfxTilesLen/4, AFFINE_BG_PB); @@ -23,21 +27,21 @@ void affine_background_hblank() // This fixes a visual issue where the top 3 pixels of the scanline are out of sync if (vcount >= 160) { - vcount -= 228; + vcount -= TOP_SCANLINE_OFFSET; } const s32 timer_s32 = timer << 8; const s32 vcount_s32 = vcount << 8; const s16 vcount_s16 = vcount; - const s32 vcount_sine = lu_sin(vcount_s32 + timer_s32 / 16); // dividing the timer by 16 to make the animation slower + const s32 vcount_sine = lu_sin(vcount_s32 + timer_s32 / ANIMATION_SPEED_DIVISOR); // dividing the timer by 16 to make the animation slower - asx.scr_x = 128; // 128 on x and y is an offset used to center the rotation - asx.scr_y = vcount_s16 - 128; // scr_y must equal vcount otherwise the background will have no vertical difference + asx.scr_x = (SCREEN_WIDTH / 2); // 128 on x and y is an offset used to center the rotation + asx.scr_y = vcount_s16 - (SCREEN_HEIGHT / 2); // scr_y must equal vcount otherwise the background will have no vertical difference asx.tex_x = vcount_sine; asx.tex_y = vcount_sine / 64; asx.sx = vcount_sine / 32; asx.sy = vcount_sine / 16; - asx.alpha = (vcount_s32 + timer_s32) / 16; + asx.alpha = vcount_sine + (timer_s32 / ANIMATION_SPEED_DIVISOR); bg_rotscale_ex(&bgaff, &asx); REG_BG_AFFINE[2] = bgaff;