DEADSOFTWARE

ddb39a28ab069f83ae44af07623cf9e62baea3ce
[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 "files.h"
27 #include "memory.h"
28 #include "vga.h"
29 #include "error.h"
30 #include "keyb.h"
31 #include "sound.h"
32 #include "view.h"
33 #include "dots.h"
34 #include "misc.h"
36 #define MAXINI 50
37 #define MAXSR 20
39 #define BL_XV 4
40 #define BL_YV 4
41 #define BL_MINT 10
42 #define BL_MAXT 14
44 #define SP_V 2
45 #define SP_MINT 5
46 #define SP_MAXT 7
48 extern byte z_dot;
50 #pragma pack(1)
51 typedef struct{
52 obj_t o;
53 byte c,t;
54 }dot_t;
55 #pragma pack()
57 typedef struct{
58 int xv,yv;
59 byte c,t;
60 }init_t;
62 static dot_t dot[MAXDOT];
63 static init_t bl_ini[MAXINI],sp_ini[MAXINI];
64 static int bl_r,sp_r,sr_r,sxr[MAXSR],syr[MAXSR];
65 static int ldot;
67 void DOT_savegame(FILE* h) {
68 int i,n;
70 for(i=n=0;i<MAXDOT;++i) if(dot[i].t) ++n;
71 myfwrite(&n,1,4,h);
72 for(i=0;i<MAXDOT;++i) if(dot[i].t) myfwrite(&dot[i],1,sizeof(dot_t),h);
73 }
75 void DOT_loadgame(FILE* h) {
76 int n;
78 myfread(&n,1,4,h);
79 myfread(dot,1,n*sizeof(dot_t),h);
80 }
82 void DOT_init(void) {
83 int i;
85 for(i=0;i<MAXDOT;++i) {dot[i].t=0;dot[i].o.r=0;dot[i].o.h=1;}
86 ldot=0;
87 }
89 static void incldot(void) {
90 if(++ldot>=MAXDOT) ldot=0;
91 }
93 void DOT_alloc(void) {
94 int i;
96 for(i=0;i<MAXINI;++i) {
97 bl_ini[i].xv=myrand(BL_XV*2+1)-BL_XV;
98 bl_ini[i].yv=-myrand(BL_YV);
99 bl_ini[i].c=0xB0+myrand(16);
100 bl_ini[i].t=myrand(BL_MAXT-BL_MINT+1)+BL_MINT;
101 sp_ini[i].xv=myrand(SP_V*2+1)-SP_V;
102 sp_ini[i].yv=myrand(SP_V*2+1)-SP_V;
103 sp_ini[i].c=0xA0+myrand(6);
104 sp_ini[i].t=myrand(SP_MAXT-SP_MINT+1)+SP_MINT;
106 for(i=0;i<MAXSR;++i) {
107 sxr[i]=myrand(2*2+1)-2;
108 syr[i]=myrand(2*2+1)-2;
110 bl_r=sp_r=sr_r=0;
113 void DOT_act(void) {
114 int i,s,xv,yv;
116 z_dot=1;
117 for(i=0;i<MAXDOT;++i) if(dot[i].t) {
118 xv=dot[i].o.xv+dot[i].o.vx;
119 yv=dot[i].o.yv+dot[i].o.vy;
120 s=Z_moveobj(&dot[i].o);
121 if(dot[i].t<254) --dot[i].t;
122 if(s&(Z_HITWATER|Z_FALLOUT)) {dot[i].t=0;continue;}
123 if(s&Z_HITLAND) {
124 if(!dot[i].o.xv) {
125 if(yv>2) {
126 if(!xv) dot[i].o.vx=(rand()&1)?-1:1;
127 else dot[i].o.vx=Z_sign(dot[i].o.vx);
128 if(rand()%yv==0) dot[i].o.vx*=2;
129 dot[i].o.yv=yv-2;
132 dot[i].o.xv=0;
133 if(dot[i].t>4 && dot[i].t!=255) dot[i].t=4;
135 if(s&Z_HITWALL) {
136 dot[i].o.vx=Z_sign(xv)*2;
137 dot[i].o.yv=Z_sign(dot[i].o.yv);
138 if(dot[i].o.yv>=0) if(rand()&3) --dot[i].o.yv;
139 if(dot[i].o.yv>=0) if(rand()&1) --dot[i].o.yv;
141 if(s&Z_HITCEIL) {dot[i].o.xv=0;dot[i].o.yv=(myrand(100))?-2:0;}
143 z_dot=0;
146 void DOT_draw(void) {
147 int i;
149 for(i=0;i<MAXDOT;++i)
150 if(dot[i].t) V_dot(dot[i].o.x-w_x+WD/2,dot[i].o.y-w_y+HT/2+1+w_o,dot[i].c);//if(dot[i].t) V_dot(dot[i].o.x-w_x+100,dot[i].o.y-w_y+50+w_o,dot[i].c);
153 void DOT_add(int x,int y,char xv,char yv,byte c,byte t) {
154 int i;
156 if(!Z_canfit(x,y,0,1)) return;
157 i=ldot;
158 dot[i].o.x=x;dot[i].o.y=y;
159 dot[i].o.xv=xv;dot[i].o.yv=yv;
160 dot[i].c=c;dot[i].t=t;
161 dot[i].o.vx=dot[i].o.vy=0;
162 incldot();
165 void DOT_blood(int x,int y,int xv,int yv,int n) {
166 int i,k,dx,dy;
168 for(k=n;k;--k) {
169 dx=x+sxr[sr_r];dy=y+syr[sr_r];
170 if(!Z_canfit(x,y,0,1)) continue;
171 i=ldot;
172 dot[i].o.x=dx;dot[i].o.y=dy;
173 dot[i].o.xv=bl_ini[bl_r].xv+Z_dec(xv,3);
174 dot[i].o.yv=bl_ini[bl_r].yv+Z_dec(yv,3)-3;
175 dot[i].c=bl_ini[bl_r].c;
176 dot[i].t=255;
177 dot[i].o.vx=dot[i].o.vy=0;
178 if(++bl_r>=MAXINI) bl_r=0;
179 if(++sr_r>=MAXSR) sr_r=0;
180 incldot();
184 void DOT_spark(int x,int y,int xv,int yv,int n) {
185 int i,k,dx,dy;
187 for(k=n;k;--k) {
188 dx=x+sxr[sr_r];dy=y+syr[sr_r];
189 if(!Z_canfit(x,y,0,1)) continue;
190 i=ldot;
191 dot[i].o.x=dx;dot[i].o.y=dy;
192 dot[i].o.xv=sp_ini[sp_r].xv-xv/4;
193 dot[i].o.yv=sp_ini[sp_r].yv-yv/4;
194 dot[i].c=sp_ini[sp_r].c;
195 dot[i].t=sp_ini[sp_r].t;
196 dot[i].o.vx=dot[i].o.vy=0;
197 if(++sp_r>=MAXINI) sp_r=0;
198 if(++sr_r>=MAXSR) sr_r=0;
199 incldot();
203 void DOT_water(int x,int y,int xv,int yv,int n,int c) {
204 int i,k,dx,dy;
205 static byte ct[3]={0xC0,0x70,0xB0};
207 if(c<0 || c>=3) return;
208 c=ct[c];
209 for(k=n;k;--k) {
210 dx=x+sxr[sr_r];dy=y+syr[sr_r];
211 if(!Z_canfit(x,y,0,1)) continue;
212 i=ldot;
213 dot[i].o.x=dx;dot[i].o.y=dy;
214 dot[i].o.xv=bl_ini[bl_r].xv-Z_dec(xv,3);
215 dot[i].o.yv=bl_ini[bl_r].yv-abs(yv);
216 dot[i].c=bl_ini[bl_r].c-0xB0+c;
217 dot[i].t=254;
218 dot[i].o.vx=dot[i].o.vy=0;
219 if(++bl_r>=MAXINI) bl_r=0;
220 if(++sr_r>=MAXSR) sr_r=0;
221 incldot();