Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- int cross(double x1, double x2, double x3, double x4, double y1, double y2, double y3, double y4)
- {
- double a1;
- double b1;
- double a2;
- double b2;
- double res;
- if (x1 != x2 && x4 != x3)
- {
- a1 = (y2 - y1) / (x2 - x1);
- a2 = (y4 - y3) / (x4 - x3);
- if (a1 == a2)
- return (0);
- b1 = y1 - (a1 * x1);
- b2 = y3 - (a2 * x3);
- res = (b2 - b1) / (a1 - a2);
- if (((res >= x1 && res <= x2) || (res >= x2 && res <= x1)) && ((res > x3 && res < x4) || (res > x4 && res < x3)))
- return (1);
- }
- else
- {
- if (x1 == x2 && x3 == x4)
- return (0);
- else if (x1 == x2)
- {
- a2 = (y4 - y3) / (x4 - x3);
- b2 = y3 - (a2 * x3);
- res = a2 * x1 + b2;
- }
- else if (x3 == x4)
- {
- a1 = (y2 - y1) / (x2 - x1);
- b1 = y1 - (a1 * x1);
- res = a1 * x3 + b1;
- }
- if (((res >= y1 && res <= y2) || (res >= y2 && res <= y1)) && ((res > y3 && res < y4) || (res > y4 && res < x3)))
- return (1);
- }
- return (0);
- }
- void sprite(t_env *w, t_map *m)
- {
- int x;
- int y;
- int z;
- double v1x;
- double v1y;
- double t1x;
- double t1z;
- double xscale1;
- double x1;
- double y1a;
- double yscale1;
- int d;
- int i;
- int l;
- int h;
- double diffx;
- double diffy;
- double range;
- int g;
- t_coor p;
- t_draw work;
- d = 0;
- (void)work;
- hand(m, w);
- while (d < WIDTH)
- {
- work.ytop[d] = 0;
- work.ybot[d] = HEIGHT - 1;
- d++;
- }
- d = 0;
- x = 40;
- y = 4;
- z = 32;
- v1x = x - PL_X;
- v1y = y - PL_Y;
- t1x = v1x * PL_AS - v1y * PL_AC;
- t1z = v1x * PL_AC + v1y * PL_AS;
- xscale1 = m->player.field_of_vision_h / t1z;
- yscale1 = m->player.field_of_vision_v / t1z;
- x1 = WIDTH / 2 - (int)(t1x * xscale1);
- y1a = HEIGHT / 2 - (int)(yaw((m->sector[3].floor - m->player.coor.z), t1z, m) * yscale1) - 64;
- x1 = x1 - 32;
- diffx = fabs(m->player.coor.x - x);
- diffy = fabs(m->player.coor.y - y);
- range = sqrt((diffx * diffx) + (diffy * diffy)) / 100;
- range = 0.5 / range;
- if (range < 1)
- range = 1;
- else if (range < 2)
- y1a = y1a - (64 * fmod(range, 1));
- else
- y1a = y1a - (64 * ((int)range - 1 + fmod(range, 1)));
- g = 1;
- p.x = x;
- p.y = y;
- if (z > m->sector[m->player.sector].ceiling)
- g = 0;
- while (i < m->sector_count)
- {
- while (h < m->sector[i].wall_count)
- {
- if (m->visible[i].wall[h] == 1 && m->sector[i].network[h] < 0)
- if (pointside(p, m->sector[i].dot[h].x , m->sector[i].dot[h].y, m->sector[i].dot[h + 1].x, m->sector[i].dot[h + 1].y) <= 0)
- {
- if (cross(m->player.coor.x, x, m->sector[i].dot[h].x, m->sector[i].dot[h + 1].x, m->player.coor.y, y, m->sector[i].dot[h].y, m->sector[i].dot[h + 1].y) == 1)
- g = 0;
- }
- h++;
- }
- h = 0;
- i++;
- }
- if (t1z > 0 && g == 1)
- {
- while (d < 64)
- {
- i = 0;
- while (i < 64)
- {
- h = 0;
- while (h < range)
- {
- l = 0;
- while (l < range)
- {
- if (w->sprite[0].pix[d * 64 + i] != 4288151688 && (y1a + h >= 0 && y1a + h < HEIGHT) && (x1 + l >= 0 && x1 + l < WIDTH))
- w->pix[(int)(y1a + h) * WIDTH + (int)(x1 + l)] = w->sprite[0].pix[d * 64 + i];
- l++;
- }
- h++;
- }
- x1 += range;
- i++;
- }
- x1 -= 64 * range;
- y1a += range;
- d++;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement