diff --git a/core/src/ru/deadsoftware/cavecraft/game/mobs/Pig.java b/core/src/ru/deadsoftware/cavecraft/game/mobs/Pig.java
index 879b66760cc082b0c0ee751f651da49092a22931..1dd9f9a2a659d46afb80f1fbf9e56fe99cd679f3 100644 (file)
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.badlogic.gdx.math.MathUtils;
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;
import com.badlogic.gdx.math.Vector2;
import ru.deadsoftware.cavecraft.misc.Assets;
-import ru.deadsoftware.cavecraft.game.GameProc;
-public class Pig extends Mob{
+public class Pig extends Mob {
- private GameProc gameProc;
+ public Pig(float x, float y) {
+ super(x, y, 25, 18, MathUtils.random(1));
+ mov = new Vector2(-1 + getDir() * 2, 0);
+ }
- public Pig(int x, int y, GameProc gameProc) {
- this.gameProc = gameProc;
- position = new Vector2(x, y);
- moveX = new Vector2(0, 0);
- moveY = new Vector2(0, 0);
- width = 25;
- height = 18;
- dir = 0;
- canJump = false;
+ @Override
+ public void changeDir() {
+ switchDir();
+ mov.x = -1 + 2 * getDir();
}
@Override
public void ai() {
}
@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();
+ else if (MathUtils.randomBoolean(.0025f)) {
+ if (mov.x != 0f) mov.x = 0;
+ else mov.x = -1 + 2 * getDir();
+ }
+ if (mov.x != 0f) anim += animDelta;
+ else anim = 0;
+ if (anim >= 60 || anim <= -60) {
+ animDelta = -animDelta;
+ }
}
@Override
public void draw(SpriteBatch spriteBatch, float x, float y) {
}
@Override
public void draw(SpriteBatch spriteBatch, float x, float y) {
+ Assets.pigSprite[0][1].setRotation(anim);
+ Assets.pigSprite[1][1].setRotation(-anim);
//back legs
//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].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[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].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
Assets.pigSprite[0][1].draw(spriteBatch);
//head & body
- spriteBatch.draw(Assets.pigSprite[dir][0], x, y);
+ spriteBatch.draw(Assets.pigSprite[getDir()][0], x, y);
}
@Override
}
@Override
- public Rectangle getRect() {
- return new Rectangle(position.x, position.y, width, height);
+ public int getType() {
+ return 0;
}
}
+
}
}