From: DeaDDooMER Date: Wed, 8 Mar 2017 10:22:20 +0000 (+0300) Subject: Small zombi-related fix X-Git-Url: http://deadsoftware.ru/gitweb?a=commitdiff_plain;h=89a93092c75dfc61007345054269c0c3c3d4b823;p=cavecraft.git Small zombi-related fix --- diff --git a/src/mobs.pas b/src/mobs.pas index 95815db..4899980 100644 --- a/src/mobs.pas +++ b/src/mobs.pas @@ -358,28 +358,31 @@ procedure storePhy(i:integer); setPosi(1, i); end; - function testSolid(i, vector:integer):boolean; + function testSolid(i, vector : integer) : boolean; var - x, y:integer; + x, y : integer; begin - y:=((getY(i)+getH(i)))/16-1; + y := (getY(i) + getH(i)) / 16 - 1; - if vector<0 then - begin - x:=(getX(i)/16)-1; - end; - else - if vector>0 then - begin - x:=((getX(i)+getW(i))/16){+1}; - end; + if vector > 0 then + x := (getX(i) + getW(i) / 2 + 16 / 2) / 16; else - x:=((getX(i)+getW(i)/2)/16); + x := (getX(i) + getW(i) / 2 - 16 / 2) / 16; - testSolid:=phy.isSolid(x, y, getVX(i), getVY(i)); + testSolid := phy.isSolid(x, y, getVX(i), getVY(i)); + end; + + function collideWithPlayer(i : integer) : boolean; + begin + collideWithPlayer := CollTwoObj(getX(i), getY(i), getW(i), getH(i), player.getX, player.getY, player.getW, player.getH); + end; + + function canBite(i : integer) : boolean; + begin + canBite := collideWithPlayer(i); end; - procedure updateZloyAiAnim(i:integer); + procedure updateZloyAiAnim(i : integer); const DEL=1; var @@ -412,26 +415,33 @@ procedure storePhy(i:integer); mob_anim[i, 3]:=a_f; end; - procedure updateZloyAi(i:integer); + procedure updateZloyAi(i : integer); + var + vector : integer; begin - if player.getXgetX(i) then - begin - goRight(i); - updateZloyAiAnim(i); - if testSolid(i, 1) then - goUp(i); + vector := -1; end; + else if player.getX > getX(i) then + begin + goRight(i); + vector := 1; + end; + + if vector <> 0 then + begin + updateZloyAiAnim(i); + if testSolid(i, vector) then + goUp(i); + end; + + if collideWithPlayer(i) then + player.biteIt(1, vector); end; - procedure update;//Обновление логики + procedure update; var i, _type, ai:integer; begin diff --git a/src/player.mpsrc b/src/player.mpsrc index 3e9f361..1891939 100644 --- a/src/player.mpsrc +++ b/src/player.mpsrc @@ -28,6 +28,7 @@ interface procedure cancelAnim(anim:integer); procedure dropItem(item, sum:integer); + procedure biteIt(hp : integer; vector : integer); procedure calcPhysics; @@ -228,6 +229,11 @@ implementation DrawImage(PlayerHand[posi, animHand], x-6-camx, y+8-camy); end; + procedure biteIt(damage : integer; vector : integer); + begin + hp := hp - damage; + end; + procedure loadPhy; begin phy.loadObject(getX, getY, getW, getH, getVelX, getVelY, getJmp);