fixed (sorta)

This commit is contained in:
Samuel Walker 2024-09-01 07:56:27 -06:00
parent a8eb642e9b
commit bf9f03c963

View File

@ -152,20 +152,24 @@ void castRay(s16 angle, s16 column){
} }
//Wall height calcs //Wall height calcs
fix16 wallHeightFix16 = fix16Div(FIX16(SCREEN_HEIGHT), (shortestDist + FIX16(1))); fix16 wallHeightFix16 = fix16Div(FIX16(SCREEN_HEIGHT), (shortestDist + FIX16(1)));
wallHeightFix16 = fix16Mul(wallHeightFix16, WALL_HEIGHT_SCALE); wallHeightFix16 = fix16Mul(wallHeightFix16, WALL_HEIGHT_SCALE);
int wallHeight = fix16ToInt(wallHeightFix16); int wallHeight = fix16ToInt(wallHeightFix16);
int wallTop = (SCREEN_HEIGHT / 2) - (wallHeight / 2); int wallTop = (SCREEN_HEIGHT / 2) - (wallHeight / 2);
int wallBottom = (SCREEN_HEIGHT / 2) + (wallHeight / 2); int wallBottom = (SCREEN_HEIGHT / 2) + (wallHeight / 2);
if (wallTop < 0) wallTop = 0; if (wallTop < 0) wallTop = 0;
if (wallBottom >= SCREEN_HEIGHT) wallBottom = SCREEN_HEIGHT - 1; if (wallBottom >= SCREEN_HEIGHT) wallBottom = SCREEN_HEIGHT - 1;
u16 tileTop = wallTop / TILE_HEIGHT; u16 tileTop = wallTop / TILE_HEIGHT;
u16 tileBottom = wallBottom / TILE_HEIGHT; u16 tileBottom = wallBottom / TILE_HEIGHT;
u16 tileHeight = tileBottom - tileTop + 1; u16 tileHeight = tileBottom - tileTop + 1;
for (int yTile = tileTop; yTile <= tileBottom; yTile++) { for (int yTile = 0; yTile <= SCREEN_TILES_Y; yTile++) {
VDP_setTileMapXY(BG_B, TILE_ATTR_FULL(PAL1, 0, FALSE, FALSE, TILE_FILLED), column, 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) { void clearScreenWithTile(u16 tileIndex) {
// Fill the entire screen with the background tile // 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_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() { void drawMap() {
@ -216,25 +221,31 @@ void drawMap() {
} }
void render() { void render() {
clearScreenWithTile(TILE_EMPTY); clearScreenWithTile(TILE_EMPTY);
s16 castStart = angle - 20; s16 castStart = angle - 20;
if(angle >= 360) angle = angle - 360; if(angle >= 360) angle = angle - 360;
if(angle < 0) angle = 360 + angle; if(angle < 0) angle = 360 + angle;
if(castStart >= 360) castStart = castStart - 360;
if(castStart < 0) castStart = 360 + castStart;
for(int i = 0; i < 40; i++){ for(int i = 0; i < 40; i++){
castRay(castStart + i, i); s16 cast = castStart+i;
} if(cast >= 360) cast = cast - 360;
//drawMap(); if(cast < 0) cast = 360 + cast;
VDP_setTextPlane(BG_B); castRay(cast, i);
VDP_setTextPalette(2); //VDP_waitVSync();
VDP_showFPS(1); }
char debugCastText[20]; //drawMap();
sprintf(debugCastText, "Cast: %d", castStart); VDP_setTextPlane(BG_B);
VDP_drawText(debugCastText, 20, 2); VDP_setTextPalette(2);
angle = angle + 1; VDP_showFPS(1);
char debugCastText[20];
sprintf(debugCastText, "Cast: %03d", castStart);
VDP_drawText(debugCastText, 20, 2);
angle = angle + 1;
SYS_doVBlankProcess(); SYS_doVBlankProcess();
} }
void update() { void update() {