X-Git-Url: http://deadsoftware.ru/gitweb?a=blobdiff_plain;f=core%2Fsrc%2Fru%2Fdeadsoftware%2Fcavecraft%2Fgame%2Fmobs%2FPig.java;h=04a96f6b7d41ad9ced14bc919e584de9ee69f815;hb=878489009db3feb875e4a0f05de955386b7afd7d;hp=aaa301998beeb1130f215f4447486cbcb6e23f33;hpb=01f293d956e7ad17163c67b8f2a2ebfd8f64ac6d;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 aaa3019..04a96f6 100644 --- a/core/src/ru/deadsoftware/cavecraft/game/mobs/Pig.java +++ b/core/src/ru/deadsoftware/cavecraft/game/mobs/Pig.java @@ -11,24 +11,39 @@ import ru.deadsoftware.cavecraft.game.GameProc; public class Pig extends Mob{ 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; + dead = false; } @Override - public void ai() { - if (MathUtils.randomBoolean(.0025f)) dir=-dir+1; + public void changeDir() { + dir=-dir+1; moveX.set(-1+2*dir,0); } + @Override + public void ai() { + if (MathUtils.randomBoolean(.0025f)) changeDir(); + else if (MathUtils.randomBoolean(.0025f)) { + if (moveX.x != 0f) moveX.setZero(); + else moveX.set(-1+2*dir, 0); + } + 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); @@ -47,4 +62,10 @@ public class Pig extends Mob{ public Rectangle getRect() { return new Rectangle(position.x, position.y, width, height); } + + @Override + public int getType() { + return 0; + } + }