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
56 static dot_t dot
[MAXDOT
];
57 static init_t bl_ini
[MAXINI
],sp_ini
[MAXINI
];
58 static int bl_r
,sp_r
,sr_r
,sxr
[MAXSR
],syr
[MAXSR
];
61 void DOT_savegame (FILE *h
) {
63 for (i
= n
= 0; i
< MAXDOT
; ++i
) {
69 for (i
= 0; i
< MAXDOT
; ++i
) {
71 myfwrite32(dot
[i
].o
.x
, h
);
72 myfwrite32(dot
[i
].o
.y
, h
);
73 myfwrite32(dot
[i
].o
.xv
, h
);
74 myfwrite32(dot
[i
].o
.yv
, h
);
75 myfwrite32(dot
[i
].o
.vx
, h
);
76 myfwrite32(dot
[i
].o
.vy
, h
);
77 myfwrite32(dot
[i
].o
.r
, h
);
78 myfwrite32(dot
[i
].o
.h
, h
);
79 myfwrite8(dot
[i
].c
, h
);
80 myfwrite8(dot
[i
].t
, h
);
85 void DOT_loadgame (FILE *h
) {
88 for (i
= 0; i
< n
; i
++) {
89 myfread32(&dot
[i
].o
.x
, h
);
90 myfread32(&dot
[i
].o
.y
, h
);
91 myfread32(&dot
[i
].o
.xv
, h
);
92 myfread32(&dot
[i
].o
.yv
, h
);
93 myfread32(&dot
[i
].o
.vx
, h
);
94 myfread32(&dot
[i
].o
.vy
, h
);
95 myfread32(&dot
[i
].o
.r
, h
);
96 myfread32(&dot
[i
].o
.h
, h
);
97 myfread8(&dot
[i
].c
, h
);
98 myfread8(&dot
[i
].t
, h
);
102 void DOT_init(void) {
105 for(i
=0;i
<MAXDOT
;++i
) {dot
[i
].t
=0;dot
[i
].o
.r
=0;dot
[i
].o
.h
=1;}
109 static void incldot(void) {
110 if(++ldot
>=MAXDOT
) ldot
=0;
113 void DOT_alloc(void) {
116 for(i
=0;i
<MAXINI
;++i
) {
117 bl_ini
[i
].xv
=myrand(BL_XV
*2+1)-BL_XV
;
118 bl_ini
[i
].yv
=-myrand(BL_YV
);
119 bl_ini
[i
].c
=0xB0+myrand(16);
120 bl_ini
[i
].t
=myrand(BL_MAXT
-BL_MINT
+1)+BL_MINT
;
121 sp_ini
[i
].xv
=myrand(SP_V
*2+1)-SP_V
;
122 sp_ini
[i
].yv
=myrand(SP_V
*2+1)-SP_V
;
123 sp_ini
[i
].c
=0xA0+myrand(6);
124 sp_ini
[i
].t
=myrand(SP_MAXT
-SP_MINT
+1)+SP_MINT
;
126 for(i
=0;i
<MAXSR
;++i
) {
127 sxr
[i
]=myrand(2*2+1)-2;
128 syr
[i
]=myrand(2*2+1)-2;
137 for(i
=0;i
<MAXDOT
;++i
) if(dot
[i
].t
) {
138 xv
=dot
[i
].o
.xv
+dot
[i
].o
.vx
;
139 yv
=dot
[i
].o
.yv
+dot
[i
].o
.vy
;
140 s
=Z_moveobj(&dot
[i
].o
);
141 if(dot
[i
].t
<254) --dot
[i
].t
;
142 if(s
&(Z_HITWATER
|Z_FALLOUT
)) {dot
[i
].t
=0;continue;}
146 if(!xv
) dot
[i
].o
.vx
=(rand()&1)?-1:1;
147 else dot
[i
].o
.vx
=Z_sign(dot
[i
].o
.vx
);
148 if(rand()%yv
==0) dot
[i
].o
.vx
*=2;
153 if(dot
[i
].t
>4 && dot
[i
].t
!=255) dot
[i
].t
=4;
156 dot
[i
].o
.vx
=Z_sign(xv
)*2;
157 dot
[i
].o
.yv
=Z_sign(dot
[i
].o
.yv
);
158 if(dot
[i
].o
.yv
>=0) if(rand()&3) --dot
[i
].o
.yv
;
159 if(dot
[i
].o
.yv
>=0) if(rand()&1) --dot
[i
].o
.yv
;
161 if(s
&Z_HITCEIL
) {dot
[i
].o
.xv
=0;dot
[i
].o
.yv
=(myrand(100))?-2:0;}
166 void DOT_draw(void) {
169 for(i
=0;i
<MAXDOT
;++i
)
170 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);
173 void DOT_add(int x
,int y
,char xv
,char yv
,byte c
,byte t
) {
176 if(!Z_canfit(x
,y
,0,1)) return;
178 dot
[i
].o
.x
=x
;dot
[i
].o
.y
=y
;
179 dot
[i
].o
.xv
=xv
;dot
[i
].o
.yv
=yv
;
180 dot
[i
].c
=c
;dot
[i
].t
=t
;
181 dot
[i
].o
.vx
=dot
[i
].o
.vy
=0;
185 void DOT_blood(int x
,int y
,int xv
,int yv
,int n
) {
189 dx
=x
+sxr
[sr_r
];dy
=y
+syr
[sr_r
];
190 if(!Z_canfit(x
,y
,0,1)) continue;
192 dot
[i
].o
.x
=dx
;dot
[i
].o
.y
=dy
;
193 dot
[i
].o
.xv
=bl_ini
[bl_r
].xv
+Z_dec(xv
,3);
194 dot
[i
].o
.yv
=bl_ini
[bl_r
].yv
+Z_dec(yv
,3)-3;
195 dot
[i
].c
=bl_ini
[bl_r
].c
;
197 dot
[i
].o
.vx
=dot
[i
].o
.vy
=0;
198 if(++bl_r
>=MAXINI
) bl_r
=0;
199 if(++sr_r
>=MAXSR
) sr_r
=0;
204 void DOT_spark(int x
,int y
,int xv
,int yv
,int n
) {
208 dx
=x
+sxr
[sr_r
];dy
=y
+syr
[sr_r
];
209 if(!Z_canfit(x
,y
,0,1)) continue;
211 dot
[i
].o
.x
=dx
;dot
[i
].o
.y
=dy
;
212 dot
[i
].o
.xv
=sp_ini
[sp_r
].xv
-xv
/4;
213 dot
[i
].o
.yv
=sp_ini
[sp_r
].yv
-yv
/4;
214 dot
[i
].c
=sp_ini
[sp_r
].c
;
215 dot
[i
].t
=sp_ini
[sp_r
].t
;
216 dot
[i
].o
.vx
=dot
[i
].o
.vy
=0;
217 if(++sp_r
>=MAXINI
) sp_r
=0;
218 if(++sr_r
>=MAXSR
) sr_r
=0;
223 void DOT_water(int x
,int y
,int xv
,int yv
,int n
,int c
) {
225 static byte ct
[3]={0xC0,0x70,0xB0};
227 if(c
<0 || c
>=3) return;
230 dx
=x
+sxr
[sr_r
];dy
=y
+syr
[sr_r
];
231 if(!Z_canfit(x
,y
,0,1)) continue;
233 dot
[i
].o
.x
=dx
;dot
[i
].o
.y
=dy
;
234 dot
[i
].o
.xv
=bl_ini
[bl_r
].xv
-Z_dec(xv
,3);
235 dot
[i
].o
.yv
=bl_ini
[bl_r
].yv
-abs(yv
);
236 dot
[i
].c
=bl_ini
[bl_r
].c
-0xB0+c
;
238 dot
[i
].o
.vx
=dot
[i
].o
.vy
=0;
239 if(++bl_r
>=MAXINI
) bl_r
=0;
240 if(++sr_r
>=MAXSR
) sr_r
=0;