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 public class Pig
extends Mob
{
10 public Pig(float x
, float y
) {
11 super(x
, y
, 25, 18, MathUtils
.random(1));
12 mov
= new Vector2(-1 + getDir() * 2, 0);
16 public void changeDir() {
18 mov
.x
= -1 + 2 * getDir();
23 if (MathUtils
.randomBoolean(.0025f)) changeDir();
24 else if (MathUtils
.randomBoolean(.0025f)) {
25 if (mov
.x
!= 0f) mov
.x
= 0;
26 else mov
.x
= -1 + 2 * getDir();
28 if (mov
.x
!= 0f) anim
+= animDelta
;
30 if (anim
>= 60 || anim
<= -60) {
31 animDelta
= -animDelta
;
36 public void draw(SpriteBatch spriteBatch
, float x
, float y
) {
37 Assets
.pigSprite
[0][1].setRotation(anim
);
38 Assets
.pigSprite
[1][1].setRotation(-anim
);
40 Assets
.pigSprite
[1][1].setPosition(x
- 4 + (9 - getDir() * 9), y
+ 6);
41 Assets
.pigSprite
[1][1].draw(spriteBatch
);
42 Assets
.pigSprite
[1][1].setPosition(x
+ 17 - (9 * getDir()), y
+ 6);
43 Assets
.pigSprite
[1][1].draw(spriteBatch
);
45 Assets
.pigSprite
[0][1].setPosition(x
- 4 + (9 - getDir() * 9), y
+ 6);
46 Assets
.pigSprite
[0][1].draw(spriteBatch
);
47 Assets
.pigSprite
[0][1].setPosition(x
+ 17 - (9 * getDir()), y
+ 6);
48 Assets
.pigSprite
[0][1].draw(spriteBatch
);
50 spriteBatch
.draw(Assets
.pigSprite
[getDir()][0], x
, y
);
54 public int getType() {