From bf9f03c96332a933b1aaf7431c589399075c6c0b Mon Sep 17 00:00:00 2001 From: Samuel Walker Date: Sun, 1 Sep 2024 07:56:27 -0600 Subject: [PATCH] fixed (sorta) --- src/main.c | 73 +++++++++++++++++++++++++++++++----------------------- 1 file changed, 42 insertions(+), 31 deletions(-) diff --git a/src/main.c b/src/main.c index 869fd00..5d26bff 100644 --- a/src/main.c +++ b/src/main.c @@ -152,20 +152,24 @@ void castRay(s16 angle, s16 column){ } -//Wall height calcs -fix16 wallHeightFix16 = fix16Div(FIX16(SCREEN_HEIGHT), (shortestDist + FIX16(1))); -wallHeightFix16 = fix16Mul(wallHeightFix16, WALL_HEIGHT_SCALE); -int wallHeight = fix16ToInt(wallHeightFix16); -int wallTop = (SCREEN_HEIGHT / 2) - (wallHeight / 2); -int wallBottom = (SCREEN_HEIGHT / 2) + (wallHeight / 2); -if (wallTop < 0) wallTop = 0; -if (wallBottom >= SCREEN_HEIGHT) wallBottom = SCREEN_HEIGHT - 1; -u16 tileTop = wallTop / TILE_HEIGHT; -u16 tileBottom = wallBottom / TILE_HEIGHT; -u16 tileHeight = tileBottom - tileTop + 1; -for (int yTile = tileTop; yTile <= tileBottom; yTile++) { - VDP_setTileMapXY(BG_B, TILE_ATTR_FULL(PAL1, 0, FALSE, FALSE, TILE_FILLED), column, yTile); + //Wall height calcs + fix16 wallHeightFix16 = fix16Div(FIX16(SCREEN_HEIGHT), (shortestDist + FIX16(1))); + wallHeightFix16 = fix16Mul(wallHeightFix16, WALL_HEIGHT_SCALE); + int wallHeight = fix16ToInt(wallHeightFix16); + int wallTop = (SCREEN_HEIGHT / 2) - (wallHeight / 2); + int wallBottom = (SCREEN_HEIGHT / 2) + (wallHeight / 2); + if (wallTop < 0) wallTop = 0; + if (wallBottom >= SCREEN_HEIGHT) wallBottom = SCREEN_HEIGHT - 1; + u16 tileTop = wallTop / TILE_HEIGHT; + u16 tileBottom = wallBottom / TILE_HEIGHT; + u16 tileHeight = tileBottom - tileTop + 1; + for (int yTile = 0; yTile <= SCREEN_TILES_Y; yTile++) { + if(yTile >= tileTop && yTile <= tileBottom){ + VDP_setTileMapXY(BG_B, TILE_ATTR_FULL(PAL1, 0, FALSE, FALSE, TILE_FILLED), column, yTile); + }else{ + VDP_setTileMapXY(BG_B, TILE_ATTR_FULL(PAL1, 0, FALSE, FALSE, TILE_EMPTY), column, yTile); } + } } @@ -204,6 +208,7 @@ void mapscan() { void clearScreenWithTile(u16 tileIndex) { // Fill the entire screen with the background tile VDP_fillTileMapRect(BG_A, TILE_ATTR_FULL(PAL1, 0, FALSE, FALSE, tileIndex), 0, 0, SCREEN_TILES_X, SCREEN_TILES_Y); + //VDP_fillTileMapRect(BG_B, TILE_ATTR_FULL(PAL1, 0, FALSE, FALSE, tileIndex), 0, 0, SCREEN_TILES_X, SCREEN_TILES_Y); } void drawMap() { @@ -216,25 +221,31 @@ void drawMap() { } void render() { - clearScreenWithTile(TILE_EMPTY); - s16 castStart = angle - 20; - if(angle >= 360) angle = angle - 360; + clearScreenWithTile(TILE_EMPTY); + s16 castStart = angle - 20; + if(angle >= 360) angle = angle - 360; if(angle < 0) angle = 360 + angle; - - for(int i = 0; i < 40; i++){ - castRay(castStart + i, i); - } - //drawMap(); - VDP_setTextPlane(BG_B); - VDP_setTextPalette(2); - VDP_showFPS(1); - char debugCastText[20]; - sprintf(debugCastText, "Cast: %d", castStart); - VDP_drawText(debugCastText, 20, 2); - angle = angle + 1; - - - SYS_doVBlankProcess(); + if(castStart >= 360) castStart = castStart - 360; + if(castStart < 0) castStart = 360 + castStart; + + for(int i = 0; i < 40; i++){ + s16 cast = castStart+i; + if(cast >= 360) cast = cast - 360; + if(cast < 0) cast = 360 + cast; + castRay(cast, i); + //VDP_waitVSync(); + } + //drawMap(); + VDP_setTextPlane(BG_B); + VDP_setTextPalette(2); + VDP_showFPS(1); + char debugCastText[20]; + sprintf(debugCastText, "Cast: %03d", castStart); + VDP_drawText(debugCastText, 20, 2); + angle = angle + 1; + + + SYS_doVBlankProcess(); } void update() {