X-Git-Url: http://deadsoftware.ru/gitweb?a=blobdiff_plain;f=core%2Fsrc%2Fru%2Fdeadsoftware%2Fcavecraft%2Fgame%2Fmobs%2FPig.java;h=10c4242429f221641c1e0ec501545b1311127350;hb=d5e611f9fb8deb93a9403b41f17dc000b9fa63ce;hp=879b66760cc082b0c0ee751f651da49092a22931;hpb=e7be8067d83f2a39c237ec7afbe115a846a74f3d;p=cavedroid.git diff --git a/core/src/ru/deadsoftware/cavecraft/game/mobs/Pig.java b/core/src/ru/deadsoftware/cavecraft/game/mobs/Pig.java index 879b667..10c4242 100644 --- a/core/src/ru/deadsoftware/cavecraft/game/mobs/Pig.java +++ b/core/src/ru/deadsoftware/cavecraft/game/mobs/Pig.java @@ -4,37 +4,45 @@ import com.badlogic.gdx.graphics.g2d.SpriteBatch; import com.badlogic.gdx.math.MathUtils; import com.badlogic.gdx.math.Rectangle; import com.badlogic.gdx.math.Vector2; +import ru.deadsoftware.cavecraft.game.GameWorld; import ru.deadsoftware.cavecraft.misc.Assets; import ru.deadsoftware.cavecraft.game.GameProc; public class Pig extends Mob{ - private GameProc gameProc; - - public Pig(int x, int y, GameProc gameProc) { - this.gameProc = gameProc; + public Pig(int x, int y) { + dir = MathUtils.random(1); position = new Vector2(x, y); - moveX = new Vector2(0, 0); + moveX = new Vector2(-1+dir*2, 0); moveY = new Vector2(0, 0); width = 25; height = 18; - dir = 0; canJump = false; + agressive = false; + } + + @Override + public void changeDir() { + dir=-dir+1; + moveX.set(-1+2*dir,0); + if (MathUtils.randomBoolean(.0025f)) { + moveX.set(0, 0); + } } @Override public void ai() { - if (canJump && position.x>16 && position.x<(gameProc.world.getWidth()-1)*16 && - gameProc.world.getForeMap((int)(position.x/16)+(dir*2-1), (int)((position.y+height)/16))>0 && - gameProc.world.getForeMap((int)(position.x/16)+(dir*2-1), (int)((position.y)/16))==0) - moveY.add(0, -8); - if (MathUtils.randomBoolean(.0001f)) dir++; - if (dir>1) dir = 0; - moveX.set(-1.5f+3*dir,0); + if (MathUtils.randomBoolean(.0025f)) changeDir(); + if (moveX.x != 0f) animation+=ANIM_SPEED; else animation=0; + if (animation>=60 || animation<=-60) { + ANIM_SPEED = -ANIM_SPEED; + } } @Override public void draw(SpriteBatch spriteBatch, float x, float y) { + Assets.pigSprite[0][1].setRotation(animation); + Assets.pigSprite[1][1].setRotation(-animation); //back legs Assets.pigSprite[1][1].setPosition(x-4+(9-dir*9),y+6); Assets.pigSprite[1][1].draw(spriteBatch);