File: boxes.c

package info (click to toggle)
liquidwar 5.6.2-1
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 15,064 kB
  • ctags: 2,524
  • sloc: ansic: 24,996; xml: 3,897; sh: 3,054; asm: 1,344; makefile: 1,312; php: 486; python: 464; sql: 22
file content (58 lines) | stat: -rw-r--r-- 1,448 bytes parent folder | download | duplicates (7)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
/*
* A bunch of boxes of the same size.
*
* This works best if r/c are large and close to each other.
*
* Copyright (C) 2003, David Redick
* Released under the GNU General Public License (v2)
*/

#include "map.h"


void boxes()
{
     int r, c;
     int startx, starty, endx, endy;
     int pad;

     pad = 1;

     for( r = 0; r < map.num_row; r++ )
     {
          for( c = 0; c < map.num_col; c++ )
          {
               /* 1 out 2 chance to draw box */
               if( rand()%2 == 0 )
               {
                    /*
                    * if box is on the edge of the map i use
                    * the absolute pixel
                    */
                    if( c == 0 )
                         startx = pad+1;
                    else
                         startx = map.sec_width*c+pad;

                    if( r == 0 )
                         starty = pad+1;
                    else
                         starty = map.sec_height*r+pad;

                    if( c == map.num_col-1 )
                         endx = map.width-pad-2;
                    else
                         endx = map.sec_width*(c+1)-pad;

                    if( r == map.num_row-1 )
                         endy = map.height-pad-2;
                    else
                         endy = map.sec_height*(r+1)-pad;

                    rectfill(map.map, startx, starty, endx, endy, 0);
               }
          }
     }

return;
}