DEADSOFTWARE

fully move highter level rendering code in separate file
[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"
30 #include "my.h"
32 enum{NONE,TFOG,IFOG,BUBL};
34 fx_t fx[MAXFX];
36 static void *bsnd[2];
37 static char bubsn;
38 static int last;
40 unsigned char fx_scr1[64000],fx_scr2[64000];
42 #define SINP 256
43 #define SINPM (SINP-1)
44 #define W (SINP/100)
46 static int stdsin[SINP]={
47 #include "fx1sin.dat"
48 };
49 static int sintab[SINP];
51 static unsigned char dmap[32*32];
53 static int isin(int a) {
54 return sintab[a&SINPM];
55 }
57 static void setamp(int a) {
58 int i;
60 for(i=0;i<SINP;++i) sintab[i]=stdsin[i]*a;
61 }
63 void FX_trans1(int t) {
65 int x,y,u,v;
66 static unsigned char k;
67 unsigned p;
69 setamp(t);
70 k=t;
71 t*=W;
72 for(y=0,p=0;y<200;++y)
73 for(x=0;x<320;++x,++p) {
74 if(dmap[(y&31)*32+(x&31)]>=k) {
75 u=x+((isin(y+t))>>16);
76 v=y+((isin(u+t))>>16);
77 if(u<0 || u>=320 || v<0 || v>=200) scra[p]=0;
78 else scra[p]=fx_scr1[v*320+u];
79 }else scra[p]=fx_scr2[p];
80 }
82 }
84 static void init_fx1sin(void) {
85 int j,r,l,rr;
86 unsigned i;
88 memset(dmap,0,32*32);
89 for(i=1,rr=32*32;i<64;++i) {
90 for(l=32*32/64;l;--l,--rr) {
91 r=rand()%rr;
92 for(j=0;r;--r,++j) {
93 for(;dmap[j];++j);
94 }
95 for(;dmap[j];++j);
96 dmap[j]=i;
97 }
98 }
99 }
101 void FX_savegame (FILE *h) {
102 int i, n;
103 for (i = n = 0; i < MAXFX; ++i) {
104 if (fx[i].t) {
105 ++n;
108 myfwrite32(n, h);
109 for (i = 0; i < MAXFX; ++i) {
110 if (fx[i].t) {
111 myfwrite32(fx[i].x, h);
112 myfwrite32(fx[i].y, h);
113 myfwrite32(fx[i].xv, h);
114 myfwrite32(fx[i].yv, h);
115 myfwrite8(fx[i].t, h);
116 myfwrite8(fx[i].s, h);
121 void FX_loadgame (FILE *h) {
122 int i, n;
123 n = myfread32(h);
124 for (i = 0; i < n; i++) {
125 fx[i].x = myfread32(h);
126 fx[i].y = myfread32(h);
127 fx[i].xv = myfread32(h);
128 fx[i].yv = myfread32(h);
129 fx[i].t = myfread8(h);
130 fx[i].s = myfread8(h);
134 void FX_alloc(void) {
135 bsnd[0]=Z_getsnd("BUBL1");
136 bsnd[1]=Z_getsnd("BUBL2");
137 init_fx1sin();
140 void FX_init(void) {
141 int i;
143 for(i=0;i<MAXFX;++i) fx[i].t=0;
144 bubsn=0;
145 last=0;
148 void FX_act(void) {
149 int i;
150 byte b;
152 bubsn=0;
153 for(i=0;i<MAXFX;++i) switch(fx[i].t) {
154 case TFOG:
155 if(++fx[i].s>=20) fx[i].t=0;
156 break;
157 case IFOG:
158 if(++fx[i].s>=10) fx[i].t=0;
159 break;
160 case BUBL:
161 fx[i].yv-=5;
162 fx[i].xv=Z_dec(fx[i].xv,20);
163 fx[i].x+=fx[i].xv;
164 fx[i].y+=fx[i].yv;
165 if((b=fld[fx[i].y>>11][fx[i].x>>11]) < 5 || b>7) fx[i].t=0;
166 break;
170 static int findfree(void) {
171 int i;
173 for(i=0;i<MAXFX;++i) if(!fx[i].t) return i;
174 for(i=0;i<MAXFX;++i) if(fx[i].t==IFOG) return i;
175 if(++last>=MAXFX) last=0;
176 return last;
179 void FX_tfog(int x,int y) {
180 int i;
182 i=findfree();
183 fx[i].t=TFOG;fx[i].s=0;
184 fx[i].x=x;fx[i].y=y;
187 void FX_ifog(int x,int y) {
188 int i;
190 i=findfree();
191 fx[i].t=IFOG;fx[i].s=0;
192 fx[i].x=x;fx[i].y=y;
195 void FX_bubble(int x,int y,int xv,int yv,int n) {
196 int i;
198 if(!bubsn) {Z_sound(bsnd[rand()&1],128);bubsn=1;}
199 for(;n>0;--n) {
200 i=findfree();
201 fx[i].t=BUBL;fx[i].s=rand()&3;
202 fx[i].x=(x<<8)+myrand(513)-256;fx[i].y=(y<<8)+myrand(513)-256;
203 fx[i].xv=xv;fx[i].yv=yv-myrand(256)-768;