From 20e8375f1818199d9916688f8f0f6958b6fd79bb Mon Sep 17 00:00:00 2001 From: Samuel Walker Date: Fri, 30 Aug 2024 14:04:02 -0600 Subject: [PATCH] Fixed some casting weirdness --- src/main.c | 29 +++++++++++++++-------------- 1 file changed, 15 insertions(+), 14 deletions(-) diff --git a/src/main.c b/src/main.c index 38e6e0e..d5bfa46 100644 --- a/src/main.c +++ b/src/main.c @@ -28,7 +28,7 @@ void castRay(s16 angle){ fix16 dy = sinFix16(ind); fix16 dx = cosFix16(ind); - fix16 tan = FIX16(1); + fix16 tan = FIX16(0); if(dx != 0) tan = fix16Div(dy, dx); fix16 aTan = FIX16(0); if(tan != 0) aTan = fix16Div(FIX16(-1), tan); @@ -37,7 +37,7 @@ void castRay(s16 angle){ fix16 distH = FIX16(500); fix16 hx = FIX16(l.pt1.x); fix16 hy = FIX16(l.pt1.y); - if(angle == 0 || angle == 180){ + if(dy == 0){ rx = FIX16(l.pt1.x); ry = FIX16(l.pt1.y); dof = 8; @@ -58,7 +58,11 @@ void castRay(s16 angle){ while(dof<8){ mx = fix16ToInt(rx) / 10; my = fix16ToInt(ry) / 10; - if(mx >=0 && my >= 0 && mx < 10 && my < 10 && map[my][mx] == 1){ + if(rx < 0 || ry < 0){ + dof = 8; + continue; + } + if(mx < 10 && my < 10 && map[my][mx] == 1){ dof = 8; hx = rx; hy = ry; @@ -87,9 +91,11 @@ void castRay(s16 angle){ xo = FIX16(10); yo = fix16Mul(0-xo,nTan); } - if(angle == 90 || angle == 270){ + if(dx == 0){ rx = FIX16(l.pt1.x); ry = FIX16(l.pt1.y); + xo = FIX16(0); + yo = FIX16(0); dof = 8; } while(dof<8){ @@ -113,12 +119,6 @@ void castRay(s16 angle){ l.pt2.x = fix16ToInt(hx); l.pt2.y = fix16ToInt(hy); } - char* str[5]; - sprintf(str, "%d", distV); - BMP_drawText(str, 20, 0); - char* str2[5]; - sprintf(str2, "%d", distH); - BMP_drawText(str2, 20, 1); } void mapscan(){ @@ -147,10 +147,11 @@ void render(){ //Draw the line defined above (in the background, hidden) mapscan(); - if(angle > 360) angle = 0; - if(angle < 0) angle = 359; + if(angle >= 360) angle = angle - 360; + if(angle < 0) angle = 360 + angle; castRay(angle); BMP_drawLine(&l); + BMP_showFPS(0); //Flip the data to the screen - i.e. actually draw the complete image on screen BMP_flip(1); @@ -172,11 +173,11 @@ void update(){ u16 joy = JOY_readJoypad(JOY_1); if(joy & BUTTON_LEFT) { //l.pt1.x -= SPEED; - angle--; + angle -= 1; } if(joy & BUTTON_RIGHT) { //l.pt1.x += SPEED; - angle++; + angle += 1; } if(joy & BUTTON_UP) { l.pt1.y -= SPEED;