DEADSOFTWARE

Convert codepage to utf8
[cavecraft.git] / src / player.mpsrc
1 unit player;
3 interface
4 const
5 ANIM_HAND=0;
6 ANIM_LEGS=1;
8 var
9 fly:boolean;
10 hp, hunger, air:integer;
11 posi:integer;//Сторона в которую повёрнут игрок
12 velx,vely:integer;//Переменные для физики игрока
13 jmp, an_pr:boolean;
14 s_get_drp:boolean;
15 invslot:integer;
17 procedure setX(val:integer);
18 procedure setY(val:integer);
19 function getX:integer;
20 function getY:integer;
21 function getW:integer;
22 function getH:integer;
24 procedure loadSkin(str, path:string);
25 procedure freeSkin;
26 procedure draw(camx, camy:integer);
27 procedure playAnim(anim:integer);
28 procedure cancelAnim(anim:integer);
30 procedure dropItem(item, sum:integer);
32 procedure calcPhysics;
34 procedure gotoUP;
35 procedure gotoDOWN;
36 procedure gotoLEFT;
37 procedure gotoRIGHT;
39 procedure getDrop;
41 implementation
42 uses func, phy, vars, Canvas, drop, items, jsr75i, inv;
43 const
44 PLAYER_W=8;
45 PLAYER_H=32;
46 PLAYER_SPEED=2;
48 POSI_LEFT=0;
49 POSI_RIGHT=1;
50 PLAYER_ANIM_DEL=1;
51 var
52 plx, ply:integer;
54 //Skin
55 PlayerBody: array [0..1] of image;
56 PlayerHand: array [0..1, 0..3] of image;
57 PlayerLegs: array [0..1, 0..2] of image;
58 animHand, animLegs, animDelay:integer;
60 procedure setX(val:integer);
61 begin
62 plx:=val;
63 end;
65 procedure setY(val:integer);
66 begin
67 ply:=val;
68 end;
70 function getX:integer;
71 begin
72 getX:=plx;
73 end;
75 function getY:integer;
76 begin
77 getY:=ply;
78 end;
80 function getW:integer;
81 begin
82 getW:=PLAYER_W;
83 end;
85 function getH:integer;
86 begin
87 getH:=PLAYER_H;
88 end;
90 procedure setVelX(val:integer);
91 begin
92 velx:=val;
93 end;
95 procedure setVelY(val:integer);
96 begin
97 vely:=val;
98 end;
100 function getVelX:integer;
101 begin
102 getVelX:=velx;
103 end;
105 function getVelY:integer;
106 begin
107 getVelY:=vely;
108 end;
110 procedure setJmp(val:boolean);
111 begin
112 jmp:=val;
113 end;
115 function getJmp:boolean;
116 begin
117 getJmp:=jmp;
118 end;
120 procedure dropItem(item, sum:integer);
121 begin
122 if posi=POSI_LEFT then
123 drop.create(item, sum, getX-8, getY);
124 else
125 drop.create(item, sum, getX+getW, getY);
126 end;
128 procedure loadSkin(str, path:string);
129 var
130 im:image;
131 i:integer;
132 begin
133 im:=ld_tex(str, path, 'mobs/');
135 PlayerBody[POSI_LEFT]:=rotate_image_from_image(im, 0, 0, 8, 20, 0);
136 PlayerBody[POSI_RIGHT]:=rotate_image_from_image(im, 8, 0, 8, 20, 0);
138 PlayerHand[POSI_LEFT, 0]:=rotate_image_from_image(im, 40, 0, 4, 12, 0);
139 PlayerHand[POSI_RIGHT, 0]:=rotate_image_from_image(im, 44, 0, 4, 12, 0);
141 for i:=1 to 3 do
142 begin
143 PlayerHand[POSI_LEFT, i]:=rotate_image_from_image(im, 16, (i-1)*6, 12, 6, 0);
144 PlayerHand[POSI_RIGHT, i]:=rotate_image_from_image(im, 28, (i-1)*6, 12, 6, 0);
145 end;
147 for i:=0 to 2 do
148 begin
149 PlayerLegs[POSI_LEFT, i]:=rotate_image_from_image(im, i*12, 20, 12, 12, 0);
150 PlayerLegs[POSI_RIGHT, i]:=rotate_image_from_image(im, 36+i*12, 20, 12, 12, 0);
151 end;
152 end;
154 procedure freeSkin;
155 var
156 i, j:integer;
157 nullimg:image;
158 begin
159 for i:=0 to 1 do
160 begin
161 PlayerBody[i]:=nullimg;
162 for j:=0 to 3 do
163 PlayerHand[i, j]:=nullimg;
164 for j:=0 to 2 do
165 PlayerLegs[i, j]:=nullimg;
166 end;
167 end;
169 procedure playAnim(anim:integer);
170 begin
171 if anim=ANIM_HAND then
172 begin
173 animHand:=animHand+1;
174 if animHand>3 then
175 animHand:=1;
176 end;
177 else
178 if anim=ANIM_LEGS then
179 begin
180 if animDelay=0 then
181 begin
182 animLegs:=animLegs+1;
183 if animLegs>2 then
184 animLegs:=0;
185 end;
187 animDelay:=animDelay+1;
188 if animDelay>PLAYER_ANIM_DEL then
189 animDelay:=0;
190 end;
191 end;
193 procedure cancelAnim(anim:integer);
194 begin
195 if anim=ANIM_HAND then
196 begin
197 animHand:=0;
198 end;
199 else
200 if anim=ANIM_LEGS then
201 begin
202 animLegs:=0;
203 end;
204 end;
206 procedure draw(camx, camy:integer);
207 var
208 x, y:integer;
209 begin
210 x:=getX;
211 y:=getY;
213 DrawImage(PlayerBody[posi], x-camx, y-camy);
214 DrawImage(PlayerLegs[posi, animLegs], x-2-camx, y+20-camy);
216 if animHand=0 then
217 drawSmallItem(inv.getItem(invslot), x-camx, y+14-camy);
218 else
219 if posi=POSI_RIGHT then
220 drawSmallItem(inv.getItem(invslot), x+10-camx, y+5-camy+animHand);
221 else
222 if posi=POSI_LEFT then
223 drawSmallItem(inv.getItem(invslot), x-10-camx, y+5-camy+animHand);
225 if (animHand=0) or (posi=POSI_RIGHT) then
226 DrawImage(PlayerHand[posi, animHand], x+2-camx, y+8-camy);
227 else
228 DrawImage(PlayerHand[posi, animHand], x-6-camx, y+8-camy);
229 end;
231 procedure loadPhy;
232 begin
233 phy.loadObject(getX, getY, getW, getH, getVelX, getVelY, getJmp);
234 end;
236 procedure storePhy;
237 begin
238 setX(phy.getX);
239 setY(phy.getY);
240 setVelX(phy.getVelX);
241 setVelY(phy.getVelY);
242 setJmp(phy.getJmp);
243 end;
245 //Player collision.
246 {function coll:boolean;
247 begin
248 coll:=CollObj(getX, getY, getW, getH);
249 end;
251 //Player collision by block id.
252 function coll_bl(id:integer):boolean;
253 begin
254 coll_bl:=CollObjBlock(getX, getY, getW, getH, id);
255 end;
257 //Player collision by XY.
258 function coll_xy(xx,yy:integer):boolean;
259 begin
260 coll_xy:=CollObjXY(getX, getY, getW, getH, xx, yy);
261 end;
263 //Controll jump velocity
264 procedure jmp_ctrl;
265 begin
266 if (coll_bl(49)) or (coll_bl(103)) or (coll_bl(108)) then
267 vely:=5;
268 if (coll_bl(50)) or (coll_bl(51)) then
269 vely:=4;
270 if (coll_bl(0)) and (coll_bl(50) or coll_bl(51)) then
271 vely:=7;
272 end;
274 //Controll fall velocity
275 procedure phy_ctrl;
276 begin
277 if (coll_bl(49)) or (coll_bl(103)) then
278 vely:=-5;
279 if (coll_bl(50)) or (coll_bl(51)) then
280 if vely<-4 then
281 vely:=-4;
282 end;}
284 procedure calcPhysics;
285 var
286 old_vely:integer;
287 cl:boolean;
288 begin
289 loadPhy;
290 phy.calc(not fly);
291 storePhy;
293 {if fly=false then
294 begin
295 old_vely:=vely;
296 calcGravY(getX, getY, getW, getH, CONST_PHY_ACC, vely, CONST_PHY_MAXVEL, jmp);
297 setY(PhyGetY);
298 vely:=PhyGetVelY;
299 jmp:=PhyGetJump;
300 cl:=PhyGetColl;
302 if cl then
303 if old_vely<-10 then
304 hp:=(hp-(abs(old_vely)-10));
305 end;}
306 end;
308 procedure gotoUP;
309 begin
310 if fly then
311 setVelY(-PLAYER_SPEED);
312 else
313 begin
314 loadPhy;
315 jumpObj(7);
316 storePhy;
317 end;
318 end;
320 procedure gotoDOWN;
321 begin
322 if fly then
323 setVelY(PLAYER_SPEED);
324 end;
326 procedure gotoLEFT;
327 begin
328 setVelX(-PLAYER_SPEED);
330 posi:=POSI_LEFT;
332 if fly=false then
333 playAnim(ANIM_LEGS);
334 end;
336 procedure gotoRIGHT;
337 begin
338 setVelX(PLAYER_SPEED);
340 posi:=POSI_RIGHT;
342 if fly=false then
343 playAnim(ANIM_LEGS);
344 end;
346 procedure getDrop;
347 var
348 i, maxd, sum:integer;
349 begin
350 maxd:=drop.max;
351 for i:=0 to maxd do
352 if drop.isNull(i)=false then
353 if CollTwoObj(getX, getY, getW, getH, drop.getX(i), drop.getY(i), drop.getW, drop.getH) then
354 begin
355 sum:=inv.giveItem(drop.getItem(i), drop.getSum(i));
356 drop.setSum(sum, i);
357 drop.fixNull(i);
358 end;
359 end;
361 initialization
363 end.