DEADSOFTWARE

4c9eb0c7d944d4758dab3520e9087ebd568d7172
[flatwaifu.git] / src / render.c
1 #include "glob.h"
2 #include "render.h"
3 #include "view.h"
4 #include "player.h"
5 #include "switch.h"
6 #include "vga.h"
7 #include "menu.h"
8 #include "misc.h"
10 extern byte clrmap[256*12]; // main.c
11 extern void *scrnh[3]; // game.c
12 extern int g_trans; // game.c
13 extern byte transdraw; // game.c
14 extern void *horiz; // view.c
15 extern int sky_type; // view.c
16 extern int lt_time, lt_type, lt_side, lt_ypos, lt_force; // game.c
17 extern void *ltn[2][2]; // game.c
19 /* --- menu --- */
21 /*
22 static int GM_draw (void) {
23 int i, j, k, y;
24 ++gm_tm;
25 V_setrect(0, SCRW, 0, SCRH);
26 if (!mnu && !gm_redraw) {
27 return 0;
28 }
29 gm_redraw = 0;
30 if (!mnu) {
31 return 1;
32 }
33 if (mnu->type == MENU) {
34 y = (200 - mnu -> n * 16 - 20) / 2;
35 Z_gotoxy(mnu->x, y - 10); Z_printbf(mnu->ttl);
36 for (i = 0; i < mnu->n; ++i) {
37 if (mnu->t[i] == LOAD || mnu->t[i] == SAVE) {
38 j = y + i * 16 + 29;
39 V_spr(mnu->x, j, mslotl);
40 for (k = 8; k < 184; k += 8) {
41 V_spr(mnu->x + k, j, mslotm);
42 }
43 V_spr(mnu->x+184,j,mslotr);
44 Z_gotoxy(mnu->x+4,j-8);
45 if (input && i == save_mnu.cur) {
46 Z_printsf("%s_", ibuf);
47 } else {
48 Z_printsf("%s", savname[i]);
49 }
50 } else {
51 Z_gotoxy(mnu->x + (mnu->t[i] >= SVOLM ? (mnu->t[i] >= PL1CM ? 50 : 152) : 0), y + i * 16 + 20);
52 Z_printbf(mnu->m[i]);
53 }
54 if (mnu->t[i] == MUSIC) {
55 Z_printbf(" '%.8s'",g_music);
56 } else if(mnu->t[i] == INTERP) {
57 Z_printbf("%s", fullscreen ? "ON" : "OFF");
58 } else if(mnu->t[i] >= PL1CM) {
59 V_manspr(mnu->x + (mnu->t[i] == PL1CM ? 15 : 35), y + i * 16 + 20 + 14, PL_getspr(*panimp, 0), pcolortab[(mnu->t[i] == PL1CM) ? p1color : p2color]);
60 } else if(mnu->t[i]>=SVOLM) {
61 j = y + i * 16 + 20'
62 V_spr(mnu->x, j, mbarl);
63 for (k = 8; k < 144; k += 8) {
64 V_spr(mnu->x + k, j, mbarm);
65 }
66 V_spr(mnu->x + 144, j, mbarr);
67 switch(mnu->t[i]) {
68 case SVOLM: k = snd_vol; break;
69 case MVOLM: k = mus_vol; break;
70 case GAMMAM: k = gammaa << 5; break;
71 }
72 V_spr(mnu->x+8+k,j,mbaro);
73 }
74 }
75 V_spr(mnu->x - 25, y + mnu->cur * 16 + 20 - 8, msklh[(gm_tm / 6) & 1]);
76 } else {
77 Z_gotoxy((320 - strlen(mnu->ttl) * 7) / 2, 90); Z_printsf(mnu->ttl);
78 Z_gotoxy(136, 100); Z_printsf("(Y/N)");
79 }
80 return 1;
81 }
82 */
84 /* --- view --- */
86 static void W_adjust (void) {
87 int MAXX = FLDW * CELW - WD / 2;
88 int MAXY = FLDH * CELH - HT / 2;
89 if (w_x < WD / 2) w_x = WD / 2;
90 if (w_y < HT / 2) w_y = HT / 2;
91 if (w_x > MAXX) w_x = MAXX;
92 if (w_y > MAXY) w_y = MAXY;
93 }
95 static void W_draw(void) {
96 W_adjust();
97 V_setrect(0, WD, w_o + 1, HT);
98 if (w_horiz) {
99 vgaimg *img = (vgaimg*)horiz;
100 int x = 0;
101 int d = 0;
102 do {
103 int y = w_o;
104 d &= ~2;
105 do {
106 V_rotspr(x, y, img, d);
107 y += img->h;
108 d ^= 2;
109 } while (y < HT + w_o);
110 x += img->w;
111 d ^= 1;
112 } while (x < WD);
113 if (sky_type == 2) {
114 if (lt_time < 0) {
115 if (!lt_side) {
116 V_spr(0, w_o + lt_ypos, ltn[lt_type][lt_time < -5 ? 0 : 1]);
117 } else {
118 V_spr2(WD - 1, w_o + lt_ypos, ltn[lt_type][lt_time < -5 ? 0 : 1]);
122 } else {
123 V_clr(0, WD, w_o + 1, HT, 0x97);
125 Z_drawfld((byte*)fldb, 1);
126 DOT_draw();
127 IT_draw();
128 PL_draw(&pl1);
129 if(_2pl) {
130 PL_draw(&pl2);
132 MN_draw();
133 WP_draw();
134 SMK_draw();
135 FX_draw();
136 Z_drawfld((byte*)fldf, 0);
137 if(sky_type == 2) {
138 if(lt_time == -4 || lt_time == -2) {
139 V_remap_rect(0, WD, w_o + 1, HT, clrmap + 256 * 11);
144 /* --- game --- */
146 #define PL_FLASH 90
148 static void drawview (player_t *p) {
149 if (p->looky < -SCRH / 4) {
150 p->looky = -SCRH / 4;
151 } else if (p->looky > SCRH / 4) {
152 p->looky = SCRH / 4;
154 w_x = p->o.x;
155 w_y = p->o.y - 12 + p->looky;
156 W_draw();
157 PL_drawst(p);
160 static int get_pu_st (int t) {
161 if (t >= PL_FLASH) {
162 return 1;
163 } else if((t / 9) & 1) {
164 return 0;
165 } else {
166 return 1;
170 static void pl_info (player_t *p, int y) {
171 dword t = p->kills * 10920 / g_time;
172 Z_gotoxy(25, y); Z_printbf("KILLS");
173 Z_gotoxy(25, y + 15); Z_printbf("KPM");
174 Z_gotoxy(25, y + 30); Z_printbf("SECRETS %u / %u", p->secrets, sw_secrets);
175 Z_gotoxy(255, y); Z_printbf("%u", p->kills);
176 Z_gotoxy(255, y + 15); Z_printbf("%u.%u", t / 10, t % 10);
179 void G_draw (void) {
180 int h;
181 word hr, mn, sc;
182 if (g_trans && !transdraw) {
183 return;
185 switch (g_st) {
186 case GS_ENDANIM:
187 case GS_END2ANIM:
188 case GS_DARKEN:
189 case GS_BVIDEO:
190 case GS_EVIDEO:
191 case GS_END3ANIM:
192 return;
193 case GS_TITLE:
194 V_center(1);
195 V_pic(0, 0, scrnh[0]);
196 V_center(0);
197 break;
198 case GS_ENDSCR:
199 V_center(1);
200 V_clr(0, SCRW, 0, SCRH, 0);
201 V_pic(0, 0, scrnh[2]);
202 V_center(0);
203 break;
204 case GS_INTER:
205 V_center(1);
206 V_clr(0, SCRW, 0, SCRH, 0);
207 V_pic(0, 0, scrnh[1]);
208 Z_gotoxy(60, 20);
209 Z_printbf("LEVEL COMPLETE");
210 Z_calc_time(g_time, &hr, &mn, &sc);
211 Z_gotoxy(115, 40);
212 Z_printbf("TIME %u:%02u:%02u", hr, mn, sc);
213 h = 60;
214 if (_2pl) {
215 Z_gotoxy(80, h);
216 Z_printbf("PLAYER ONE");
217 Z_gotoxy(80, h + 70);
218 Z_printbf("PLAYER TWO");
219 h += SCRH / 10;
221 pl_info(&pl1, h);
222 if (_2pl) {
223 pl_info(&pl2, h + 70);
225 V_center(0);
226 break;
228 V_center(1);
229 if (g_st != GS_GAME) {
230 if (g_trans) {
231 return;
233 GM_draw();
234 V_copytoscr(0, SCRW, 0, SCRH);
235 return;
237 V_center(0);
238 if (_2pl) {
239 w_o = 0;
240 WD = SCRW - 120;
241 HT = SCRH / 2 - 2;
242 drawview(&pl1);
243 w_o = SCRH / 2;
244 WD = SCRW - 120;
245 HT = SCRH / 2 - 2;
246 drawview(&pl2);
247 } else{
248 w_o = 0;
249 WD = SCRW - 120;
250 HT = SCRH - 2;
251 drawview(&pl1);
253 if (g_trans) {
254 return;
256 V_center(1);
257 if (GM_draw()) {
258 pl1.drawst = 0xFF;
259 pl2.drawst = 0xFF;
260 V_copytoscr(0,SCRW,0,SCRH);
261 return;
263 V_center(0);
264 if (pl1.invl) {
265 h = get_pu_st(pl1.invl) * 6;
266 } else if (pl1.pain < 15) {
267 h = 0;
268 } else if (pl1.pain < 35) {
269 h = 1;
270 } else if (pl1.pain < 55) {
271 h = 2;
272 } else if (pl1.pain < 75) {
273 h=3;
274 } else if (pl1.pain < 95) {
275 h=4;
276 } else {
277 h = 5;
279 if (h != 0) {
280 V_maptoscr(0, SCRW - 120, 1, _2pl ? SCRH / 2 - 2 : SCRH - 2, clrmap + h * 256);
281 } else {
282 V_copytoscr(0, SCRW - 120, 1, _2pl ? SCRH / 2 - 2 : SCRH - 2);
284 if (pl1.drawst) {
285 V_copytoscr(SCRW - 120, 120, 0, _2pl ? SCRH / 2 : SCRH);
287 pl1.drawst = 0xFF;
288 if (_2pl) {
289 if (pl2.invl) {
290 h = get_pu_st(pl2.invl) * 6;
291 } else if (pl2.pain < 15) {
292 h = 0;
293 } else if (pl2.pain < 35) {
294 h = 1;
295 } else if (pl2.pain < 55) {
296 h = 2;
297 } else if (pl2.pain < 75) {
298 h = 3;
299 } else if (pl2.pain < 95) {
300 h = 4;
301 } else {
302 h = 5;
304 if (h) {
305 V_maptoscr(0, SCRW - 120, SCRH / 2 + 1, SCRH / 2 - 2, clrmap + h * 256);
306 } else {
307 V_copytoscr(0, SCRW - 120, SCRH / 2 + 1, SCRH / 2 - 2);
309 if (pl2.drawst) {
310 V_copytoscr(SCRW - 120, 120, SCRH / 2, SCRH / 2);
312 pl2.drawst = 0xFF;