1 package ru
.deadsoftware
.cavedroid
.game
.mobs
;
3 import com
.badlogic
.gdx
.graphics
.g2d
.SpriteBatch
;
4 import com
.badlogic
.gdx
.math
.MathUtils
;
5 import com
.badlogic
.gdx
.math
.Vector2
;
6 import ru
.deadsoftware
.cavedroid
.misc
.Assets
;
8 import static ru
.deadsoftware
.cavedroid
.GameScreen
.GP
;
9 import static ru
.deadsoftware
.cavedroid
.misc
.Assets
.pigSprite
;
11 public class Pig
extends Mob
{
13 public Pig(float x
, float y
) {
14 super(x
, y
, 25, 18, Mob
.randomDir());
15 mov
= new Vector2(looksLeft() ?
-1 : 1, 0);
19 public void changeDir() {
21 mov
.x
= -1 + 2 * getDirection();
26 if (MathUtils
.randomBoolean(.0025f)) changeDir();
27 else if (MathUtils
.randomBoolean(.0025f)) {
28 if (mov
.x
!= 0f) mov
.x
= 0;
29 else mov
.x
= -1 + 2 * getDirection();
31 if (mov
.x
!= 0f) anim
+= animDelta
;
33 if (anim
>= 60 || anim
<= -60) {
34 animDelta
= -animDelta
;
39 public int getType() {
44 public void draw(SpriteBatch spriteBatch
, float x
, float y
) {
45 if (x
+ getWidth() - GP
.world
.getWidthPx() >= 0 && x
- GP
.world
.getWidthPx() <= getWidth()) {
46 x
-= GP
.world
.getWidthPx();
47 } else if (x
+ getWidth() + GP
.world
.getWidthPx() >= 0 && x
+ GP
.world
.getWidthPx() <= getWidth()) {
48 x
+= GP
.world
.getWidthPx();
51 pigSprite
[0][1].setRotation(getAnim());
52 pigSprite
[1][1].setRotation(-getAnim());
54 pigSprite
[1][1].setPosition(x
- 4 + (9 - getDirection() * 9), y
+ 6);
55 pigSprite
[1][1].draw(spriteBatch
);
56 pigSprite
[1][1].setPosition(x
+ 17 - (9 * getDirection()), y
+ 6);
57 pigSprite
[1][1].draw(spriteBatch
);
59 pigSprite
[0][1].setPosition(x
- 4 + (9 - getDirection() * 9), y
+ 6);
60 pigSprite
[0][1].draw(spriteBatch
);
61 pigSprite
[0][1].setPosition(x
+ 17 - (9 * getDirection()), y
+ 6);
62 pigSprite
[0][1].draw(spriteBatch
);
64 spriteBatch
.draw(Assets
.pigSprite
[getDirection()][0], x
, y
);