DEADSOFTWARE

Small refactoring of physics module
[cavecraft.git] / src / particles.mpsrc
1 unit particles;
3 interface
4 var
5 bubble:image;
6 pr_1:array [0..7] of image;
7 none1:image;
8 pr_2:array [0..7] of image;
9 none2:image;
10 pr_3:array [0..7] of image;
11 none3:image;
12 pr_4:array [0..7] of image;
13 none4:image;
14 pr_5:array [0..7] of image;
15 none5:image;
16 pr_boom:array [0..15] of image;
17 none6:image;
19 max_particles:integer;
20 s_particles:boolean;
21 gb_up_pa:integer;
23 procedure create_particle(tp,ix,iy:integer);
24 procedure update_particle;
25 procedure draw_particle;
27 implementation
28 uses vars,maps,particles_store;
30 procedure create_particle(tp,ix,iy:integer);
31 var
32 i:integer;
33 begin
34 if s_particles=true then
35 for i:=0 to max_particles do
36 if get_particle_type(i)=0 then
37 begin
38 set_particle(i,tp,0,ix,iy);
39 exit;
40 end;
41 end;
43 procedure null_particle(i:integer);
44 begin
45 set_particle(i,0,0,0,0);
46 end;
48 procedure pr_ai_1(i,maxani:integer);
49 begin
50 set_particle_y(i,get_particle_y(i)-1);
51 set_particle_ani(i,get_particle_ani(i)+1);
52 if get_particle_ani(i)>maxani then null_particle(i);
53 end;
55 procedure pr_ai_bubble(i:integer);
56 var
57 xx,yy:integer;
58 begin
59 set_particle_y(i,get_particle_y(i)-1);
60 xx:=get_particle_x(i) div 16;
61 yy:=get_particle_y(i) div 16;
62 if getmap(xx,yy)<>50 then null_particle(i);
63 end;
65 procedure pr_ai_boom(i:integer);
66 begin
67 set_particle_ani(i,get_particle_ani(i)+1);
68 if get_particle_ani(i)>15 then null_particle(i);
69 end;
71 procedure update_particle;
72 var
73 i:integer;
74 begin
75 if s_particles=true then
76 begin
77 for i:=0 to max_particles do
78 if get_particle_type(i)>0 then
79 begin
80 if get_particle_type(i)=1 then pr_ai_1(i,5); else
81 if get_particle_type(i)=2 then pr_ai_1(i,5); else
82 if get_particle_type(i)=3 then pr_ai_1(i,5); else
83 if get_particle_type(i)=4 then pr_ai_1(i,5); else
84 if get_particle_type(i)=5 then pr_ai_1(i,5); else
85 if get_particle_type(i)=6 then pr_ai_bubble(i); else
86 if get_particle_type(i)=7 then pr_ai_boom(i); else
87 null_particle(i);
88 end;
89 gb_up_pa:=gb_up_pa+1;
90 if gb_up_pa>=2 then gb_up_pa:=0;
91 end;
92 end;
94 procedure draw_particle;
95 var
96 i:integer;
97 begin
98 for i:=0 to max_particles do
99 if get_particle_type(i)>0 then
100 begin
101 if get_particle_type(i)=1 then
102 begin
103 if (get_particle_x(i)-camx>-8) and (get_particle_x(i)-camx<getwidth) and (get_particle_y(i)-camy>-8) and (get_particle_y(i)-camy<getheight) then
104 drawimage(pr_1[get_particle_ani(i)],get_particle_x(i)-camx,get_particle_y(i)-camy);
105 end; else
106 if get_particle_type(i)=2 then
107 begin
108 if (get_particle_x(i)-camx>-8) and (get_particle_x(i)-camx<getwidth) and (get_particle_y(i)-camy>-8) and (get_particle_y(i)-camy<getheight) then
109 drawimage(pr_2[get_particle_ani(i)],get_particle_x(i)-camx,get_particle_y(i)-camy);
110 end; else
111 if get_particle_type(i)=3 then
112 begin
113 if (get_particle_x(i)-camx>-8) and (get_particle_x(i)-camx<getwidth) and (get_particle_y(i)-camy>-8) and (get_particle_y(i)-camy<getheight) then
114 drawimage(pr_3[get_particle_ani(i)],get_particle_x(i)-camx,get_particle_y(i)-camy);
115 end; else
116 if get_particle_type(i)=4 then
117 begin
118 if (get_particle_x(i)-camx>-8) and (get_particle_x(i)-camx<getwidth) and (get_particle_y(i)-camy>-8) and (get_particle_y(i)-camy<getheight) then
119 drawimage(pr_4[get_particle_ani(i)],get_particle_x(i)-camx,get_particle_y(i)-camy);
120 end; else
121 if get_particle_type(i)=5 then
122 begin
123 if (get_particle_x(i)-camx>-8) and (get_particle_x(i)-camx<getwidth) and (get_particle_y(i)-camy>-8) and (get_particle_y(i)-camy<getheight) then
124 drawimage(pr_4[get_particle_ani(i)],get_particle_x(i)-camx,get_particle_y(i)-camy);
125 end; else
126 if get_particle_type(i)=6 then
127 begin
128 if (get_particle_x(i)-camx>-8) and (get_particle_x(i)-camx<getwidth) and (get_particle_y(i)-camy>-8) and (get_particle_y(i)-camy<getheight) then
129 drawimage(bubble,get_particle_x(i)-camx,get_particle_y(i)-camy);
130 end; else
131 if get_particle_type(i)=7 then
132 begin
133 if (get_particle_x(i)-camx>-32) and (get_particle_x(i)-camx<getwidth) and (get_particle_y(i)-camy>-32) and (get_particle_y(i)-camy<getheight) then
134 drawimage(pr_boom[get_particle_ani(i)],get_particle_x(i)-camx,get_particle_y(i)-camy);
135 end;
136 end;
137 end;
139 end.