95815db35f60c894ba81fd5da88288eb5f65968a
10 procedure create(_type
, x
, y
:integer);//Создать моба
11 function findAndHit(value
, x
, y
, w
, h
, addvx
, addvy
:integer):integer;
13 procedure update
;//Обновление логики
14 procedure updatePhy
;//Обновление физики
15 procedure draw(camx
, camy
:integer);//Отрисовка
17 procedure saveData
;//Сохранение всех данных
18 procedure loadData
;//Загрузка всех данных
19 procedure resetData
;//Сброс всех данных
21 procedure loadSkin(path
:string);//Загрузка текстур
22 procedure freeSkin
;//Выгрузка текстур
25 uses phy
, player
, canvas
, func
;
33 mob_type
, mob_x
, mob_y
, mob_vx
, mob_vy
, mob_posi
, mob_hp
:array [0..MAX_MOBS
] of integer;
34 mob_jmp
:array [0..MAX_MOBS
] of boolean;
35 mob_anim
:array [0..MAX_MOBS
, 0..MAX_ANIMREG
] of integer;
36 tab_w
, tab_h
, tab_hp
, tab_speedx
, tab_jumph
, tab_ai
:array [0..MOB_TYPES
] of integer;
38 texture_left
, texture_right
:array [0..MOB_TYPES
, 0..0] of image
;
39 tex_x
, tex_y
, tex_w
, tex_h
:array [0..1, 0..MOB_TYPES
, 0..0] of integer;
41 part_max
: array [0..MOB_TYPES
] of integer;
42 part_tex
, part_x
, part_y
, part_anim
: array [0..MOB_TYPES
, 0..0] of integer;
44 function getType(i
:integer):integer;
49 function getX(i
:integer):integer;
54 function getY(i
:integer):integer;
59 function getVX(i
:integer):integer;
64 function getVY(i
:integer):integer;
69 function getPosi(i
:integer):integer;
74 function getHp(i
:integer):integer;
79 function getW(i
:integer):integer;
81 getW
:=tab_w
[mob_type
[i
]];
84 function getH(i
:integer):integer;
86 getH
:=tab_h
[mob_type
[i
]];
89 function getSpeedX(i
:integer):integer;
91 getSpeedX
:=tab_speedx
[mob_type
[i
]];
94 function getJumpH(i
:integer):integer;
96 getJumpH
:=tab_jumph
[mob_type
[i
]];
99 function getJmp(i
:integer):boolean;
104 procedure setType(value
, i
:integer);
109 procedure setX(value
, i
:integer);
114 procedure setY(value
, i
:integer);
119 procedure setVX(value
, i
:integer);
124 procedure setVY(value
, i
:integer);
129 procedure setPosi(value
, i
:integer);
134 procedure setHp(value
, i
:integer);
139 procedure setJmp(value
:boolean; i
:integer);
144 procedure initTab(_type
, w
, h
, hp
, speedx
, jumph
, ai
:integer);
149 tab_speedx
[_type
]:=speedx
;
150 tab_jumph
[_type
]:=jumph
;
154 procedure initTexture(img
:image
; mobtype
, texid
, posi
, centerx
, centery
:integer);
156 tex_w
[posi
, mobtype
, texid
]:=getImageWidth(img
);
157 tex_h
[posi
, mobtype
, texid
]:=getImageHeight(img
);
159 texture_left
[mobtype
, texid
]:=img
;
161 texture_right
[mobtype
, texid
]:=img
;
162 tex_x
[posi
, mobtype
, texid
]:=centerx
;
163 tex_y
[posi
, mobtype
, texid
]:=centery
;
166 procedure setMaxTextures(mobtype
, max
:integer);
171 debug('setMaxTextures(mobtype, max:integer);');
173 getstatic field
'mob', 'texture_left', '[[Ljavax/microedition/lcdui/Image;';
176 multianewarray
class '[Ljavax/microedition/lcdui/Image;', 1;
179 getstatic field
'mob', 'texture_right', '[[Ljavax/microedition/lcdui/Image;';
182 multianewarray
class '[Ljavax/microedition/lcdui/Image;', 1;
188 //tex_x[i][mobtype]=new int[max];
189 getstatic field
'mob', 'tex_x', '[[[I';
194 multianewarray
class '[I', 1;
197 getstatic field
'mob', 'tex_y', '[[[I';
202 multianewarray
class '[I', 1;
205 getstatic field
'mob', 'tex_w', '[[[I';
210 multianewarray
class '[I', 1;
213 getstatic field
'mob', 'tex_h', '[[[I';
218 multianewarray
class '[I', 1;
223 procedure setMaxParts(mobtype
, max
:integer);
225 part_max
[mobtype
]:=max
;
229 getstatic field
'mob', 'part_tex', '[[I';
232 multianewarray
class '[I', 1;
235 getstatic field
'mob', 'part_x', '[[I';
238 multianewarray
class '[I', 1;
241 getstatic field
'mob', 'part_y', '[[I';
244 multianewarray
class '[I', 1;
247 getstatic field
'mob', 'part_anim', '[[I';
250 multianewarray
class '[I', 1;
255 procedure initPart(mobtype
, partid
, tex
, x
, y
, animreg
:integer);
257 part_tex
[mobtype
, partid
]:=tex
;
258 part_x
[mobtype
, partid
]:=x
;
259 part_y
[mobtype
, partid
]:=y
;
260 part_anim
[mobtype
, partid
]:=animreg
;
263 procedure loadPhy(i
:integer);
265 phy
.loadObject(mob_x
[i
], mob_y
[i
], tab_w
[mob_type
[i
]], tab_h
[mob_type
[i
]], mob_vx
[i
], mob_vy
[i
], mob_jmp
[i
]);
268 procedure storePhy(i
:integer);
272 mob_vx
[i
]:=phy
.getVelX
;
273 mob_vy
[i
]:=phy
.getVelY
;
274 mob_jmp
[i
]:=phy
.getJmp
;
279 procedure create(_type
, x
, y
:integer);//Создать моба
283 debug('Create mob '+_type
+' @ '+x
+'x'+y
);
284 for i
:=0 to MAX_MOBS
do
285 if mob_type
[i
]=M_NONE
then
293 mob_hp
[i
]:=tab_hp
[_type
];
295 for j
:=0 to MAX_ANIMREG
do
298 debug('Created mob is '+i
);
303 procedure die(i
:integer);//Убить
308 procedure hit(value
, i
:integer);//Нанести урон
319 function findAndHit(value
, x
, y
, w
, h
, addvx
, addvy
:integer):integer;
323 for i
:=0 to MAX_MOBS
do
324 if getType(i
)<>M_NONE
then
325 if CollTwoObj(x
, y
, w
, h
, getX(i
), getY(i
), getW(i
), getH(i
)) then
327 setVX(getVX(i
)+addvx
, i
);
328 setVX(getVY(i
)+addvy
, i
);
337 procedure goUp(i
:integer);
340 phy
.jumpObj(getJumpH(i
));
344 procedure goDown(i
:integer);
349 procedure goLeft(i
:integer);
351 setVX(-getSpeedX(i
), i
);
355 procedure goRight(i
:integer);
357 setVX(getSpeedX(i
), i
);
361 function testSolid(i
, vector
:integer):boolean;
365 y
:=((getY(i
)+getH(i
)))/16-1;
374 x
:=((getX(i
)+getW(i
))/16){+1};
377 x
:=((getX(i
)+getW(i
)/2)/16);
379 testSolid
:=phy
.isSolid(x
, y
, getVX(i
), getVY(i
));
382 procedure updateZloyAiAnim(i
:integer);
386 a_a
, a_d
, a_f
:integer;
415 procedure updateZloyAi(i
:integer);
417 if player
.getX
<getX(i
) then
421 if testSolid(i
, -1) then
425 if player
.getX
>getX(i
) then
429 if testSolid(i
, 1) then
434 procedure update
;//Обновление логики
436 i
, _type
, ai
:integer;
438 for i
:=0 to MAX_MOBS
do
442 if _type
<>M_NONE
then
451 procedure updatePhy
;//Обновление физики
455 for i
:=0 to MAX_MOBS
do
463 procedure drawPart(mobtype
, texid
, posi
, anim
, x
, y
, camx
, camy
:integer);
465 x
:=x
-tex_x
[posi
, mobtype
, texid
]-camx
;
466 y
:=y
-tex_y
[posi
, mobtype
, texid
]-camy
;
468 if CollTwoObj(x
, y
, tex_w
[posi
, mobtype
, texid
], tex_h
[posi
, mobtype
, texid
], 0, 0, getWidth
, getHeight
) then
470 drawImage(texture_left
[mobtype
, texid
+anim
], x
, y
);
472 drawImage(texture_right
[mobtype
, texid
+anim
], x
, y
);
475 procedure draw(camx
, camy
:integer);//Отрисовка
479 for i
:=0 to MAX_MOBS
do
482 if _type
<>M_NONE
then
484 for j
:=0 to part_max
[_type
] do
485 drawPart(_type
, part_tex
[_type
, j
], mob_posi
[i
], mob_anim
[i
, part_anim
[_type
, j
]], mob_x
[i
]+part_x
[_type
, j
], mob_y
[i
]+part_y
[_type
, j
], camx
, camy
);
490 procedure loadSkin(path
:string);//Загрузка текстур
494 setMaxTextures(M_ZOMBY
, 5);
495 im
:=ld_tex('zombie_ani.png', path
, 'mobs/');
496 // IMG, TYPE, ID, POSI, X, Y
497 initTexture(rotate_image_from_image(im
, 6, 2, 8, 8, 0), M_ZOMBY
, 0, 0, 4, 8);//head[left]
498 initTexture(rotate_image_from_image(im
, 8, 10, 4, 12, 0), M_ZOMBY
, 1, 0, 2, 0);//body[left]
499 initTexture(rotate_image_from_image(im
, 0, 10, 12, 4, 0), M_ZOMBY
, 2, 0, 10, 2);//hands[left]
500 initTexture(rotate_image_from_image(im
, 0, 52, 12, 12, 0), M_ZOMBY
, 3, 0, 6, 0);//legs[left]
501 initTexture(rotate_image_from_image(im
, 13, 52, 12, 12, 0), M_ZOMBY
, 4, 0, 6, 0);
502 initTexture(rotate_image_from_image(im
, 26, 52, 12, 12, 0), M_ZOMBY
, 5, 0, 6, 0);
504 initTexture(rotate_image_from_image(im
, 27, 2, 8, 8, 0), M_ZOMBY
, 0, 1, 4, 8);//head[right]
505 initTexture(rotate_image_from_image(im
, 29, 10, 4, 12, 0), M_ZOMBY
, 1, 1, 2, 0);//body[right]
506 initTexture(rotate_image_from_image(im
, 29, 10, 12, 4, 0), M_ZOMBY
, 2, 1, 2, 2);//hands[right]
507 initTexture(rotate_image_from_image(im
, 39, 52, 12, 12, 0), M_ZOMBY
, 3, 1, 6, 0);//legs[right]
508 initTexture(rotate_image_from_image(im
, 52, 52, 12, 12, 0), M_ZOMBY
, 4, 1, 6, 0);
509 initTexture(rotate_image_from_image(im
, 65, 52, 12, 12, 0), M_ZOMBY
, 5, 1, 6, 0);
512 procedure freeSkin
;//Выгрузка текстур
517 for i
:=0 to MOB_TYPES
do
520 getstatic field
'mob', 'texture_left', '[[Ljavax/microedition/lcdui/Image;';
530 texture_left
[i
, j
]:=nullimg
;
531 texture_right
[i
, j
]:=nullimg
;
536 procedure saveData
;//Сохранение всех данных
541 procedure loadData
;//Загрузка всех данных
546 procedure resetData
;//Сброс всех данных
550 for i
:=0 to MAX_MOBS
do
560 for j
:=0 to MAX_ANIMREG
do
566 // TYPE W H HP SX JH, AI_TYPE
567 initTab(M_NONE
, 0, 0, 0, 0, 0, AI_NONE
);
568 setMaxParts(M_NONE
, -1);
570 initTab(M_ZOMBY
, 8, 32, 10, 1, 7, AI_ZLOY
);
571 setMaxParts(M_ZOMBY
, 3);
572 // TYPE PART, TEX, X, Y ANIM
573 initPart(M_ZOMBY
, 0, 0, 4, 8, 0);//Head
574 initPart(M_ZOMBY
, 1, 1, 4, 8, 0);//Body
575 initPart(M_ZOMBY
, 2, 2, 4, 10, 0);//Hands
576 initPart(M_ZOMBY
, 3, 3, 4, 20, 1);//Legs