10 static int init(void);
11 static void destroy(void);
12 static int start(void);
13 static void stop(void);
14 static void display(void);
15 static void reshape(int x, int y);
16 static void keyb(int key, int press);
17 static void mouse(int bn, int press, int x, int y);
18 static void motion(int x, int y);
20 struct game_screen scr_lvled = {
28 static struct level *lvl;
30 static float cam_theta, cam_phi = 20, cam_dist = 10;
31 static float cam_pan[3];
38 static void destroy(void)
42 static int start(void)
44 lvl = malloc_nf(sizeof *lvl);
46 if(load_level(lvl, "data/test.lvl") == -1) {
49 cam_pan[0] = -(lvl->xsz / 2.0f) * lvl->scale;
50 cam_pan[2] = -(lvl->ysz / 2.0f) * lvl->scale;
54 static void stop(void)
60 static void display(void)
64 struct level_cell *cell;
65 struct level_rect *rect;
67 glMatrixMode(GL_MODELVIEW);
69 glTranslatef(0, 0, -cam_dist);
70 glRotatef(cam_phi, 1, 0, 0);
71 glRotatef(cam_theta, 0, 1, 0);
72 glTranslatef(cam_pan[0], cam_pan[1], cam_pan[2]);
76 glColor3f(0.4, 0.4, 0.4);
78 rad = lvl->scale * 0.48;
79 for(i=0; i<lvl->ysz; i++) {
80 y = (float)i * lvl->scale;
81 for(j=0; j<lvl->xsz; j++) {
82 x = (float)j * lvl->scale;
84 glVertex3f(x - rad, -1, y - rad);
85 glVertex3f(x + rad, -1, y - rad);
86 glVertex3f(x + rad, -1, y + rad);
87 glVertex3f(x - rad, -1, y + rad);
96 for(i=0; i<darr_size(lvl->rects); i++) {
97 float x = (rect->x - 0.55) * lvl->scale;
98 float y = (rect->y - 0.55) * lvl->scale;
99 float w = (rect->w + 0.1) * lvl->scale;
100 float h = (rect->h + 0.1) * lvl->scale;
102 glBegin(GL_LINE_LOOP);
103 glColor3ubv(rect->dbgcol);
105 glVertex3f(x + w, 0, y);
106 glVertex3f(x + w, 0, y + h);
107 glVertex3f(x, 0, y + h);
114 static void reshape(int x, int y)
118 static void keyb(int key, int press)
128 printf("saving level\n");
129 save_level(lvl, "data/test.lvl");
137 static void mouse(int bn, int press, int x, int y)
141 static void motion(int x, int y)
143 int dx = x - mouse_x;
144 int dy = y - mouse_y;
146 if(!(dx | dy)) return;
149 cam_theta += dx * 0.5;
151 if(cam_phi < -90) cam_phi = -90;
152 if(cam_phi > 90) cam_phi = 90;
155 float up[3], right[3];
156 float theta = cam_theta * M_PI / 180.0f;
157 float phi = cam_phi * M_PI / 180.0f;
159 up[0] = -sin(theta) * sin(phi);
161 up[2] = cos(theta) * sin(phi);
162 right[0] = cos(theta);
164 right[2] = sin(theta);
166 cam_pan[0] += (right[0] * dx + up[0] * dy) * 0.01;
167 cam_pan[1] += up[1] * dy * 0.01;
168 cam_pan[2] += (right[2] * dx + up[2] * dy) * 0.01;
171 cam_dist += dy * 0.1;
172 if(cam_dist < 0) cam_dist = 0;