DEADSOFTWARE

8a38050cf9bfc7789bae981efaa0e6791fe09298
[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 <stdio.h>
24 #include <stdlib.h>
25 #include <string.h>
26 #include "vga.h"
27 #include "view.h"
28 #include "fx.h"
29 #include "misc.h"
31 enum{NONE,TFOG,IFOG,BUBL};
33 #pragma pack(1)
34 typedef struct{
35 int x,y,xv,yv;
36 char t,s;
37 }fx_t;
38 #pragma pack()
40 static void *spr[15],*bsnd[2];
41 static char sprd[15];
42 static fx_t fx[MAXFX];
43 static char bubsn;
44 static int last;
46 unsigned char fx_scr1[64000],fx_scr2[64000];
48 #define SINP 256
49 #define SINPM (SINP-1)
50 #define W (SINP/100)
52 static int stdsin[SINP]={
53 #include "fx1sin.dat"
54 };
55 static int sintab[SINP];
57 static unsigned char dmap[32*32];
59 static int isin(int a) {
60 return sintab[a&SINPM];
61 }
63 static void setamp(int a) {
64 int i;
66 for(i=0;i<SINP;++i) sintab[i]=stdsin[i]*a;
67 }
69 void FX_trans1(int t) {
71 int x,y,u,v;
72 static unsigned char k;
73 unsigned p;
75 setamp(t);
76 k=t;
77 t*=W;
78 for(y=0,p=0;y<200;++y)
79 for(x=0;x<320;++x,++p) {
80 if(dmap[(y&31)*32+(x&31)]>=k) {
81 u=x+((isin(y+t))>>16);
82 v=y+((isin(u+t))>>16);
83 if(u<0 || u>=320 || v<0 || v>=200) scra[p]=0;
84 else scra[p]=fx_scr1[v*320+u];
85 }else scra[p]=fx_scr2[p];
86 }
88 }
90 static void init_fx1sin(void) {
91 int j,r,l,rr;
92 unsigned i;
94 memset(dmap,0,32*32);
95 for(i=1,rr=32*32;i<64;++i) {
96 for(l=32*32/64;l;--l,--rr) {
97 r=rand()%rr;
98 for(j=0;r;--r,++j) {
99 for(;dmap[j];++j);
101 for(;dmap[j];++j);
102 dmap[j]=i;
107 void FX_savegame(FILE* h) {
108 int i,n;
110 for(i=n=0;i<MAXFX;++i) if(fx[i].t) ++n;
111 myfwrite(&n,1,4,h);
112 for(i=0;i<MAXFX;++i) if(fx[i].t) myfwrite(&fx[i],1,sizeof(fx_t),h);
115 void FX_loadgame(FILE* h) {
116 int n;
118 myfread(&n,1,4,h);
119 myfread(fx,1,n*sizeof(fx_t),h);
122 void FX_alloc(void) {
123 int i;
125 for(i=0;i<10;++i) spr[i]=Z_getspr("TFOG",i,0,sprd+i);
126 for(;i<15;++i) spr[i]=Z_getspr("IFOG",i-10,0,sprd+i);
127 bsnd[0]=Z_getsnd("BUBL1");
128 bsnd[1]=Z_getsnd("BUBL2");
129 init_fx1sin();
132 void FX_init(void) {
133 int i;
135 for(i=0;i<MAXFX;++i) fx[i].t=0;
136 bubsn=0;
137 last=0;
140 void FX_act(void) {
141 int i;
142 byte b;
144 bubsn=0;
145 for(i=0;i<MAXFX;++i) switch(fx[i].t) {
146 case TFOG:
147 if(++fx[i].s>=20) fx[i].t=0;
148 break;
149 case IFOG:
150 if(++fx[i].s>=10) fx[i].t=0;
151 break;
152 case BUBL:
153 fx[i].yv-=5;
154 fx[i].xv=Z_dec(fx[i].xv,20);
155 fx[i].x+=fx[i].xv;
156 fx[i].y+=fx[i].yv;
157 if((b=fld[fx[i].y>>11][fx[i].x>>11]) < 5 || b>7) fx[i].t=0;
158 break;
162 void FX_draw(void) {
163 int i,s;
165 for(i=0;i<MAXFX;++i) {
166 s=-1;
167 switch(fx[i].t) {
168 case TFOG: s=fx[i].s/2;break;
169 case IFOG: s=fx[i].s/2+10;break;
170 case BUBL:
171 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);
172 continue;
174 if(s>=0) Z_drawspr(fx[i].x,fx[i].y,spr[s],sprd[s]);
178 static int findfree(void) {
179 int i;
181 for(i=0;i<MAXFX;++i) if(!fx[i].t) return i;
182 for(i=0;i<MAXFX;++i) if(fx[i].t==IFOG) return i;
183 if(++last>=MAXFX) last=0;
184 return last;
187 void FX_tfog(int x,int y) {
188 int i;
190 i=findfree();
191 fx[i].t=TFOG;fx[i].s=0;
192 fx[i].x=x;fx[i].y=y;
195 void FX_ifog(int x,int y) {
196 int i;
198 i=findfree();
199 fx[i].t=IFOG;fx[i].s=0;
200 fx[i].x=x;fx[i].y=y;
203 void FX_bubble(int x,int y,int xv,int yv,int n) {
204 int i;
206 if(!bubsn) {Z_sound(bsnd[rand()&1],128);bubsn=1;}
207 for(;n>0;--n) {
208 i=findfree();
209 fx[i].t=BUBL;fx[i].s=rand()&3;
210 fx[i].x=(x<<8)+myrand(513)-256;fx[i].y=(y<<8)+myrand(513)-256;
211 fx[i].xv=xv;fx[i].yv=yv-myrand(256)-768;