]> git.itanic.dy.fi Git - sdl-planets/commitdiff
main loop: Add support for tracers
authorTimo Kokkonen <kaapeli@itanic.dy.fi>
Fri, 2 Apr 2010 13:19:21 +0000 (16:19 +0300)
committerTimo Kokkonen <kaapeli@itanic.dy.fi>
Fri, 2 Apr 2010 13:19:21 +0000 (16:19 +0300)
Tracers are a fading trail of the planet's movement.

Signed-off-by: Timo Kokkonen <kaapeli@itanic.dy.fi>
main.c

diff --git a/main.c b/main.c
index 02ff5b224b9bc4007624b84fd0d8883aece1b409..f779cdad8f29b992b31702c65948c893f36cebfd 100644 (file)
--- a/main.c
+++ b/main.c
@@ -49,6 +49,7 @@ struct sim_status {
        SDL_Surface *screen;
        struct camera *cam;
        double time_scale;
+       int tracers_enabled;
 };
 
 static int poll_events(struct sim_status *status, double time)
@@ -91,6 +92,9 @@ static int poll_events(struct sim_status *status, double time)
                        case SDLK_a:
                                time_scale_rate = 1 / 1.5;
                                break;
+                       case SDLK_t:
+                               status->tracers_enabled =
+                                       !status->tracers_enabled;
                        default:
                                break;
                        }
@@ -163,6 +167,7 @@ static void loop(SDL_Surface *screen, int num_of_planets, double total_mass,
        status.cam = &camera;
        status.time_scale = 1;
        status.screen = screen;
+       status.tracers_enabled = 0;
 
        planet = malloc(sizeof(*planet));
        init_planet(planet);
@@ -210,7 +215,14 @@ static void loop(SDL_Surface *screen, int num_of_planets, double total_mass,
                last_frame_tick = ticks;
 
                SDL_LockSurface(screen);
-               clear_buf(screen);
+
+               if (status.tracers_enabled &&
+                   !camera.speed.x && !camera.speed.y &&
+                   camera.zoom_rate == 1) {
+                       fade_buf(screen, 10 * true_time);
+               } else {
+                       clear_buf(screen);
+               }
 
                list_for_each_entry(pl1, &planet->list, list) {
                        draw_planet(screen, pl1, &camera);