DEADSOFTWARE

Fix json load
[cavedroid.git] / core / src / ru / deadsoftware / cavedroid / game / mobs / Pig.java
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);
13 }
15 @Override
16 public void changeDir() {
17 switchDir();
18 mov.x = -1 + 2 * getDir();
19 }
21 @Override
22 public void ai() {
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();
27 }
28 if (mov.x != 0f) anim += animDelta;
29 else anim = 0;
30 if (anim >= 60 || anim <= -60) {
31 animDelta = -animDelta;
32 }
33 }
35 @Override
36 public void draw(SpriteBatch spriteBatch, float x, float y) {
37 Assets.pigSprite[0][1].setRotation(anim);
38 Assets.pigSprite[1][1].setRotation(-anim);
39 //back legs
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);
44 //front legs
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);
49 //head & body
50 spriteBatch.draw(Assets.pigSprite[getDir()][0], x, y);
51 }
53 @Override
54 public int getType() {
55 return 0;
56 }
58 }