DEADSOFTWARE

cd89a2bc7c40cdc2ae869b6c143e79c2e5b71879
[flatwaifu.git] / src / dots.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 <stdio.h>
25 #include <stdlib.h>
26 #include "view.h"
27 #include "dots.h"
28 #include "misc.h"
29 #include "my.h"
31 #define MAXINI 50
32 #define MAXSR 20
34 #define BL_XV 4
35 #define BL_YV 4
36 #define BL_MINT 10
37 #define BL_MAXT 14
39 #define SP_V 2
40 #define SP_MINT 5
41 #define SP_MAXT 7
43 typedef struct{
44 int xv,yv;
45 byte c,t;
46 }init_t;
48 dot_t dot[MAXDOT];
50 static init_t bl_ini[MAXINI],sp_ini[MAXINI];
51 static int bl_r,sp_r,sr_r,sxr[MAXSR],syr[MAXSR];
52 static int ldot;
54 void DOT_init(void) {
55 int i;
57 for(i=0;i<MAXDOT;++i) {dot[i].t=0;dot[i].o.r=0;dot[i].o.h=1;}
58 ldot=0;
59 }
61 static void incldot(void) {
62 if(++ldot>=MAXDOT) ldot=0;
63 }
65 void DOT_alloc(void) {
66 int i;
68 for(i=0;i<MAXINI;++i) {
69 bl_ini[i].xv=myrand(BL_XV*2+1)-BL_XV;
70 bl_ini[i].yv=-myrand(BL_YV);
71 bl_ini[i].c=0xB0+myrand(16);
72 bl_ini[i].t=myrand(BL_MAXT-BL_MINT+1)+BL_MINT;
73 sp_ini[i].xv=myrand(SP_V*2+1)-SP_V;
74 sp_ini[i].yv=myrand(SP_V*2+1)-SP_V;
75 sp_ini[i].c=0xA0+myrand(6);
76 sp_ini[i].t=myrand(SP_MAXT-SP_MINT+1)+SP_MINT;
77 }
78 for(i=0;i<MAXSR;++i) {
79 sxr[i]=myrand(2*2+1)-2;
80 syr[i]=myrand(2*2+1)-2;
81 }
82 bl_r=sp_r=sr_r=0;
83 }
85 void DOT_act(void) {
86 int i,s,xv,yv;
88 z_dot=1;
89 for(i=0;i<MAXDOT;++i) if(dot[i].t) {
90 xv=dot[i].o.xv+dot[i].o.vx;
91 yv=dot[i].o.yv+dot[i].o.vy;
92 s=Z_moveobj(&dot[i].o);
93 if(dot[i].t<254) --dot[i].t;
94 if(s&(Z_HITWATER|Z_FALLOUT)) {dot[i].t=0;continue;}
95 if(s&Z_HITLAND) {
96 if(!dot[i].o.xv) {
97 if(yv>2) {
98 if(!xv) dot[i].o.vx=(rand()&1)?-1:1;
99 else dot[i].o.vx=Z_sign(dot[i].o.vx);
100 if(rand()%yv==0) dot[i].o.vx*=2;
101 dot[i].o.yv=yv-2;
104 dot[i].o.xv=0;
105 if(dot[i].t>4 && dot[i].t!=255) dot[i].t=4;
107 if(s&Z_HITWALL) {
108 dot[i].o.vx=Z_sign(xv)*2;
109 dot[i].o.yv=Z_sign(dot[i].o.yv);
110 if(dot[i].o.yv>=0) if(rand()&3) --dot[i].o.yv;
111 if(dot[i].o.yv>=0) if(rand()&1) --dot[i].o.yv;
113 if(s&Z_HITCEIL) {dot[i].o.xv=0;dot[i].o.yv=(myrand(100))?-2:0;}
115 z_dot=0;
118 void DOT_add(int x,int y,char xv,char yv,byte c,byte t) {
119 int i;
121 if(!Z_canfit(x,y,0,1)) return;
122 i=ldot;
123 dot[i].o.x=x;dot[i].o.y=y;
124 dot[i].o.xv=xv;dot[i].o.yv=yv;
125 dot[i].c=c;dot[i].t=t;
126 dot[i].o.vx=dot[i].o.vy=0;
127 incldot();
130 void DOT_blood(int x,int y,int xv,int yv,int n) {
131 int i,k,dx,dy;
133 for(k=n;k;--k) {
134 dx=x+sxr[sr_r];dy=y+syr[sr_r];
135 if(!Z_canfit(x,y,0,1)) continue;
136 i=ldot;
137 dot[i].o.x=dx;dot[i].o.y=dy;
138 dot[i].o.xv=bl_ini[bl_r].xv+Z_dec(xv,3);
139 dot[i].o.yv=bl_ini[bl_r].yv+Z_dec(yv,3)-3;
140 dot[i].c=bl_ini[bl_r].c;
141 dot[i].t=255;
142 dot[i].o.vx=dot[i].o.vy=0;
143 if(++bl_r>=MAXINI) bl_r=0;
144 if(++sr_r>=MAXSR) sr_r=0;
145 incldot();
149 void DOT_spark(int x,int y,int xv,int yv,int n) {
150 int i,k,dx,dy;
152 for(k=n;k;--k) {
153 dx=x+sxr[sr_r];dy=y+syr[sr_r];
154 if(!Z_canfit(x,y,0,1)) continue;
155 i=ldot;
156 dot[i].o.x=dx;dot[i].o.y=dy;
157 dot[i].o.xv=sp_ini[sp_r].xv-xv/4;
158 dot[i].o.yv=sp_ini[sp_r].yv-yv/4;
159 dot[i].c=sp_ini[sp_r].c;
160 dot[i].t=sp_ini[sp_r].t;
161 dot[i].o.vx=dot[i].o.vy=0;
162 if(++sp_r>=MAXINI) sp_r=0;
163 if(++sr_r>=MAXSR) sr_r=0;
164 incldot();
168 void DOT_water(int x,int y,int xv,int yv,int n,int c) {
169 int i,k,dx,dy;
170 static byte ct[3]={0xC0,0x70,0xB0};
172 if(c<0 || c>=3) return;
173 c=ct[c];
174 for(k=n;k;--k) {
175 dx=x+sxr[sr_r];dy=y+syr[sr_r];
176 if(!Z_canfit(x,y,0,1)) continue;
177 i=ldot;
178 dot[i].o.x=dx;dot[i].o.y=dy;
179 dot[i].o.xv=bl_ini[bl_r].xv-Z_dec(xv,3);
180 dot[i].o.yv=bl_ini[bl_r].yv-abs(yv);
181 dot[i].c=bl_ini[bl_r].c-0xB0+c;
182 dot[i].t=254;
183 dot[i].o.vx=dot[i].o.vy=0;
184 if(++bl_r>=MAXINI) bl_r=0;
185 if(++sr_r>=MAXSR) sr_r=0;
186 incldot();