DEADSOFTWARE

b9ca8ec7104913b821402546238821ead00226a9
[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_savegame (FILE *h) {
55 int i, n;
56 for (i = n = 0; i < MAXDOT; ++i) {
57 if (dot[i].t) {
58 ++n;
59 }
60 }
61 myfwrite32(n, h);
62 for (i = 0; i < MAXDOT; ++i) {
63 if (dot[i].t) {
64 myfwrite32(dot[i].o.x, h);
65 myfwrite32(dot[i].o.y, h);
66 myfwrite32(dot[i].o.xv, h);
67 myfwrite32(dot[i].o.yv, h);
68 myfwrite32(dot[i].o.vx, h);
69 myfwrite32(dot[i].o.vy, h);
70 myfwrite32(dot[i].o.r, h);
71 myfwrite32(dot[i].o.h, h);
72 myfwrite8(dot[i].c, h);
73 myfwrite8(dot[i].t, h);
74 }
75 }
76 }
78 void DOT_loadgame (FILE *h) {
79 int i, n;
80 n = myfread32(h);
81 for (i = 0; i < n; i++) {
82 dot[i].o.x = myfread32(h);
83 dot[i].o.y = myfread32(h);
84 dot[i].o.xv = myfread32(h);
85 dot[i].o.yv = myfread32(h);
86 dot[i].o.vx = myfread32(h);
87 dot[i].o.vy = myfread32(h);
88 dot[i].o.r = myfread32(h);
89 dot[i].o.h = myfread32(h);
90 dot[i].c = myfread8(h);
91 dot[i].t = myfread8(h);
92 }
93 }
95 void DOT_init(void) {
96 int i;
98 for(i=0;i<MAXDOT;++i) {dot[i].t=0;dot[i].o.r=0;dot[i].o.h=1;}
99 ldot=0;
102 static void incldot(void) {
103 if(++ldot>=MAXDOT) ldot=0;
106 void DOT_alloc(void) {
107 int i;
109 for(i=0;i<MAXINI;++i) {
110 bl_ini[i].xv=myrand(BL_XV*2+1)-BL_XV;
111 bl_ini[i].yv=-myrand(BL_YV);
112 bl_ini[i].c=0xB0+myrand(16);
113 bl_ini[i].t=myrand(BL_MAXT-BL_MINT+1)+BL_MINT;
114 sp_ini[i].xv=myrand(SP_V*2+1)-SP_V;
115 sp_ini[i].yv=myrand(SP_V*2+1)-SP_V;
116 sp_ini[i].c=0xA0+myrand(6);
117 sp_ini[i].t=myrand(SP_MAXT-SP_MINT+1)+SP_MINT;
119 for(i=0;i<MAXSR;++i) {
120 sxr[i]=myrand(2*2+1)-2;
121 syr[i]=myrand(2*2+1)-2;
123 bl_r=sp_r=sr_r=0;
126 void DOT_act(void) {
127 int i,s,xv,yv;
129 z_dot=1;
130 for(i=0;i<MAXDOT;++i) if(dot[i].t) {
131 xv=dot[i].o.xv+dot[i].o.vx;
132 yv=dot[i].o.yv+dot[i].o.vy;
133 s=Z_moveobj(&dot[i].o);
134 if(dot[i].t<254) --dot[i].t;
135 if(s&(Z_HITWATER|Z_FALLOUT)) {dot[i].t=0;continue;}
136 if(s&Z_HITLAND) {
137 if(!dot[i].o.xv) {
138 if(yv>2) {
139 if(!xv) dot[i].o.vx=(rand()&1)?-1:1;
140 else dot[i].o.vx=Z_sign(dot[i].o.vx);
141 if(rand()%yv==0) dot[i].o.vx*=2;
142 dot[i].o.yv=yv-2;
145 dot[i].o.xv=0;
146 if(dot[i].t>4 && dot[i].t!=255) dot[i].t=4;
148 if(s&Z_HITWALL) {
149 dot[i].o.vx=Z_sign(xv)*2;
150 dot[i].o.yv=Z_sign(dot[i].o.yv);
151 if(dot[i].o.yv>=0) if(rand()&3) --dot[i].o.yv;
152 if(dot[i].o.yv>=0) if(rand()&1) --dot[i].o.yv;
154 if(s&Z_HITCEIL) {dot[i].o.xv=0;dot[i].o.yv=(myrand(100))?-2:0;}
156 z_dot=0;
159 void DOT_add(int x,int y,char xv,char yv,byte c,byte t) {
160 int i;
162 if(!Z_canfit(x,y,0,1)) return;
163 i=ldot;
164 dot[i].o.x=x;dot[i].o.y=y;
165 dot[i].o.xv=xv;dot[i].o.yv=yv;
166 dot[i].c=c;dot[i].t=t;
167 dot[i].o.vx=dot[i].o.vy=0;
168 incldot();
171 void DOT_blood(int x,int y,int xv,int yv,int n) {
172 int i,k,dx,dy;
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+Z_dec(yv,3)-3;
181 dot[i].c=bl_ini[bl_r].c;
182 dot[i].t=255;
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();
190 void DOT_spark(int x,int y,int xv,int yv,int n) {
191 int i,k,dx,dy;
193 for(k=n;k;--k) {
194 dx=x+sxr[sr_r];dy=y+syr[sr_r];
195 if(!Z_canfit(x,y,0,1)) continue;
196 i=ldot;
197 dot[i].o.x=dx;dot[i].o.y=dy;
198 dot[i].o.xv=sp_ini[sp_r].xv-xv/4;
199 dot[i].o.yv=sp_ini[sp_r].yv-yv/4;
200 dot[i].c=sp_ini[sp_r].c;
201 dot[i].t=sp_ini[sp_r].t;
202 dot[i].o.vx=dot[i].o.vy=0;
203 if(++sp_r>=MAXINI) sp_r=0;
204 if(++sr_r>=MAXSR) sr_r=0;
205 incldot();
209 void DOT_water(int x,int y,int xv,int yv,int n,int c) {
210 int i,k,dx,dy;
211 static byte ct[3]={0xC0,0x70,0xB0};
213 if(c<0 || c>=3) return;
214 c=ct[c];
215 for(k=n;k;--k) {
216 dx=x+sxr[sr_r];dy=y+syr[sr_r];
217 if(!Z_canfit(x,y,0,1)) continue;
218 i=ldot;
219 dot[i].o.x=dx;dot[i].o.y=dy;
220 dot[i].o.xv=bl_ini[bl_r].xv-Z_dec(xv,3);
221 dot[i].o.yv=bl_ini[bl_r].yv-abs(yv);
222 dot[i].c=bl_ini[bl_r].c-0xB0+c;
223 dot[i].t=254;
224 dot[i].o.vx=dot[i].o.vy=0;
225 if(++bl_r>=MAXINI) bl_r=0;
226 if(++sr_r>=MAXSR) sr_r=0;
227 incldot();