- case 0: size = 1 + (random()%(grid_h - hole_y - 1)); h = size; w = 1; break;
- case 1: size = 1 + (random()%hole_x); w = size; h = 1; break;
- case 2: size = 1 + (random()%hole_y); h = size; w = 1; break;
- case 3: size = 1 + (random()%(grid_w - hole_x - 1)); w = size; h = 1; break;
- default: abort ();
- }
+ if (st->draw_last == -1) st->draw_last = random () % 2;
+
+ /* alternate between horizontal and vertical slides */
+ /* note that draw_dir specifies the direction the _hole_ moves, not the tiles */
+ if (st->draw_last == VERTICAL) {
+ if (((st->grid_w > 1) ? st->draw_rnd = random () % (st->grid_w - 1) : 0)
+ < st->hole_x) {
+ st->draw_dx = -1; st->draw_dir = LEFT; st->hole_x -= st->draw_rnd;
+ } else {
+ st->draw_dx = 1; st->draw_dir = RIGHT; st->draw_rnd -= st->hole_x;
+ }
+ st->draw_dy = 0; st->draw_w = st->draw_size = st->draw_rnd + 1; st->draw_h = 1;
+ st->draw_last = HORIZONTAL;
+ } else {
+ if (((st->grid_h > 1) ? st->draw_rnd = random () % (st->grid_h - 1) : 0)
+ < st->hole_y) {
+ st->draw_dy = -1; st->draw_dir = UP; st->hole_y -= st->draw_rnd;
+ } else {
+ st->draw_dy = 1; st->draw_dir = DOWN; st->draw_rnd -= st->hole_y;
+ }
+ st->draw_dx = 0; st->draw_h = st->draw_size = st->draw_rnd + 1; st->draw_w = 1;
+ st->draw_last = VERTICAL;
+ }
+
+ st->draw_ix = st->draw_x = st->xoff + (st->hole_x + st->draw_dx) * st->grid_size;
+ st->draw_iy = st->draw_y = st->yoff + (st->hole_y + st->draw_dy) * st->grid_size;
+ st->draw_inc = st->pix_inc;