DEADSOFTWARE

Fix code style
[cavedroid.git] / core / src / ru / deadsoftware / cavecraft / game / mobs / Pig.java
1 package ru.deadsoftware.cavecraft.game.mobs;
3 import com.badlogic.gdx.graphics.g2d.SpriteBatch;
4 import com.badlogic.gdx.math.MathUtils;
5 import com.badlogic.gdx.math.Rectangle;
6 import com.badlogic.gdx.math.Vector2;
7 import ru.deadsoftware.cavecraft.misc.Assets;
9 public class Pig extends Mob {
11 public Pig(int x, int y) {
12 dir = MathUtils.random(1);
13 position = new Vector2(x, y);
14 moveX = new Vector2(-1 + dir * 2, 0);
15 moveY = new Vector2(0, 0);
16 width = 25;
17 height = 18;
18 canJump = false;
19 dead = false;
20 }
22 @Override
23 public void changeDir() {
24 dir = -dir + 1;
25 moveX.set(-1 + 2 * dir, 0);
26 }
28 @Override
29 public void ai() {
30 if (MathUtils.randomBoolean(.0025f)) changeDir();
31 else if (MathUtils.randomBoolean(.0025f)) {
32 if (moveX.x != 0f) moveX.setZero();
33 else moveX.set(-1 + 2 * dir, 0);
34 }
35 if (moveX.x != 0f) animation += ANIM_SPEED;
36 else animation = 0;
37 if (animation >= 60 || animation <= -60) {
38 ANIM_SPEED = -ANIM_SPEED;
39 }
40 }
42 @Override
43 public void draw(SpriteBatch spriteBatch, float x, float y) {
44 Assets.pigSprite[0][1].setRotation(animation);
45 Assets.pigSprite[1][1].setRotation(-animation);
46 //back legs
47 Assets.pigSprite[1][1].setPosition(x - 4 + (9 - dir * 9), y + 6);
48 Assets.pigSprite[1][1].draw(spriteBatch);
49 Assets.pigSprite[1][1].setPosition(x + 17 - (9 * dir), y + 6);
50 Assets.pigSprite[1][1].draw(spriteBatch);
51 //front legs
52 Assets.pigSprite[0][1].setPosition(x - 4 + (9 - dir * 9), y + 6);
53 Assets.pigSprite[0][1].draw(spriteBatch);
54 Assets.pigSprite[0][1].setPosition(x + 17 - (9 * dir), y + 6);
55 Assets.pigSprite[0][1].draw(spriteBatch);
56 //head & body
57 spriteBatch.draw(Assets.pigSprite[dir][0], x, y);
58 }
60 @Override
61 public Rectangle getRect() {
62 return new Rectangle(position.x, position.y, width, height);
63 }
65 @Override
66 public int getType() {
67 return 0;
68 }
70 }