loop edge mode: allow particles to have velocities greater than the size of the screen

Also, added terminal velocity for stickmen
This commit is contained in:
jacob1 2016-03-12 13:14:20 -05:00
parent 13d3547211
commit d334209027
2 changed files with 46 additions and 40 deletions

View File

@ -2403,27 +2403,22 @@ int Simulation::do_move(int i, int x, int y, float nxf, float nyf)
int nx = (int)(nxf+0.5f), ny = (int)(nyf+0.5f), result; int nx = (int)(nxf+0.5f), ny = (int)(nyf+0.5f), result;
if (edgeMode == 2) if (edgeMode == 2)
{ {
float diffx = 0.0f, diffy = 0.0f; bool x_ok = (nx >= CELL && nx < XRES-CELL);
if (nx < CELL) bool y_ok = (ny >= CELL && ny < YRES-CELL);
diffx = XRES-CELL*2; if (!x_ok)
if (nx >= XRES-CELL) nxf = remainder_p(nxf-CELL, XRES-CELL*2.5f)+CELL;
diffx = -(XRES-CELL*2); if (!y_ok)
if (ny < CELL) nyf = remainder_p(nyf-CELL, YRES-CELL*2.5f)+CELL;
diffy = YRES-CELL*2;
if (ny >= YRES-CELL)
diffy = -(YRES-CELL*2);
if (diffx || diffy)
{
nxf += diffx;
nyf += diffy;
nx = (int)(nxf+0.5f); nx = (int)(nxf+0.5f);
ny = (int)(nyf+0.5f); ny = (int)(nyf+0.5f);
/*if (!x_ok || !y_ok)
{
//make sure there isn't something blocking it on the other side //make sure there isn't something blocking it on the other side
//only needed if this if statement is moved after the try_move (like my mod) //only needed if this if statement is moved after the try_move (like my mod)
//if (!eval_move(t, nx, ny, NULL) || (t == PT_PHOT && pmap[ny][nx])) //if (!eval_move(t, nx, ny, NULL) || (t == PT_PHOT && pmap[ny][nx]))
// return -1; // return -1;
} }*/
} }
if (parts[i].type == PT_NONE) if (parts[i].type == PT_NONE)
return 0; return 0;
@ -4081,14 +4076,12 @@ killed:
fin_y = (int)(fin_yf+0.5f); fin_y = (int)(fin_yf+0.5f);
if (edgeMode == 2) if (edgeMode == 2)
{ {
if (fin_x < CELL) bool x_ok = (fin_x >= CELL && fin_x < XRES-CELL);
fin_xf += XRES-CELL*2; bool y_ok = (fin_y >= CELL && fin_y < YRES-CELL);
if (fin_x >= XRES-CELL) if (!x_ok)
fin_xf -= XRES-CELL*2; fin_xf = remainder_p(fin_xf-CELL, XRES-CELL*2.5f)+CELL;
if (fin_y < CELL) if (!y_ok)
fin_yf += YRES-CELL*2; fin_yf = remainder_p(fin_yf-CELL, YRES-CELL*2.5f)+CELL;
if (fin_y >= YRES-CELL)
fin_yf -= YRES-CELL*2;
fin_x = (int)(fin_xf+0.5f); fin_x = (int)(fin_xf+0.5f);
fin_y = (int)(fin_yf+0.5f); fin_y = (int)(fin_yf+0.5f);
} }
@ -4134,22 +4127,22 @@ killed:
int ny = (int)((float)parts[i].y+0.5f); int ny = (int)((float)parts[i].y+0.5f);
if (edgeMode == 2) if (edgeMode == 2)
{ {
int diffx = 0, diffy = 0; bool x_ok = (nx >= CELL && nx < XRES-CELL);
if (nx < CELL) bool y_ok = (ny >= CELL && ny < YRES-CELL);
diffx = XRES-CELL*2; int oldnx = nx, oldny = ny;
if (nx >= XRES-CELL) if (!x_ok)
diffx = -(XRES-CELL*2);
if (ny < CELL)
diffy = YRES-CELL*2;
if (ny >= YRES-CELL)
diffy = -(YRES-CELL*2);
if (diffx || diffy) //when moving from left to right stickmen might be able to fall through solid things, fix with "eval_move(t, nx+diffx, ny+diffy, NULL)" but then they die instead
{ {
parts[i].x += diffx; parts[i].x = remainder_p(parts[i].x-CELL, XRES-CELL*2.5f)+CELL;
parts[i].y += diffy; nx = (int)((float)parts[i].x+0.5f);
nx += diffx; }
ny += diffy; if (!y_ok)
{
parts[i].y = remainder_p(parts[i].y-CELL, YRES-CELL*2.5f)+CELL;
ny = (int)((float)parts[i].y+0.5f);
}
if (!x_ok || !y_ok) //when moving from left to right stickmen might be able to fall through solid things, fix with "eval_move(t, nx+diffx, ny+diffy, NULL)" but then they die instead
{
//adjust stickmen legs //adjust stickmen legs
playerst* stickman = NULL; playerst* stickman = NULL;
int t = parts[i].type; int t = parts[i].type;
@ -4163,9 +4156,12 @@ killed:
if (stickman) if (stickman)
for (int i = 0; i < 16; i+=2) for (int i = 0; i < 16; i+=2)
{ {
stickman->legs[i] += diffx; stickman->legs[i] += (nx-oldnx)+.5f;
stickman->legs[i+1] += diffy; stickman->legs[i+1] += (ny-oldny)+.5f;
stickman->accs[i/2] *= .95f;
} }
parts[i].vy *= .95f;
parts[i].vx *= .95f;
} }
} }
if (ny!=y || nx!=x) if (ny!=y || nx!=x)

View File

@ -215,6 +215,16 @@ public:
{ {
return (x>=0 && y>=0 && x<XRES && y<YRES); return (x>=0 && y>=0 && x<XRES && y<YRES);
} }
// these don't really belong anywhere at the moment, so go here for loop edge mode
static int remainder_p(int x, int y)
{
return (x % y) + (x>=0 ? 0 : y);
}
static float remainder_p(float x, float y)
{
return std::fmod(x, y) + (x>=0 ? 0 : y);
}
}; };
#endif /* SIMULATION_H */ #endif /* SIMULATION_H */