From 4211296f3b36bc6da0a6b0fd6456ad7a904bbfb5 Mon Sep 17 00:00:00 2001 From: Trevor Boddy Date: Sun, 21 Aug 2022 13:44:00 -0400 Subject: [PATCH] foreground work --- src/background.h | 2 +- src/foreground.h | 32 ++++++++++++++++++-------------- 2 files changed, 19 insertions(+), 15 deletions(-) diff --git a/src/background.h b/src/background.h index a0cf3bd..70c4951 100644 --- a/src/background.h +++ b/src/background.h @@ -30,7 +30,7 @@ fix16 bgPosXF[GAME_H_T]; static void scrollBg(){ for(u8 y = 0; y < GAME_H_T; y++){ - if(y > 3) bgPosXF[y] = fix16Sub(bgPosXF[y], BG_SPEED); + if(y > 2) bgPosXF[y] = fix16Sub(bgPosXF[y], BG_SPEED); if(bgPosXF[y] <= -BG_SIZE_F) bgPosXF[y] = fix16Add(bgPosXF[y], BG_SIZE_F); bgPosX[y] = fix16ToInt(bgPosXF[y]); } diff --git a/src/foreground.h b/src/foreground.h index 7ad4dc2..5d0b257 100644 --- a/src/foreground.h +++ b/src/foreground.h @@ -26,18 +26,24 @@ SpriteDefinition* currentBottomImage; static void drawFg(){ switch(currentFg){ case 0: - currentTopImage = &rock1Top; - currentBottomImage = &rock1Bottom; + VDP_loadTileSet(rock1Top.tileset, FG_I, DMA); + VDP_loadTileSet(rock1Bottom.tileset, FG_I + 16, DMA); break; case 1: - currentTopImage = &rock2Top; - currentBottomImage = &rock2Bottom; + VDP_loadTileSet(rock2Top.tileset, FG_I, DMA); + VDP_loadTileSet(rock2Bottom.tileset, FG_I + 16, DMA); break; } + + for(u16 x = 0; x < FG_W; x++){ if(x % 4 == 0){ - VDP_drawImageEx(BG_B, currentTopImage, TILE_ATTR_FULL(PAL2, 1, 0, 0, FG_I), x, CEIL_Y, 0, DMA); - VDP_drawImageEx(BG_B, currentBottomImage, TILE_ATTR_FULL(PAL2, 1, 0, 0, FG_I + 16), x, FLOOR_Y, 0, DMA); + for(s16 i = 0; i < 4; i++){ + for(s16 j = 0; j < 4; j++){ + VDP_setTileMapXY(BG_B, TILE_ATTR_FULL(PAL2, 1, 0, 0, FG_I + i + 4 * j), x + i, CEIL_Y + j); + VDP_setTileMapXY(BG_B, TILE_ATTR_FULL(PAL2, 1, 0, 0, FG_I + 16 + i + 4 * j), x + i, FLOOR_Y + j); + } + } } } } @@ -91,17 +97,15 @@ static void spawnObstacle(bool top, s16 offset, u8 type){ #define OBSTACLE_MOD FIX16(8) #define OBSTACLE_LIMIT_X FIX16(-64) -SpriteDefinition* obstacleImage; - static void killObstacle(s16 i){ obstacles[i].active = FALSE; VDP_clearTileMapRect(BG_B, obstacles[i].startX, obstacles[i].top ? OBS_CEIL_Y + 4 : OBS_FLOOR_Y, 4, 4); - VDP_drawImageEx(BG_B, - obstacles[i].top ? currentTopImage : currentBottomImage, - TILE_ATTR_FULL(PAL2, 1, 0, 0, FG_I + (obstacles[i].top ? 0 : 16)), - obstacles[i].startX, - obstacles[i].top ? CEIL_Y : FLOOR_Y, - 0, DMA_QUEUE); + for(s16 h = 0; h < 4; h++){ + for(s16 j = 0; j < 4; j++){ + if(obstacles[i].top) VDP_setTileMapXY(BG_B, TILE_ATTR_FULL(PAL2, 1, 0, 0, FG_I + h + 4 * j), obstacles[i].startX + h, CEIL_Y + j); + else VDP_setTileMapXY(BG_B, TILE_ATTR_FULL(PAL2, 1, 0, 0, FG_I + 16 + h + 4 * j), obstacles[i].startX + h, FLOOR_Y + j); + } + } } static void collideObstacle(s16 i){