2 Copyright (C) Prikol Software 1996-1997
3 Copyright (C) Aleksey Volynskov 1996-1997
4 Copyright (C) <ARembo@gmail.com> 2011
6 This file is part of the Doom2D:Rembo project.
8 Doom2D:Rembo is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License version 2 as
10 published by the Free Software Foundation.
12 Doom2D:Rembo is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, see <http://www.gnu.org/licenses/> or
19 write to the Free Software Foundation, Inc.,
20 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
51 #include <SDL_keysym.h>
64 char g_music
[8] = "MENU";
71 static void *telepsnd
;
78 static void *ltnsnd
[2];
83 static void set_trans(int st
) {
85 case GS_ENDANIM
: case GS_END2ANIM
: case GS_DARKEN
:
86 case GS_BVIDEO
: case GS_EVIDEO
: case GS_END3ANIM
:
90 case GS_ENDANIM
: case GS_END2ANIM
: case GS_DARKEN
:
91 case GS_BVIDEO
: case GS_EVIDEO
: case GS_END3ANIM
:
97 void G_savegame (FILE* h
) {
100 myfwrite8(g_exit
, h
);
102 myfwrite32(g_time
, h
);
103 myfwrite32(dm_pl1p
, h
);
104 myfwrite32(dm_pl2p
, h
);
105 myfwrite32(dm_pnum
, h
);
107 while (i
< dm_pnum
) {
108 myfwrite32(dm_pos
[i
].x
, h
);
109 myfwrite32(dm_pos
[i
].y
, h
);
110 myfwrite8(dm_pos
[i
].d
, h
);
114 myfwrite(g_music
, 8, 1, h
);
117 void G_loadgame (FILE* h
) {
120 g_exit
= myfread8(h
);
122 g_time
= myfread32(h
);
123 dm_pl1p
= myfread32(h
);
124 dm_pl2p
= myfread32(h
);
125 dm_pnum
= myfread32(h
);
127 while (i
< dm_pnum
) {
128 dm_pos
[i
].x
= myfread32(h
);
129 dm_pos
[i
].y
= myfread32(h
);
130 dm_pos
[i
].d
= myfread8(h
);
134 myfread(g_music
, 8, 1, h
);
138 int G_load (FILE *h
) {
141 myfread(g_music
, 8, 1, h
);
151 void load_game (int n
) {
157 if(_2pl
) pl2
.drawst
=0xFF;
159 BM_clear(BM_PLR1
|BM_PLR2
|BM_MONSTER
);
160 BM_mark(&pl1
.o
,BM_PLR1
);
161 if(_2pl
) BM_mark(&pl2
.o
,BM_PLR2
);
163 S_startmusic(music_time
);
166 void G_start (void) {
170 sprintf(s
,"MAP%02u",(word
)g_map
);
174 if(_2pl
) pl2
.drawst
=0xFF;
176 itm_rtime
=(g_dm
)?1092:0;
177 p_immortal
=0;PL_JUMP
=10;
181 if(!_2pl
) pl1
.lives
=3;
183 BM_clear(BM_PLR1
|BM_PLR2
|BM_MONSTER
);
184 BM_mark(&pl1
.o
,BM_PLR1
);
185 if(_2pl
) BM_mark(&pl2
.o
,BM_PLR2
);
187 S_startmusic(music_time
);
190 #define GGAS_TOTAL (MN__LAST-MN_DEMON+16+10)
196 logo("G_init: настройка ресурсов игры ");
197 logo_gas(5,GGAS_TOTAL
);
198 telepsnd
=Z_getsnd("TELEPT");
199 ltnsnd
[0]=Z_getsnd("THUND1");
200 ltnsnd
[1]=Z_getsnd("THUND2");
210 logo_gas(GGAS_TOTAL
,GGAS_TOTAL
);
218 static int G_beg_video (void) {
221 case 3: return A8_start("FALL");
222 case 4: return A8_start("KORIDOR");
223 case 5: return A8_start("SKULL");
224 case 6: return A8_start("TORCHES");
225 case 7: return A8_start("CACO");
226 case 8: return A8_start("DARTS");
227 case 9: return A8_start("FISH");
228 case 10: return A8_start("TRAP");
229 case 11: return A8_start("JAIL");
230 case 12: return A8_start("MMON1");
231 case 13: return A8_start("TOWER");
232 case 14: return A8_start("SAPOG");
233 case 15: return A8_start("SWITCH");
234 case 16: return A8_start("ACCEL");
235 case 17: return A8_start("MEAT");
236 case 18: return A8_start("LEGION");
237 case 19: return A8_start("CLOUDS");
244 static int G_end_video (void) {
247 case 1: return A8_start("TRUBA");
248 case 10: return A8_start("GOTCHA");
259 V_setscr(NULL);memcpy(fx_scr1,scra,64000);
261 transdraw=1;G_draw();transdraw=0;
264 FX_trans1(g_transt*2);
265 V_copytoscr(0,320,0,200);
275 if(g_st
==GS_BVIDEO
|| g_st
==GS_EVIDEO
) {
276 if(!A8_nextframe() || lastkey
==SDLK_ESCAPE
) {
277 if(lastkey
==SDLK_ESCAPE
) lastkey
=0;
279 if(g_st
==GS_BVIDEO
) G_start();
282 // V_copytoscr(0,SCRW,0,SCRH);//V_copytoscr(0,320,0,200);
284 }else if(g_st
==GS_ENDANIM
|| g_st
==GS_END2ANIM
|| g_st
==GS_END3ANIM
) {
285 if(!A8_nextframe()) {
287 case GS_ENDANIM
: g_st
=GS_DARKEN
;break;
288 case GS_END2ANIM
: g_st
=GS_END3ANIM
;A8_start("KONEC");break;
289 case GS_END3ANIM
: g_st
=GS_ENDSCR
;lastkey
=0;break;
293 // V_copytoscr(0,SCRW,0,SCRH);//V_copytoscr(0,320,0,200);
295 }else if(g_st
==GS_DARKEN
) {
296 g_st
=GS_END2ANIM
;A8_start("CREDITS");
305 case GS_TITLE
: case GS_ENDSCR
:
310 if(keys
[0x39] || keys
[0x1C] || keys
[0x9C]) {
314 if(keys
[SDLK_SPACE
] || keys
[SDLK_RETURN
] || keys
[SDLK_KP_ENTER
])//if(keys[0x39] || keys[0x1C] || keys[0x9C])
315 if(!G_beg_video()) G_start(); else {
316 g_st
=GS_BVIDEO
;F_freemus();
324 if(lt_time
>LT_DELAY
|| lt_force
) {
325 if(!(rand()&31) || lt_force
) {
331 Z_sound(ltnsnd
[rand()&1],128);
336 pl1
.hit
=0;pl1
.hito
=-3;
337 if(_2pl
) {pl2
.hit
=0;pl2
.hito
=-3;}
343 if(pcnt
) {PL_act(&pl1
);PL_act(&pl2
);}
344 else {PL_act(&pl2
);PL_act(&pl1
);}
348 if(fld_need_remap
) BM_remapfld();
349 BM_clear(BM_PLR1
|BM_PLR2
|BM_MONSTER
);
350 BM_mark(&pl1
.o
,BM_PLR1
);
351 if(_2pl
) BM_mark(&pl2
.o
,BM_PLR2
);
358 PL_damage(&pl1
);PL_damage(&pl2
);
359 if(!(pl1
.f
&PLF_PNSND
) && pl1
.pain
) PL_cry(&pl1
);
360 if(!(pl2
.f
&PLF_PNSND
) && pl2
.pain
) PL_cry(&pl2
);
361 if((pl1
.pain
-=5) < 0) {pl1
.pain
=0;pl1
.f
&=(0xFFFF-PLF_PNSND
);}
362 if((pl2
.pain
-=5) < 0) {pl2
.pain
=0;pl2
.f
&=(0xFFFF-PLF_PNSND
);}
365 if(!(pl1
.f
&PLF_PNSND
) && pl1
.pain
) PL_cry(&pl1
);
366 if((pl1
.pain
-=5) < 0) {pl1
.pain
=0;pl1
.f
&=(0xFFFF-PLF_PNSND
);}
378 case 19: g_st
=GS_ENDANIM
;A8_start("FINAL");break;
379 case 31: case 32: g_map
=16;set_trans(GS_INTER
);break;
380 default: ++g_map
;set_trans(GS_INTER
);break;
384 F_loadmus("INTERMUS");
385 }else {F_loadmus("\x8a\x8e\x8d\x85\x96\x0");if(mus_vol
>0) {S_volumemusic(128);} }
387 }else if(g_exit
==2) {
389 case 31: g_map
=32;set_trans(GS_INTER
);break;
390 case 32: g_map
=16;set_trans(GS_INTER
);break;
391 default: g_map
=31;set_trans(GS_INTER
);break;
394 F_loadmus("INTERMUS");
399 if(g_dm
&& g_time
>10920) {set_trans(GS_INTER
);}
403 void G_respawn_player (player_t
*p
) {
407 if(p
==&pl1
) i
=dm_pl1p
^=1;
409 p
->o
.x
=dm_pos
[i
].x
;p
->o
.y
=dm_pos
[i
].y
;p
->d
=dm_pos
[i
].d
;
410 FX_tfog(dm_pos
[i
].x
,dm_pos
[i
].y
);Z_sound(telepsnd
,128);
413 do{i
=myrand(dm_pnum
);}while(i
==dm_pl1p
|| i
==dm_pl2p
);
414 p
->o
.x
=dm_pos
[i
].x
;p
->o
.y
=dm_pos
[i
].y
;p
->d
=dm_pos
[i
].d
;
415 if(p
==&pl1
) dm_pl1p
=i
; else dm_pl2p
=i
;
416 FX_tfog(dm_pos
[i
].x
,dm_pos
[i
].y
);Z_sound(telepsnd
,128);