- El ninotet en el minimap ara es veu millor
- Arreglat el issue #1 "noclip en els cantons caminant arrere"
This commit is contained in:
78
main.cpp
78
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)
|
bool tryMove(float angle, float speed)
|
||||||
{
|
{
|
||||||
|
float sign = speed > 0 ? 1.0f : -1.0f;
|
||||||
bool moved = false;
|
bool moved = false;
|
||||||
sector &s = sectors[current_sector];
|
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;
|
bool collision=false;
|
||||||
for (auto w : s.walls) {
|
for (auto w : s.walls) {
|
||||||
if (get_line_intersection(position, newpos, s.verts[w.v1], s.verts[w.v2], NULL))
|
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;
|
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;
|
collision=false;
|
||||||
for (auto w : s.walls) {
|
for (auto w : s.walls) {
|
||||||
if (get_line_intersection(position, newpos, s.verts[w.v1], s.verts[w.v2], NULL))
|
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;
|
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;
|
return moved;
|
||||||
}
|
}
|
||||||
@@ -384,68 +387,7 @@ int main(int argc, char *argv[])
|
|||||||
infi.y = position.y + SDL_sinf(angle*DEG_TO_RAD)*40000;
|
infi.y = position.y + SDL_sinf(angle*DEG_TO_RAD)*40000;
|
||||||
|
|
||||||
drawColumn(s, screen_column, 0, 240, a_inc, infi);
|
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 (d<dist) {
|
|
||||||
dist = d;
|
|
||||||
result = tmp_result;
|
|
||||||
w = &wall;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (w) {
|
|
||||||
putp(int(result.x/8),int(result.y/8),6);
|
|
||||||
dist *= SDL_cosf(a_inc*DEG_TO_RAD);
|
|
||||||
const vec2 AB = {s.verts[w->v2].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<wall_start-1; y++) {
|
|
||||||
float straight_dist = (277 * (64-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]);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Pinta la pared
|
|
||||||
for (int i=0; i<wall_height; ++i) {
|
|
||||||
if (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++;
|
screen_column++;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -461,9 +403,9 @@ int main(int argc, char *argv[])
|
|||||||
|
|
||||||
// Draw map hero
|
// Draw map hero
|
||||||
vec2 lookat;
|
vec2 lookat;
|
||||||
lookat.x = position.x + SDL_cosf(orientation*DEG_TO_RAD)*4;
|
lookat.x = position.x + SDL_cosf(orientation*DEG_TO_RAD)*20;
|
||||||
lookat.y = position.y + SDL_sinf(orientation*DEG_TO_RAD)*4;
|
lookat.y = position.y + SDL_sinf(orientation*DEG_TO_RAD)*20;
|
||||||
map::line(position.x, position.y, lookat.x, lookat.y, 1);
|
map::line(position.x, position.y, lookat.x, lookat.y, 3);
|
||||||
map::putp(position.x, position.y, 7);
|
map::putp(position.x, position.y, 7);
|
||||||
|
|
||||||
// Send to texture and render
|
// Send to texture and render
|
||||||
|
|||||||
Reference in New Issue
Block a user