From 960bc8b995ac115f35a41e85816dfa4b0f16fda5 Mon Sep 17 00:00:00 2001 From: Raimon Zamora Date: Fri, 26 Sep 2025 18:30:26 +0200 Subject: [PATCH] - El ninotet en el minimap ara es veu millor - Arreglat el issue #1 "noclip en els cantons caminant arrere" --- main.cpp | 78 ++++++++------------------------------------------------ 1 file changed, 10 insertions(+), 68 deletions(-) diff --git a/main.cpp b/main.cpp index fb580e3..da66ae3 100644 --- a/main.cpp +++ b/main.cpp @@ -256,10 +256,11 @@ void drawColumn(sector &s, int screen_column, int start, int end, float a_inc, v bool tryMove(float angle, float speed) { + float sign = speed > 0 ? 1.0f : -1.0f; bool moved = false; sector &s = sectors[current_sector]; - vec2 newpos = { position.x + SDL_cosf(angle*DEG_TO_RAD)*5, position.y }; + vec2 newpos = { position.x + SDL_cosf(angle*DEG_TO_RAD)*5*sign, position.y }; bool collision=false; for (auto w : s.walls) { if (get_line_intersection(position, newpos, s.verts[w.v1], s.verts[w.v2], NULL)) @@ -274,9 +275,10 @@ bool tryMove(float angle, float speed) break; } } - if (!collision) { moved = true; position.x += SDL_cosf(angle*DEG_TO_RAD)*dt*speed; } + if (!collision) + { moved = true; position.x += SDL_cosf(angle*DEG_TO_RAD)*dt*speed; } - newpos = { position.x, position.y + SDL_sinf(angle*DEG_TO_RAD)*5 }; + newpos = { position.x, position.y + SDL_sinf(angle*DEG_TO_RAD)*5*sign }; collision=false; for (auto w : s.walls) { if (get_line_intersection(position, newpos, s.verts[w.v1], s.verts[w.v2], NULL)) @@ -291,7 +293,8 @@ bool tryMove(float angle, float speed) break; } } - if (!collision) { moved = true; position.y += SDL_sinf(angle*DEG_TO_RAD)*dt*speed; } + if (!collision) + { moved = true; position.y += SDL_sinf(angle*DEG_TO_RAD)*dt*speed; } return moved; } @@ -384,68 +387,7 @@ int main(int argc, char *argv[]) infi.y = position.y + SDL_sinf(angle*DEG_TO_RAD)*40000; drawColumn(s, screen_column, 0, 240, a_inc, infi); - /* - vec2 result, tmp_result; - wall *w = nullptr; - float dist=100000.0f; - for (auto &wall : s.walls) - { - if (get_line_intersection(position, infi, s.verts[wall.v1], s.verts[wall.v2], &tmp_result)) - { - const float d = distance(position, tmp_result);// * SDL_cosf(a_inc*DEG_TO_RAD); - if (dv2].x-s.verts[w->v1].x, s.verts[w->v2].y-s.verts[w->v1].y}; - const vec2 AP = {result.x-s.verts[w->v1].x, result.y-s.verts[w->v1].y}; - float v = dot(AP,AB) / dot(AB,AB); v *= w->u2; v = (v-int(v))*64.0f; - //const float v = distance(s.verts[w.v1], result); - float wall_height = (64*277)/dist; - float dpix = 64/wall_height; - float cpix = 0; - float wall_start = 120-(wall_height/64)*(64-height); - if (wall_start<0) { - cpix = -wall_start*dpix; - wall_height += wall_start; - wall_start=0; - } - - // Pinta el sostre - for (int y=0; y> 1)); - float actual_dist = straight_dist / SDL_cosf(a_inc*DEG_TO_RAD); - int tx = abs(int(actual_dist * SDL_cosf(angle*DEG_TO_RAD) - position.x)) % 64; - int ty = abs(int(actual_dist * SDL_sinf(angle*DEG_TO_RAD) - position.y)) % 64; - putp(screen_column, y, gif[tx+ty*64]); - } - - // Pinta la pared - for (int i=0; i=240) break; - putp(screen_column, wall_start+i, gif[(int(v)%64)+int(cpix)*64]); - cpix += dpix; - } - - // Pinta el piso - int paint_end = wall_start+wall_height-1; - for (int y=paint_end+1; y<240-1; y++) { - float straight_dist = (277 * height) / (y - (240 >> 1)); - float actual_dist = straight_dist / SDL_cosf(a_inc*DEG_TO_RAD); - int tx = abs(int(actual_dist * SDL_cosf(angle*DEG_TO_RAD) + position.x)) % 64; - int ty = abs(int(actual_dist * SDL_sinf(angle*DEG_TO_RAD) + position.y)) % 64; - putp(screen_column, y, gif[tx+ty*64]); - } - //line(screen_column, 120-(wall_height), screen_column, 120+(wall_height), 5); - } - */ screen_column++; } @@ -461,9 +403,9 @@ int main(int argc, char *argv[]) // Draw map hero vec2 lookat; - lookat.x = position.x + SDL_cosf(orientation*DEG_TO_RAD)*4; - lookat.y = position.y + SDL_sinf(orientation*DEG_TO_RAD)*4; - map::line(position.x, position.y, lookat.x, lookat.y, 1); + lookat.x = position.x + SDL_cosf(orientation*DEG_TO_RAD)*20; + lookat.y = position.y + SDL_sinf(orientation*DEG_TO_RAD)*20; + map::line(position.x, position.y, lookat.x, lookat.y, 3); map::putp(position.x, position.y, 7); // Send to texture and render