DEADSOFTWARE

menu: remove data field from menu_t
[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 "view.h"
27 #include "fx.h"
28 #include "misc.h"
29 #include "my.h"
31 enum{NONE,TFOG,IFOG,BUBL};
33 fx_t fx[MAXFX];
35 static void *bsnd[2];
36 static char bubsn;
37 static int last;
39 //unsigned char fx_scr1[64000],fx_scr2[64000];
41 #define SINP 256
42 #define SINPM (SINP-1)
43 #define W (SINP/100)
45 static int stdsin[SINP]={
46 #include "fx1sin.dat"
47 };
48 static int sintab[SINP];
50 static unsigned char dmap[32*32];
52 static int isin(int a) {
53 return sintab[a&SINPM];
54 }
56 static void setamp(int a) {
57 int i;
59 for(i=0;i<SINP;++i) sintab[i]=stdsin[i]*a;
60 }
62 /*
63 void FX_trans1 (int t) {
64 int x,y,u,v;
65 static unsigned char k;
66 unsigned p;
68 setamp(t);
69 k=t;
70 t*=W;
71 for(y=0,p=0;y<200;++y)
72 for(x=0;x<320;++x,++p) {
73 if(dmap[(y&31)*32+(x&31)]>=k) {
74 u=x+((isin(y+t))>>16);
75 v=y+((isin(u+t))>>16);
76 if(u<0 || u>=320 || v<0 || v>=200) scra[p]=0;
77 else scra[p]=fx_scr1[v*320+u];
78 }else scra[p]=fx_scr2[p];
79 }
80 }
81 */
83 static void init_fx1sin(void) {
84 int j,r,l,rr;
85 unsigned i;
87 memset(dmap,0,32*32);
88 for(i=1,rr=32*32;i<64;++i) {
89 for(l=32*32/64;l;--l,--rr) {
90 r=rand()%rr;
91 for(j=0;r;--r,++j) {
92 for(;dmap[j];++j);
93 }
94 for(;dmap[j];++j);
95 dmap[j]=i;
96 }
97 }
98 }
100 void FX_alloc (void) {
101 bsnd[0]=Z_getsnd("BUBL1");
102 bsnd[1]=Z_getsnd("BUBL2");
103 init_fx1sin();
106 void FX_init (void) {
107 int i;
109 for(i=0;i<MAXFX;++i) fx[i].t=0;
110 bubsn=0;
111 last=0;
114 void FX_act (void) {
115 int i;
116 byte b;
118 bubsn=0;
119 for(i=0;i<MAXFX;++i) switch(fx[i].t) {
120 case TFOG:
121 if(++fx[i].s>=20) fx[i].t=0;
122 break;
123 case IFOG:
124 if(++fx[i].s>=10) fx[i].t=0;
125 break;
126 case BUBL:
127 fx[i].yv-=5;
128 fx[i].xv=Z_dec(fx[i].xv,20);
129 fx[i].x+=fx[i].xv;
130 fx[i].y+=fx[i].yv;
131 if((b=fld[fx[i].y>>11][fx[i].x>>11]) < 5 || b>7) fx[i].t=0;
132 break;
136 static int findfree (void) {
137 int i;
139 for(i=0;i<MAXFX;++i) if(!fx[i].t) return i;
140 for(i=0;i<MAXFX;++i) if(fx[i].t==IFOG) return i;
141 if(++last>=MAXFX) last=0;
142 return last;
145 void FX_tfog (int x, int y) {
146 int i;
148 i=findfree();
149 fx[i].t=TFOG;fx[i].s=0;
150 fx[i].x=x;fx[i].y=y;
153 void FX_ifog (int x, int y) {
154 int i;
156 i=findfree();
157 fx[i].t=IFOG;fx[i].s=0;
158 fx[i].x=x;fx[i].y=y;
161 void FX_bubble (int x, int y, int xv, int yv, int n) {
162 int i;
164 if(!bubsn) {Z_sound(bsnd[rand()&1],128);bubsn=1;}
165 for(;n>0;--n) {
166 i=findfree();
167 fx[i].t=BUBL;fx[i].s=rand()&3;
168 fx[i].x=(x<<8)+myrand(513)-256;fx[i].y=(y<<8)+myrand(513)-256;
169 fx[i].xv=xv;fx[i].yv=yv-myrand(256)-768;