diff options
Diffstat (limited to 'xd.c')
-rw-r--r-- | xd.c | 86 |
1 files changed, 52 insertions, 34 deletions
@@ -3919,6 +3919,7 @@ static void GravityDemo(void) int mass; double tx[GRAV_TRAIL]; double ty[GRAV_TRAIL]; + int alive; } GravObj; static GravObj gravobj[GRAV_OBJ]; @@ -3936,6 +3937,7 @@ static void GravityDemo(void) gravobj[f].dx = 0; gravobj[f].dy = 0; gravobj[f].mass = 1000; + gravobj[f].alive = TRUE; } else { @@ -3954,6 +3956,7 @@ static void GravityDemo(void) gravobj[f].dy = costab[a] * 0.1; gravobj[f].mass = 1; + gravobj[f].alive = TRUE; } gravobj[f].col = GetCol(RND2(255,128), @@ -3980,63 +3983,78 @@ static void GravityDemo(void) for(f = 1; f < GRAV_OBJ; f++) { - for(r = 0; r < GRAV_OBJ; r++) + if (gravobj[f].alive) { - if (f != r) + for(r = 0; r < GRAV_OBJ; r++) { - double d; - double g; - double dx; - double dy; + if (f != r && gravobj[r].alive) + { + double d; + double g; + double dx; + double dy; - dx = gravobj[f].x - gravobj[r].x; - dy = gravobj[f].y - gravobj[r].y; + dx = gravobj[f].x - gravobj[r].x; + dy = gravobj[f].y - gravobj[r].y; - d = sqrt(dx*dx + dy*dy); + d = sqrt(dx*dx + dy*dy); + + if (d < (gravobj[r].mass / GRAV_SIZE)) + { + gravobj[f].alive = FALSE; + gravobj[r].mass += gravobj[f].mass; + } - g = 1.0 / d*d; + g = 1.0 / d*d; - g /= 10000.0; - g *= gravobj[f].mass; + g /= 10000.0; + g *= gravobj[f].mass; - dx /= d; - dy /= d; + dx /= d; + dy /= d; - dx *= g; - dy *= g; + dx *= g; + dy *= g; - gravobj[f].dx -= dx; - gravobj[f].dy -= dy; + gravobj[f].dx -= dx; + gravobj[f].dy -= dy; + } } } } for(f = 0; f < GRAV_OBJ; f++) { - gravobj[f].x += gravobj[f].dx; - gravobj[f].y += gravobj[f].dy; - - for(r = GRAV_TRAIL - 1; r > 0; r--) + if (gravobj[f].alive) { - gravobj[f].tx[r] = gravobj[f].tx[r-1]; - gravobj[f].ty[r] = gravobj[f].ty[r-1]; - } + gravobj[f].x += gravobj[f].dx; + gravobj[f].y += gravobj[f].dy; - gravobj[f].tx[0] = gravobj[f].x; - gravobj[f].ty[0] = gravobj[f].y; + for(r = GRAV_TRAIL - 1; r > 0; r--) + { + gravobj[f].tx[r] = gravobj[f].tx[r-1]; + gravobj[f].ty[r] = gravobj[f].ty[r-1]; + } - for(r = 0; r < GRAV_TRAIL - 1; r++) - { - Line(gravobj[f].tx[r], gravobj[f].ty[r], - gravobj[f].tx[r+1], gravobj[f].ty[r+1], - gravobj[f].col); + gravobj[f].tx[0] = gravobj[f].x; + gravobj[f].ty[0] = gravobj[f].y; + + for(r = 0; r < GRAV_TRAIL - 1; r++) + { + Line(gravobj[f].tx[r], gravobj[f].ty[r], + gravobj[f].tx[r+1], gravobj[f].ty[r+1], + gravobj[f].col); + } } } for(f = 0; f < GRAV_OBJ; f++) { - FCircle(gravobj[f].x, gravobj[f].y, - gravobj[f].mass/GRAV_SIZE, gravobj[f].col); + if (gravobj[f].alive) + { + FCircle(gravobj[f].x, gravobj[f].y, + gravobj[f].mass/GRAV_SIZE, gravobj[f].col); + } } } |