From 69e6f12bb716b890f53a1154d25672eb16e47d27 Mon Sep 17 00:00:00 2001 From: John Tsiombikas Date: Tue, 2 Jan 2024 20:52:48 +0200 Subject: [PATCH] fixed sprite scaling --- src/part_dna.c | 51 ++++++++++++++++++++++++++++++++------------------- 1 file changed, 32 insertions(+), 19 deletions(-) diff --git a/src/part_dna.c b/src/part_dna.c index d5edadb..4ca99c2 100644 --- a/src/part_dna.c +++ b/src/part_dna.c @@ -1,3 +1,4 @@ +#include #include "sprite.h" #include "vdp.h" #include "demo.h" @@ -37,7 +38,7 @@ void dna_update(void) { static int x = 160; static int y = 120; - static int sz = 0; + static int sz = 24; if(bnstate & PAD_UP) { if(y > 0) y--; @@ -60,57 +61,69 @@ void dna_update(void) static void particle(int x, int y, int pixsz) { - int tile, offs = 4, szlevel; + int tile, offs = 4, invoffs, szlevel; + static int offstab[] = { + 4, 4, 4, 4, 4, 4, 4, 4, + 4, 8, 8, 8, 8, 8, 8, 8, - if(pixsz < 2) { + 8, 14, 14, 15, 15, 15, 16, 16, + 16, 14, 14, 15, 15, 15, 16, 16, + 16 + }; + + dbgval[0] = pixsz; + + if(pixsz <= 2) { szlevel = 0; pixsz = 2; tile = VDP_ADDR2TILE(SPRITE_BASE); - } else if(pixsz < 16) { - szlevel = pixsz >> 1; - tile = VDP_ADDR2TILE(SPRITE_BASE) + szlevel; - } else if(pixsz < 24) { - szlevel = 7; + } else if(pixsz <= 16) { + szlevel = (pixsz - 1) >> 1; tile = VDP_ADDR2TILE(SPRITE_BASE) + szlevel; - } else if(pixsz < 32) { + } else if(pixsz <= 24) { szlevel = 8; + tile = VDP_ADDR2TILE(SPRITE_BASE) + 8; + } else if(pixsz <= 32) { + szlevel = 9; + tile = VDP_ADDR2TILE(SPRITE_BASE) + 12; } else { szlevel = 9; + tile = VDP_ADDR2TILE(SPRITE_BASE) + 12; pixsz = 32; } - dbgval[0] = pixsz; dbgval[1] = szlevel; + dbgval[2] = tile; - tile = VDP_ADDR2TILE(SPRITE_BASE) + (pixsz < 32 ? szlevel : 12); + offs = offstab[pixsz]; switch(szlevel) { case 0: case 1: case 2: case 3: - spr_add(x - 4, y - 4, VDP_TILENAME(tile, 1, VDP_TILE_FG), SPR_SIZE(1, 1)); + spr_add(x - offs, y - offs, VDP_TILENAME(tile, 1, VDP_TILE_FG), SPR_SIZE(1, 1)); break; case 4: /* 10x10 */ case 5: /* 12x12 */ case 6: /* 14x14 */ case 7: /* 16x16 */ - offs = 8; spr_add(x - offs, y - offs, VDP_TILENAME(tile, 1, VDP_TILE_FG), SPR_SIZE(1, 1)); spr_add(x, y - offs, VDP_TILENAME(tile, 1, VDP_TILE_FG | VDP_TILE_HFLIP), SPR_SIZE(1, 1)); spr_add(x - offs, y, VDP_TILENAME(tile, 1, VDP_TILE_FG | VDP_TILE_VFLIP), SPR_SIZE(1, 1)); spr_add(x, y, VDP_TILENAME(tile, 1, VDP_TILE_FG | VDP_TILE_HVFLIP), SPR_SIZE(1, 1)); break; - default: - offs = 8 + (pixsz & 7); + case 8: /* 17x17 - 24x24 */ + default: /* 25x25 - 32x32 */ + invoffs = 16 - offs; spr_add(x - offs, y - offs, VDP_TILENAME(tile, 1, VDP_TILE_FG), SPR_SIZE(2, 2)); - spr_add(x, y - offs, VDP_TILENAME(tile, 1, VDP_TILE_FG | VDP_TILE_HFLIP), SPR_SIZE(2, 2)); - spr_add(x - offs, y, VDP_TILENAME(tile, 1, VDP_TILE_FG | VDP_TILE_VFLIP), SPR_SIZE(2, 2)); - spr_add(x, y, VDP_TILENAME(tile, 1, VDP_TILE_FG | VDP_TILE_HVFLIP), SPR_SIZE(2, 2)); + spr_add(x - invoffs, y - offs, VDP_TILENAME(tile, 1, VDP_TILE_FG | VDP_TILE_HFLIP), SPR_SIZE(2, 2)); + spr_add(x - offs, y - invoffs, VDP_TILENAME(tile, 1, VDP_TILE_FG | VDP_TILE_VFLIP), SPR_SIZE(2, 2)); + spr_add(x - invoffs, y - invoffs, VDP_TILENAME(tile, 1, VDP_TILE_FG | VDP_TILE_HVFLIP), SPR_SIZE(2, 2)); break; } - dbgval[2] = offs; + dbgval[3] = offs; } -- 1.7.10.4