X-Git-Url: https://deadsoftware.ru/gitweb?p=cavedroid.git;a=blobdiff_plain;f=core%2Fsrc%2Fru%2Fdeadsoftware%2Fcavecraft%2Fgame%2Fmobs%2FPig.java;h=aa3f79763f8791d87f3d90847317cdf6c1483827;hp=38eac46d69d9b70180df37400c86c70038bfbe34;hb=cef4b5a9985bcbdfea6dc652147ecde0721d7fdc;hpb=d7f5950fc751cec8fa64005dd1886cac4081ee99 diff --git a/core/src/ru/deadsoftware/cavecraft/game/mobs/Pig.java b/core/src/ru/deadsoftware/cavecraft/game/mobs/Pig.java index 38eac46..aa3f797 100644 --- a/core/src/ru/deadsoftware/cavecraft/game/mobs/Pig.java +++ b/core/src/ru/deadsoftware/cavecraft/game/mobs/Pig.java @@ -2,39 +2,33 @@ package ru.deadsoftware.cavecraft.game.mobs; 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.misc.Assets; public class Pig extends Mob { - 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; - canJump = false; - dead = false; + public Pig(float x, float y) { + super(x, y, 25, 18, MathUtils.random(1)); + mov = new Vector2(-1 + getDir() * 2, 0); } @Override public void changeDir() { - dir = -dir + 1; - move.x = -1 + 2 * dir; + switchDir(); + mov.x = -1 + 2 * getDir(); } @Override public void ai() { if (MathUtils.randomBoolean(.0025f)) changeDir(); else if (MathUtils.randomBoolean(.0025f)) { - if (move.x != 0f) move.x = 0; - else move.x = -1 + 2 * dir; + if (mov.x != 0f) mov.x = 0; + else mov.x = -1 + 2 * getDir(); } - if (move.x != 0f) anim += ANIM_SPEED; + if (mov.x != 0f) anim += animSpeed; else anim = 0; if (anim >= 60 || anim <= -60) { - ANIM_SPEED = -ANIM_SPEED; + animSpeed = -animSpeed; } } @@ -43,22 +37,17 @@ public class Pig extends Mob { 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 - getDir() * 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 * getDir()), 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 - getDir() * 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 * getDir()), y + 6); Assets.pigSprite[0][1].draw(spriteBatch); //head & body - spriteBatch.draw(Assets.pigSprite[dir][0], x, y); - } - - @Override - public Rectangle getRect() { - return new Rectangle(pos.x, pos.y, width, height); + spriteBatch.draw(Assets.pigSprite[getDir()][0], x, y); } @Override