10 hp
, hunger
, air
:integer;
11 posi
:integer;//Сторона в которую повёрнут игрок
12 velx
,vely
: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);
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
;
42 uses func
, phy
, vars
, Canvas
, drop
, items
, jsr75i
, inv
;
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);
65 procedure setY(val
:integer);
70 function getX
:integer;
75 function getY
:integer;
80 function getW
:integer;
85 function getH
:integer;
90 procedure setVelX(val
:integer);
95 procedure setVelY(val
:integer);
100 function getVelX
:integer;
105 function getVelY
:integer;
110 procedure setJmp(val
:boolean);
115 function getJmp
:boolean;
120 procedure dropItem(item
, sum
:integer);
122 if posi
=POSI_LEFT
then
123 drop
.create(item
, sum
, getX
-8, getY
);
125 drop
.create(item
, sum
, getX
+getW
, getY
);
128 procedure loadSkin(str
, path
:string);
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);
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);
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);
161 PlayerBody
[i
]:=nullimg
;
163 PlayerHand
[i
, j
]:=nullimg
;
165 PlayerLegs
[i
, j
]:=nullimg
;
169 procedure playAnim(anim
:integer);
171 if anim
=ANIM_HAND
then
173 animHand
:=animHand
+1;
178 if anim
=ANIM_LEGS
then
182 animLegs
:=animLegs
+1;
187 animDelay
:=animDelay
+1;
188 if animDelay
>PLAYER_ANIM_DEL
then
193 procedure cancelAnim(anim
:integer);
195 if anim
=ANIM_HAND
then
200 if anim
=ANIM_LEGS
then
206 procedure draw(camx
, camy
:integer);
213 DrawImage(PlayerBody
[posi
], x
-camx
, y
-camy
);
214 DrawImage(PlayerLegs
[posi
, animLegs
], x
-2-camx
, y
+20-camy
);
217 drawSmallItem(inv
.getItem(invslot
), x
-camx
, y
+14-camy
);
219 if posi
=POSI_RIGHT
then
220 drawSmallItem(inv
.getItem(invslot
), x
+10-camx
, y
+5-camy
+animHand
);
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
);
228 DrawImage(PlayerHand
[posi
, animHand
], x
-6-camx
, y
+8-camy
);
233 phy
.loadObject(getX
, getY
, getW
, getH
, getVelX
, getVelY
, getJmp
);
240 setVelX(phy
.getVelX
);
241 setVelY(phy
.getVelY
);
246 {function coll:boolean;
248 coll:=CollObj(getX, getY, getW, getH);
251 //Player collision by block id.
252 function coll_bl(id:integer):boolean;
254 coll_bl:=CollObjBlock(getX, getY, getW, getH, id);
257 //Player collision by XY.
258 function coll_xy(xx,yy:integer):boolean;
260 coll_xy:=CollObjXY(getX, getY, getW, getH, xx, yy);
263 //Controll jump velocity
266 if (coll_bl(49)) or (coll_bl(103)) or (coll_bl(108)) then
268 if (coll_bl(50)) or (coll_bl(51)) then
270 if (coll_bl(0)) and (coll_bl(50) or coll_bl(51)) then
274 //Controll fall velocity
277 if (coll_bl(49)) or (coll_bl(103)) then
279 if (coll_bl(50)) or (coll_bl(51)) then
284 procedure calcPhysics
;
296 calcGravY(getX, getY, getW, getH, CONST_PHY_ACC, vely, CONST_PHY_MAXVEL, jmp);
304 hp:=(hp-(abs(old_vely)-10));
311 setVelY(-PLAYER_SPEED
);
323 setVelY(PLAYER_SPEED
);
328 setVelX(-PLAYER_SPEED
);
338 setVelX(PLAYER_SPEED
);
348 i
, maxd
, sum
:integer;
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
355 sum
:=inv
.giveItem(drop
.getItem(i
), drop
.getSum(i
));