DEADSOFTWARE

Editing source tree for configuring with CMake
[flatwaifu.git] / src / fx.c
1 /*
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
21 */
23 #include "glob.h"
24 //#include <io.h>
25 #include <stdio.h>
26 #include <stdlib.h>
27 #include <string.h>
28 #include "vga.h"
29 #include "error.h"
30 #include "view.h"
31 #include "fx.h"
32 #include "misc.h"
34 enum{NONE,TFOG,IFOG,BUBL};
36 #pragma pack(1)
37 typedef struct{
38 int x,y,xv,yv;
39 char t,s;
40 }fx_t;
41 #pragma pack()
43 static void *spr[15],*bsnd[2];
44 static char sprd[15];
45 static fx_t fx[MAXFX];
46 static char bubsn;
47 static int last;
49 unsigned char fx_scr1[64000],fx_scr2[64000];
51 #define SINP 256
52 #define SINPM (SINP-1)
53 #define W (SINP/100)
55 static int stdsin[SINP]={
56 #include "fx1sin.dat"
57 };
58 static int sintab[SINP];
60 static unsigned char dmap[32*32];
62 static int isin(int a) {
63 return sintab[a&SINPM];
64 }
66 static void setamp(int a) {
67 int i;
69 for(i=0;i<SINP;++i) sintab[i]=stdsin[i]*a;
70 }
72 void FX_trans1(int t) {
74 int x,y,u,v;
75 static unsigned char k;
76 unsigned p;
78 setamp(t);
79 k=t;
80 t*=W;
81 for(y=0,p=0;y<200;++y)
82 for(x=0;x<320;++x,++p) {
83 if(dmap[(y&31)*32+(x&31)]>=k) {
84 u=x+((isin(y+t))>>16);
85 v=y+((isin(u+t))>>16);
86 if(u<0 || u>=320 || v<0 || v>=200) scra[p]=0;
87 else scra[p]=fx_scr1[v*320+u];
88 }else scra[p]=fx_scr2[p];
89 }
91 }
93 static void init_fx1sin(void) {
94 int j,r,l,rr;
95 unsigned i;
97 memset(dmap,0,32*32);
98 for(i=1,rr=32*32;i<64;++i) {
99 for(l=32*32/64;l;--l,--rr) {
100 r=rand()%rr;
101 for(j=0;r;--r,++j) {
102 for(;dmap[j];++j);
104 for(;dmap[j];++j);
105 dmap[j]=i;
110 void FX_savegame(FILE* h) {
111 int i,n;
113 for(i=n=0;i<MAXFX;++i) if(fx[i].t) ++n;
114 myfwrite(&n,1,4,h);
115 for(i=0;i<MAXFX;++i) if(fx[i].t) myfwrite(&fx[i],1,sizeof(fx_t),h);
118 void FX_loadgame(FILE* h) {
119 int n;
121 myfread(&n,1,4,h);
122 myfread(fx,1,n*sizeof(fx_t),h);
125 void FX_alloc(void) {
126 int i;
128 for(i=0;i<10;++i) spr[i]=Z_getspr("TFOG",i,0,sprd+i);
129 for(;i<15;++i) spr[i]=Z_getspr("IFOG",i-10,0,sprd+i);
130 bsnd[0]=Z_getsnd("BUBL1");
131 bsnd[1]=Z_getsnd("BUBL2");
132 init_fx1sin();
135 void FX_init(void) {
136 int i;
138 for(i=0;i<MAXFX;++i) fx[i].t=0;
139 bubsn=0;
140 last=0;
143 void FX_act(void) {
144 int i;
145 byte b;
147 bubsn=0;
148 for(i=0;i<MAXFX;++i) switch(fx[i].t) {
149 case TFOG:
150 if(++fx[i].s>=20) fx[i].t=0;
151 break;
152 case IFOG:
153 if(++fx[i].s>=10) fx[i].t=0;
154 break;
155 case BUBL:
156 fx[i].yv-=5;
157 fx[i].xv=Z_dec(fx[i].xv,20);
158 fx[i].x+=fx[i].xv;
159 fx[i].y+=fx[i].yv;
160 if((b=fld[fx[i].y>>11][fx[i].x>>11]) < 5 || b>7) fx[i].t=0;
161 break;
165 void FX_draw(void) {
166 int i,s;
168 for(i=0;i<MAXFX;++i) {
169 s=-1;
170 switch(fx[i].t) {
171 case TFOG: s=fx[i].s/2;break;
172 case IFOG: s=fx[i].s/2+10;break;
173 case BUBL:
174 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);
175 continue;
177 if(s>=0) Z_drawspr(fx[i].x,fx[i].y,spr[s],sprd[s]);
181 static int findfree(void) {
182 int i;
184 for(i=0;i<MAXFX;++i) if(!fx[i].t) return i;
185 for(i=0;i<MAXFX;++i) if(fx[i].t==IFOG) return i;
186 if(++last>=MAXFX) last=0;
187 return last;
190 void FX_tfog(int x,int y) {
191 int i;
193 i=findfree();
194 fx[i].t=TFOG;fx[i].s=0;
195 fx[i].x=x;fx[i].y=y;
198 void FX_ifog(int x,int y) {
199 int i;
201 i=findfree();
202 fx[i].t=IFOG;fx[i].s=0;
203 fx[i].x=x;fx[i].y=y;
206 void FX_bubble(int x,int y,int xv,int yv,int n) {
207 int i;
209 if(!bubsn) {Z_sound(bsnd[rand()&1],128);bubsn=1;}
210 for(;n>0;--n) {
211 i=findfree();
212 fx[i].t=BUBL;fx[i].s=rand()&3;
213 fx[i].x=(x<<8)+myrand(513)-256;fx[i].y=(y<<8)+myrand(513)-256;
214 fx[i].xv=xv;fx[i].yv=yv-myrand(256)-768;