http://ftp.x.org/contrib/applications/xscreensaver-3.23.tar.gz
[xscreensaver] / hacks / penetrate.c
index 3976444a54b91d493be75360c6c991f64a3bd630..ebe6858d4dc614cb3a3711fe50802b10b71d14b6 100644 (file)
@@ -92,6 +92,7 @@ typedef struct {
   int startx, starty;
   int endx, endy;
   int oldx, oldy;
+  int oldx2, oldy2;
   float velx, vely, fposx, fposy;
   float lenMul;
   XColor color;
@@ -321,8 +322,10 @@ static int fire(int xlim, int ylim,
   m->target = misnum;
   m->x = m->startx;
   m->y = m->starty;
-  m->oldx = m->x;
-  m->oldy = m->y;
+  m->oldx = -1;
+  m->oldy = -1;
+  m->oldx2 = -1;
+  m->oldy2 = -1;
   m->fposx = m->x;
   m->fposy = m->y;
   dx = (m->endx - m->x);
@@ -542,11 +545,25 @@ static void LoopMissiles(Display *dpy, Window window, Colormap cmap, int xlim, i
         }
 
         if (m->alive == 0) {
+               int old_x, old_y;
+               float my_pos;
                /* we just died */
                Explode(m->x, m->y, kBoomRad + max, m->color, 0);
-               XSetLineAttributes(dpy, erase_gc, 5, 0,0,0);
-               XDrawLine(dpy, window, erase_gc,
-                                        m->startx, m->starty, m->x, m->y);             
+               XSetLineAttributes(dpy, erase_gc, 4, 0,0,0);
+               /* In a perfect world, we could simply erase a line from
+                  (m->startx, m->starty) to (m->x, m->y). This is not a
+                  perfect world. */
+               old_x = m->startx;
+               old_y = m->starty;
+               my_pos = kMissileSpeed;
+               while (my_pos <= m->pos) {
+                       m->x = m->startx + ((float) (m->endx - m->startx)) * my_pos;
+                       m->y = m->starty + ((float) (m->endy - m->starty)) * my_pos;
+                       XDrawLine(dpy, window, erase_gc, old_x, old_y, m->x, m->y);
+                       old_x = m->x;
+                       old_y = m->y;
+                       my_pos += kMissileSpeed;
+               }
         }
   }
 }
@@ -559,6 +576,13 @@ static void LoopLasers(Display *dpy, Window window, Colormap cmap, int xlim, int
         Laser *m = &laser[i];
         if (!m->alive)
                continue;
+
+        if (m->oldx != -1) {
+                XSetLineAttributes(dpy, erase_gc, 2, 0,0,0);
+                XDrawLine(dpy, window, erase_gc,
+                                 m->oldx2, m->oldy2, m->oldx, m->oldy);
+        }
+
         m->fposx += m->velx;
         m->fposy += m->vely;
         m->x = m->fposx;
@@ -567,9 +591,6 @@ static void LoopLasers(Display *dpy, Window window, Colormap cmap, int xlim, int
         x = m->fposx + (-m->velx * m->lenMul);
         y = m->fposy + (-m->vely * m->lenMul);
 
-        XSetLineAttributes(dpy, erase_gc, 4, 0,0,0);
-        XDrawLine(dpy, window, erase_gc,
-                                 x, y, m->oldx, m->oldy);              
         m->oldx = x;
         m->oldy = y;
 
@@ -577,6 +598,11 @@ static void LoopLasers(Display *dpy, Window window, Colormap cmap, int xlim, int
     XSetForeground (dpy, draw_gc, m->color.pixel);
         XDrawLine(dpy, window, draw_gc,
                                  m->x, m->y, x, y);
+
+        m->oldx2 = m->x;
+        m->oldy2 = m->y;
+        m->oldx = x;
+        m->oldy = y;
         
         if (m->y < m->endy) {
                m->alive = 0;
@@ -621,7 +647,7 @@ static void LoopBooms(Display *dpy, Window window, Colormap cmap, int xlim, int
         if (!m->alive)
                continue;
         
-        if (loop & 1)
+        if (loop & 1) {
                if (m->outgoing) {
                  m->rad++;
                  if (m->rad >= m->max)
@@ -637,6 +663,7 @@ static void LoopBooms(Display *dpy, Window window, Colormap cmap, int xlim, int
                  if (m->rad <= 0)
                         m->alive = 0;
                }
+        }
   }
 }