X-Git-Url: http://deadsoftware.ru/gitweb?a=blobdiff_plain;ds=inline;f=core%2Fsrc%2Fru%2Fdeadsoftware%2Fcavecraft%2Fgame%2Fmobs%2FPig.java;h=38eac46d69d9b70180df37400c86c70038bfbe34;hb=d7f5950fc751cec8fa64005dd1886cac4081ee99;hp=0400be0196d03990480f60261d4ba523fd8b65b6;hpb=385255cc7b49fbfd3290497367cbc69919b24d4f;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 0400be0..38eac46 100644 --- a/core/src/ru/deadsoftware/cavecraft/game/mobs/Pig.java +++ b/core/src/ru/deadsoftware/cavecraft/game/mobs/Pig.java @@ -4,46 +4,53 @@ 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.Assets; -import ru.deadsoftware.cavecraft.game.GameWorld; +import ru.deadsoftware.cavecraft.misc.Assets; -public class Pig extends Mob{ +public class Pig extends Mob { - private GameWorld world; - - public Pig(int x, int y, GameWorld world) { - this.world = world; - position = new Vector2(x, y); - moveX = new Vector2(0, 0); - moveY = new Vector2(0, 0); + public Pig(int x, int y) { + dir = MathUtils.random(1); + pos = new Vector2(x, y); + move = new Vector2(-1 + dir * 2, 0); width = 25; height = 18; - dir = 0; canJump = false; + dead = false; + } + + @Override + public void changeDir() { + dir = -dir + 1; + move.x = -1 + 2 * dir; } @Override public void ai() { - if (canJump && position.x>16 && position.x<(world.getWidth()-1)*16 && - world.getForeMap((int)(position.x/16)+(dir*2-1), (int)((position.y+height)/16))>0 && - 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(); + else if (MathUtils.randomBoolean(.0025f)) { + if (move.x != 0f) move.x = 0; + else move.x = -1 + 2 * dir; + } + if (move.x != 0f) anim += ANIM_SPEED; + else anim = 0; + if (anim >= 60 || anim <= -60) { + ANIM_SPEED = -ANIM_SPEED; + } } @Override public void draw(SpriteBatch spriteBatch, float x, float y) { + Assets.pigSprite[0][1].setRotation(anim); + Assets.pigSprite[1][1].setRotation(-anim); //back legs - Assets.pigSprite[1][1].setPosition(x-4+(9-dir*9),y+6); + Assets.pigSprite[1][1].setPosition(x - 4 + (9 - dir * 9), y + 6); Assets.pigSprite[1][1].draw(spriteBatch); - Assets.pigSprite[1][1].setPosition(x+17-(9*dir),y+6); + Assets.pigSprite[1][1].setPosition(x + 17 - (9 * dir), y + 6); Assets.pigSprite[1][1].draw(spriteBatch); //front legs - Assets.pigSprite[0][1].setPosition(x-4+(9-dir*9),y+6); + Assets.pigSprite[0][1].setPosition(x - 4 + (9 - dir * 9), y + 6); Assets.pigSprite[0][1].draw(spriteBatch); - Assets.pigSprite[0][1].setPosition(x+17-(9*dir),y+6); + Assets.pigSprite[0][1].setPosition(x + 17 - (9 * dir), y + 6); Assets.pigSprite[0][1].draw(spriteBatch); //head & body spriteBatch.draw(Assets.pigSprite[dir][0], x, y); @@ -51,6 +58,12 @@ public class Pig extends Mob{ @Override public Rectangle getRect() { - return new Rectangle(position.x, position.y, width, height); + return new Rectangle(pos.x, pos.y, width, height); } + + @Override + public int getType() { + return 0; + } + }