DEADSOFTWARE

7212a8ac4c13fdd2a070854609203b326094e1cd
[flatwaifu.git] / src / fx.c
1 /*
2 Copyright (C) Prikol Software 1996-1997
3 Copyright (C) Aleksey Volynskov 1996-1997
5 This file is part of the Doom2D:Rembo project.
7 Doom2D:Rembo is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License version 2 as
9 published by the Free Software Foundation.
11 Doom2D:Rembo is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, see <http://www.gnu.org/licenses/> or
18 write to the Free Software Foundation, Inc.,
19 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20 */
22 #include "glob.h"
23 //#include <io.h>
24 #include <stdio.h>
25 #include <stdlib.h>
26 #include <string.h>
27 #include "vga.h"
28 #include "error.h"
29 #include "view.h"
30 #include "fx.h"
31 #include "misc.h"
33 enum{NONE,TFOG,IFOG,BUBL};
35 #pragma pack(1)
36 typedef struct{
37 int x,y,xv,yv;
38 char t,s;
39 }fx_t;
40 #pragma pack()
42 static void *spr[15],*bsnd[2];
43 static char sprd[15];
44 static fx_t fx[MAXFX];
45 static char bubsn;
46 static int last;
48 unsigned char fx_scr1[64000],fx_scr2[64000];
50 #define SINP 256
51 #define SINPM (SINP-1)
52 #define W (SINP/100)
54 static int stdsin[SINP]={
55 #include "fx1sin.dat"
56 };
57 static int sintab[SINP];
59 static unsigned char dmap[32*32];
61 static int isin(int a) {
62 return sintab[a&SINPM];
63 }
65 static void setamp(int a) {
66 int i;
68 for(i=0;i<SINP;++i) sintab[i]=stdsin[i]*a;
69 }
71 void FX_trans1(int t) {
73 int x,y,u,v;
74 static unsigned char k;
75 unsigned p;
77 setamp(t);
78 k=t;
79 t*=W;
80 for(y=0,p=0;y<200;++y)
81 for(x=0;x<320;++x,++p) {
82 if(dmap[(y&31)*32+(x&31)]>=k) {
83 u=x+((isin(y+t))>>16);
84 v=y+((isin(u+t))>>16);
85 if(u<0 || u>=320 || v<0 || v>=200) scra[p]=0;
86 else scra[p]=fx_scr1[v*320+u];
87 }else scra[p]=fx_scr2[p];
88 }
90 }
92 static void init_fx1sin(void) {
93 int j,r,l,rr;
94 unsigned i;
96 memset(dmap,0,32*32);
97 for(i=1,rr=32*32;i<64;++i) {
98 for(l=32*32/64;l;--l,--rr) {
99 r=rand()%rr;
100 for(j=0;r;--r,++j) {
101 for(;dmap[j];++j);
103 for(;dmap[j];++j);
104 dmap[j]=i;
109 void FX_savegame(FILE* h) {
110 int i,n;
112 for(i=n=0;i<MAXFX;++i) if(fx[i].t) ++n;
113 myfwrite(&n,1,4,h);
114 for(i=0;i<MAXFX;++i) if(fx[i].t) myfwrite(&fx[i],1,sizeof(fx_t),h);
117 void FX_loadgame(FILE* h) {
118 int n;
120 myfread(&n,1,4,h);
121 myfread(fx,1,n*sizeof(fx_t),h);
124 void FX_alloc(void) {
125 int i;
127 for(i=0;i<10;++i) spr[i]=Z_getspr("TFOG",i,0,sprd+i);
128 for(;i<15;++i) spr[i]=Z_getspr("IFOG",i-10,0,sprd+i);
129 bsnd[0]=Z_getsnd("BUBL1");
130 bsnd[1]=Z_getsnd("BUBL2");
131 init_fx1sin();
134 void FX_init(void) {
135 int i;
137 for(i=0;i<MAXFX;++i) fx[i].t=0;
138 bubsn=0;
139 last=0;
142 void FX_act(void) {
143 int i;
144 byte b;
146 bubsn=0;
147 for(i=0;i<MAXFX;++i) switch(fx[i].t) {
148 case TFOG:
149 if(++fx[i].s>=20) fx[i].t=0;
150 break;
151 case IFOG:
152 if(++fx[i].s>=10) fx[i].t=0;
153 break;
154 case BUBL:
155 fx[i].yv-=5;
156 fx[i].xv=Z_dec(fx[i].xv,20);
157 fx[i].x+=fx[i].xv;
158 fx[i].y+=fx[i].yv;
159 if((b=fld[fx[i].y>>11][fx[i].x>>11]) < 5 || b>7) fx[i].t=0;
160 break;
164 void FX_draw(void) {
165 int i,s;
167 for(i=0;i<MAXFX;++i) {
168 s=-1;
169 switch(fx[i].t) {
170 case TFOG: s=fx[i].s/2;break;
171 case IFOG: s=fx[i].s/2+10;break;
172 case BUBL:
173 V_dot((fx[i].x>>8)-w_x+WD/2,(fx[i].y>>8)-w_y+HT/2+1+w_o,0xC0+fx[i].s);//V_dot((fx[i].x>>8)-w_x+100,(fx[i].y>>8)-w_y+50+w_o,0xC0+fx[i].s);
174 continue;
176 if(s>=0) Z_drawspr(fx[i].x,fx[i].y,spr[s],sprd[s]);
180 static int findfree(void) {
181 int i;
183 for(i=0;i<MAXFX;++i) if(!fx[i].t) return i;
184 for(i=0;i<MAXFX;++i) if(fx[i].t==IFOG) return i;
185 if(++last>=MAXFX) last=0;
186 return last;
189 void FX_tfog(int x,int y) {
190 int i;
192 i=findfree();
193 fx[i].t=TFOG;fx[i].s=0;
194 fx[i].x=x;fx[i].y=y;
197 void FX_ifog(int x,int y) {
198 int i;
200 i=findfree();
201 fx[i].t=IFOG;fx[i].s=0;
202 fx[i].x=x;fx[i].y=y;
205 void FX_bubble(int x,int y,int xv,int yv,int n) {
206 int i;
208 if(!bubsn) {Z_sound(bsnd[rand()&1],128);bubsn=1;}
209 for(;n>0;--n) {
210 i=findfree();
211 fx[i].t=BUBL;fx[i].s=rand()&3;
212 fx[i].x=(x<<8)+myrand(513)-256;fx[i].y=(y<<8)+myrand(513)-256;
213 fx[i].xv=xv;fx[i].yv=yv-myrand(256)-768;