DEADSOFTWARE

Minor changes
[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.game.GameWorld;
8 import ru.deadsoftware.cavecraft.misc.Assets;
9 import ru.deadsoftware.cavecraft.game.GameProc;
11 public class Pig extends Mob{
13 public Pig(int x, int y) {
14 dir = MathUtils.random(1);
15 position = new Vector2(x, y);
16 moveX = new Vector2(-1+dir*2, 0);
17 moveY = new Vector2(0, 0);
18 width = 25;
19 height = 18;
20 canJump = false;
21 dead = false;
22 }
24 @Override
25 public void changeDir() {
26 dir=-dir+1;
27 moveX.set(-1+2*dir,0);
28 }
30 @Override
31 public void ai() {
32 if (MathUtils.randomBoolean(.0025f)) changeDir();
33 else if (MathUtils.randomBoolean(.0025f)) {
34 if (moveX.x != 0f) moveX.setZero();
35 else moveX.set(-1+2*dir, 0);
36 }
37 if (moveX.x != 0f) animation+=ANIM_SPEED; else animation=0;
38 if (animation>=60 || animation<=-60) {
39 ANIM_SPEED = -ANIM_SPEED;
40 }
41 }
43 @Override
44 public void draw(SpriteBatch spriteBatch, float x, float y) {
45 Assets.pigSprite[0][1].setRotation(animation);
46 Assets.pigSprite[1][1].setRotation(-animation);
47 //back legs
48 Assets.pigSprite[1][1].setPosition(x-4+(9-dir*9),y+6);
49 Assets.pigSprite[1][1].draw(spriteBatch);
50 Assets.pigSprite[1][1].setPosition(x+17-(9*dir),y+6);
51 Assets.pigSprite[1][1].draw(spriteBatch);
52 //front legs
53 Assets.pigSprite[0][1].setPosition(x-4+(9-dir*9),y+6);
54 Assets.pigSprite[0][1].draw(spriteBatch);
55 Assets.pigSprite[0][1].setPosition(x+17-(9*dir),y+6);
56 Assets.pigSprite[0][1].draw(spriteBatch);
57 //head & body
58 spriteBatch.draw(Assets.pigSprite[dir][0], x, y);
59 }
61 @Override
62 public Rectangle getRect() {
63 return new Rectangle(position.x, position.y, width, height);
64 }
66 @Override
67 public int getType() {
68 return 0;
69 }
71 }