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
, jsr75i
, 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;
368 x
:= (getX(i
) + getW(i
) / 2 + 16 / 2) / 16;
370 x
:= (getX(i
) + getW(i
) / 2 - 16 / 2) / 16;
372 testSolid
:= phy
.isSolid(x
, y
, getVX(i
), getVY(i
));
375 function collideWithPlayer(i
: integer) : boolean;
377 collideWithPlayer
:= CollTwoObj(getX(i
), getY(i
), getW(i
), getH(i
), player
.getX
, player
.getY
, player
.getW
, player
.getH
);
380 function canBite(i
: integer) : boolean;
382 canBite
:= collideWithPlayer(i
);
385 procedure updateZloyAiAnim(i
: integer);
389 a_a
, a_d
, a_f
:integer;
418 procedure updateZloyAi(i
: integer);
422 if player
.getX
< getX(i
) then
427 else if player
.getX
> getX(i
) then
436 if testSolid(i
, vector
) then
440 if collideWithPlayer(i
) then
441 player
.biteIt(1, vector
);
446 i
, _type
, ai
:integer;
448 for i
:=0 to MAX_MOBS
do
452 if _type
<>M_NONE
then
461 procedure updatePhy
;//Обновление физики
465 for i
:=0 to MAX_MOBS
do
473 procedure drawPart(mobtype
, texid
, posi
, anim
, x
, y
, camx
, camy
:integer);
475 x
:=x
-tex_x
[posi
, mobtype
, texid
]-camx
;
476 y
:=y
-tex_y
[posi
, mobtype
, texid
]-camy
;
478 if CollTwoObj(x
, y
, tex_w
[posi
, mobtype
, texid
], tex_h
[posi
, mobtype
, texid
], 0, 0, getWidth
, getHeight
) then
480 drawImage(texture_left
[mobtype
, texid
+anim
], x
, y
);
482 drawImage(texture_right
[mobtype
, texid
+anim
], x
, y
);
485 procedure draw(camx
, camy
:integer);//Отрисовка
489 for i
:=0 to MAX_MOBS
do
492 if _type
<>M_NONE
then
494 for j
:=0 to part_max
[_type
] do
495 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
);
500 procedure loadSkin(path
:string);//Загрузка текстур
504 setMaxTextures(M_ZOMBY
, 5);
505 im
:=ld_tex('zombie_ani.png', path
, 'mobs/');
506 // IMG, TYPE, ID, POSI, X, Y
507 initTexture(rotate_image_from_image(im
, 6, 2, 8, 8, 0), M_ZOMBY
, 0, 0, 4, 8);//head[left]
508 initTexture(rotate_image_from_image(im
, 8, 10, 4, 12, 0), M_ZOMBY
, 1, 0, 2, 0);//body[left]
509 initTexture(rotate_image_from_image(im
, 0, 10, 12, 4, 0), M_ZOMBY
, 2, 0, 10, 2);//hands[left]
510 initTexture(rotate_image_from_image(im
, 0, 52, 12, 12, 0), M_ZOMBY
, 3, 0, 6, 0);//legs[left]
511 initTexture(rotate_image_from_image(im
, 13, 52, 12, 12, 0), M_ZOMBY
, 4, 0, 6, 0);
512 initTexture(rotate_image_from_image(im
, 26, 52, 12, 12, 0), M_ZOMBY
, 5, 0, 6, 0);
514 initTexture(rotate_image_from_image(im
, 27, 2, 8, 8, 0), M_ZOMBY
, 0, 1, 4, 8);//head[right]
515 initTexture(rotate_image_from_image(im
, 29, 10, 4, 12, 0), M_ZOMBY
, 1, 1, 2, 0);//body[right]
516 initTexture(rotate_image_from_image(im
, 29, 10, 12, 4, 0), M_ZOMBY
, 2, 1, 2, 2);//hands[right]
517 initTexture(rotate_image_from_image(im
, 39, 52, 12, 12, 0), M_ZOMBY
, 3, 1, 6, 0);//legs[right]
518 initTexture(rotate_image_from_image(im
, 52, 52, 12, 12, 0), M_ZOMBY
, 4, 1, 6, 0);
519 initTexture(rotate_image_from_image(im
, 65, 52, 12, 12, 0), M_ZOMBY
, 5, 1, 6, 0);
522 procedure freeSkin
;//Выгрузка текстур
527 for i
:=0 to MOB_TYPES
do
530 getstatic field
'mob', 'texture_left', '[[Ljavax/microedition/lcdui/Image;';
540 texture_left
[i
, j
]:=nullimg
;
541 texture_right
[i
, j
]:=nullimg
;
550 for i
:= 0 to MAX_MOBS
do
552 write_byte(mob_type
[i
]);
557 write_byte(mob_posi
[i
]);
559 writebool(mob_jmp
[i
]);
560 for j
:= 0 to MAX_ANIMREG
do
561 write_byte(mob_anim
[i
, j
]);
565 procedure loadData
;//Загрузка всех данных
569 for i
:= 0 to MAX_MOBS
do
571 mob_type
[i
] := read_byte
;
574 mob_vx
[i
] := readint
;
575 mob_vy
[i
] := readint
;
576 mob_posi
[i
] := read_byte
;
577 mob_hp
[i
] := readint
;
578 mob_jmp
[i
] := readbool
;
579 for j
:= 0 to MAX_ANIMREG
do
580 mob_anim
[i
, j
] := read_byte
;
584 procedure resetData
;//Сброс всех данных
588 for i
:= 0 to MAX_MOBS
do
598 for j
:= 0 to MAX_ANIMREG
do
604 // TYPE W H HP SX JH, AI_TYPE
605 initTab(M_NONE
, 0, 0, 0, 0, 0, AI_NONE
);
606 setMaxParts(M_NONE
, -1);
608 initTab(M_ZOMBY
, 8, 32, 10, 1, 7, AI_ZLOY
);
609 setMaxParts(M_ZOMBY
, 3);
610 // TYPE PART, TEX, X, Y ANIM
611 initPart(M_ZOMBY
, 0, 0, 4, 8, 0);//Head
612 initPart(M_ZOMBY
, 1, 1, 4, 8, 0);//Body
613 initPart(M_ZOMBY
, 2, 2, 4, 10, 0);//Hands
614 initPart(M_ZOMBY
, 3, 3, 4, 20, 1);//Legs