7 extern int view_width, view_height;
9 struct level *create_level(int xsz, int ysz)
13 if(!(lvl = malloc(sizeof *lvl))) {
16 if(!(lvl->cells = calloc(xsz * ysz, sizeof *lvl->cells))) {
25 void free_level(struct level *lvl)
32 static void draw_cell(float x, float y, float sz, struct cell *cell)
34 static const float colors[][3] = {{0, 0, 0}, {0.6, 0.6, 0.6}, {0.4, 0.2, 0.1}};
37 glColor3fv(colors[cell->type]);
42 glVertex2f(x + sz, y);
43 glVertex2f(x + sz, y + sz);
44 glVertex2f(x, y + sz);
47 void draw_level(struct level *lvl)
50 float x, y, dx, dy, cellsz;
53 dx = view_width / lvl->width;
54 dy = view_height / lvl->height;
55 cellsz = dx > dy ? dy : dx;
60 for(i=0; i<lvl->height; i++) {
62 for(j=0; j<lvl->width; j++) {
63 draw_cell(x, y, cellsz, cell++);
70 glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
73 for(i=0; i<lvl->height; i++) {
75 for(j=0; j<lvl->width; j++) {
76 draw_cell(x, y, cellsz, 0);
82 glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);