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
57 static dot_t dot
[MAXDOT
];
58 static init_t bl_ini
[MAXINI
],sp_ini
[MAXINI
];
59 static int bl_r
,sp_r
,sr_r
,sxr
[MAXSR
],syr
[MAXSR
];
62 void DOT_savegame (FILE *h
) {
64 for (i
= n
= 0; i
< MAXDOT
; ++i
) {
70 for (i
= 0; i
< MAXDOT
; ++i
) {
72 myfwrite32(dot
[i
].o
.x
, h
);
73 myfwrite32(dot
[i
].o
.y
, h
);
74 myfwrite32(dot
[i
].o
.xv
, h
);
75 myfwrite32(dot
[i
].o
.yv
, h
);
76 myfwrite32(dot
[i
].o
.vx
, h
);
77 myfwrite32(dot
[i
].o
.vy
, h
);
78 myfwrite32(dot
[i
].o
.r
, h
);
79 myfwrite32(dot
[i
].o
.h
, h
);
80 myfwrite8(dot
[i
].c
, h
);
81 myfwrite8(dot
[i
].t
, h
);
86 void DOT_loadgame (FILE *h
) {
89 for (i
= 0; i
< n
; i
++) {
90 dot
[i
].o
.x
= myfread32(h
);
91 dot
[i
].o
.y
= myfread32(h
);
92 dot
[i
].o
.xv
= myfread32(h
);
93 dot
[i
].o
.yv
= myfread32(h
);
94 dot
[i
].o
.vx
= myfread32(h
);
95 dot
[i
].o
.vy
= myfread32(h
);
96 dot
[i
].o
.r
= myfread32(h
);
97 dot
[i
].o
.h
= myfread32(h
);
98 dot
[i
].c
= myfread8(h
);
99 dot
[i
].t
= myfread8(h
);
103 void DOT_init(void) {
106 for(i
=0;i
<MAXDOT
;++i
) {dot
[i
].t
=0;dot
[i
].o
.r
=0;dot
[i
].o
.h
=1;}
110 static void incldot(void) {
111 if(++ldot
>=MAXDOT
) ldot
=0;
114 void DOT_alloc(void) {
117 for(i
=0;i
<MAXINI
;++i
) {
118 bl_ini
[i
].xv
=myrand(BL_XV
*2+1)-BL_XV
;
119 bl_ini
[i
].yv
=-myrand(BL_YV
);
120 bl_ini
[i
].c
=0xB0+myrand(16);
121 bl_ini
[i
].t
=myrand(BL_MAXT
-BL_MINT
+1)+BL_MINT
;
122 sp_ini
[i
].xv
=myrand(SP_V
*2+1)-SP_V
;
123 sp_ini
[i
].yv
=myrand(SP_V
*2+1)-SP_V
;
124 sp_ini
[i
].c
=0xA0+myrand(6);
125 sp_ini
[i
].t
=myrand(SP_MAXT
-SP_MINT
+1)+SP_MINT
;
127 for(i
=0;i
<MAXSR
;++i
) {
128 sxr
[i
]=myrand(2*2+1)-2;
129 syr
[i
]=myrand(2*2+1)-2;
138 for(i
=0;i
<MAXDOT
;++i
) if(dot
[i
].t
) {
139 xv
=dot
[i
].o
.xv
+dot
[i
].o
.vx
;
140 yv
=dot
[i
].o
.yv
+dot
[i
].o
.vy
;
141 s
=Z_moveobj(&dot
[i
].o
);
142 if(dot
[i
].t
<254) --dot
[i
].t
;
143 if(s
&(Z_HITWATER
|Z_FALLOUT
)) {dot
[i
].t
=0;continue;}
147 if(!xv
) dot
[i
].o
.vx
=(rand()&1)?-1:1;
148 else dot
[i
].o
.vx
=Z_sign(dot
[i
].o
.vx
);
149 if(rand()%yv
==0) dot
[i
].o
.vx
*=2;
154 if(dot
[i
].t
>4 && dot
[i
].t
!=255) dot
[i
].t
=4;
157 dot
[i
].o
.vx
=Z_sign(xv
)*2;
158 dot
[i
].o
.yv
=Z_sign(dot
[i
].o
.yv
);
159 if(dot
[i
].o
.yv
>=0) if(rand()&3) --dot
[i
].o
.yv
;
160 if(dot
[i
].o
.yv
>=0) if(rand()&1) --dot
[i
].o
.yv
;
162 if(s
&Z_HITCEIL
) {dot
[i
].o
.xv
=0;dot
[i
].o
.yv
=(myrand(100))?-2:0;}
167 void DOT_draw(void) {
170 for(i
=0;i
<MAXDOT
;++i
)
171 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);
174 void DOT_add(int x
,int y
,char xv
,char yv
,byte c
,byte t
) {
177 if(!Z_canfit(x
,y
,0,1)) return;
179 dot
[i
].o
.x
=x
;dot
[i
].o
.y
=y
;
180 dot
[i
].o
.xv
=xv
;dot
[i
].o
.yv
=yv
;
181 dot
[i
].c
=c
;dot
[i
].t
=t
;
182 dot
[i
].o
.vx
=dot
[i
].o
.vy
=0;
186 void DOT_blood(int x
,int y
,int xv
,int yv
,int n
) {
190 dx
=x
+sxr
[sr_r
];dy
=y
+syr
[sr_r
];
191 if(!Z_canfit(x
,y
,0,1)) continue;
193 dot
[i
].o
.x
=dx
;dot
[i
].o
.y
=dy
;
194 dot
[i
].o
.xv
=bl_ini
[bl_r
].xv
+Z_dec(xv
,3);
195 dot
[i
].o
.yv
=bl_ini
[bl_r
].yv
+Z_dec(yv
,3)-3;
196 dot
[i
].c
=bl_ini
[bl_r
].c
;
198 dot
[i
].o
.vx
=dot
[i
].o
.vy
=0;
199 if(++bl_r
>=MAXINI
) bl_r
=0;
200 if(++sr_r
>=MAXSR
) sr_r
=0;
205 void DOT_spark(int x
,int y
,int xv
,int yv
,int n
) {
209 dx
=x
+sxr
[sr_r
];dy
=y
+syr
[sr_r
];
210 if(!Z_canfit(x
,y
,0,1)) continue;
212 dot
[i
].o
.x
=dx
;dot
[i
].o
.y
=dy
;
213 dot
[i
].o
.xv
=sp_ini
[sp_r
].xv
-xv
/4;
214 dot
[i
].o
.yv
=sp_ini
[sp_r
].yv
-yv
/4;
215 dot
[i
].c
=sp_ini
[sp_r
].c
;
216 dot
[i
].t
=sp_ini
[sp_r
].t
;
217 dot
[i
].o
.vx
=dot
[i
].o
.vy
=0;
218 if(++sp_r
>=MAXINI
) sp_r
=0;
219 if(++sr_r
>=MAXSR
) sr_r
=0;
224 void DOT_water(int x
,int y
,int xv
,int yv
,int n
,int c
) {
226 static byte ct
[3]={0xC0,0x70,0xB0};
228 if(c
<0 || c
>=3) return;
231 dx
=x
+sxr
[sr_r
];dy
=y
+syr
[sr_r
];
232 if(!Z_canfit(x
,y
,0,1)) continue;
234 dot
[i
].o
.x
=dx
;dot
[i
].o
.y
=dy
;
235 dot
[i
].o
.xv
=bl_ini
[bl_r
].xv
-Z_dec(xv
,3);
236 dot
[i
].o
.yv
=bl_ini
[bl_r
].yv
-abs(yv
);
237 dot
[i
].c
=bl_ini
[bl_r
].c
-0xB0+c
;
239 dot
[i
].o
.vx
=dot
[i
].o
.vy
=0;
240 if(++bl_r
>=MAXINI
) bl_r
=0;
241 if(++sr_r
>=MAXSR
) sr_r
=0;