DEADSOFTWARE

Refactor
[cavedroid.git] / core / src / ru / deadsoftware / cavecraft / game / mobs / Mob.java
1 package ru.deadsoftware.cavecraft.game.mobs;
3 import com.badlogic.gdx.graphics.g2d.SpriteBatch;
4 import com.badlogic.gdx.math.Rectangle;
5 import com.badlogic.gdx.math.Vector2;
7 import java.io.Serializable;
9 public abstract class Mob implements Serializable {
11 public boolean flyMode;
12 private float width, height;
13 private int dir;
15 public Vector2 pos;
16 public Vector2 mov;
18 private boolean dead;
20 public boolean canJump;
21 protected int anim, animDelta = 6;
23 protected Mob(float x, float y, float width, float height, int dir, boolean player) {
24 pos = new Vector2(x, y);
25 mov = new Vector2(0, 0);
26 this.width = width;
27 this.height = height;
28 canJump = false;
29 flyMode = false;
30 dead = false;
31 this.dir = dir;
32 }
34 protected Mob(float x, float y, float width, float height, int dir) {
35 this(x, y, width, height, dir, false);
36 }
38 public int getMapX() {
39 return (int) (pos.x + (getWidth() / 2)) / 16;
40 }
42 public int getMapY() {
43 return (int) (pos.y + (getHeight() / 2)) / 16;
44 }
46 public float getWidth() {
47 return width;
48 }
50 public float getHeight() {
51 return height;
52 }
54 public int getDir() {
55 return dir;
56 }
58 protected void switchDir() {
59 dir = -dir + 1;
60 }
62 public boolean isDead() {
63 return dead;
64 }
66 public void kill() {
67 dead = true;
68 }
70 public Rectangle getRect() {
71 return new Rectangle(pos.x, pos.y, getWidth(), getHeight());
72 }
74 public abstract void ai();
76 public abstract void changeDir();
78 public abstract void draw(SpriteBatch spriteBatch, float x, float y);
80 public abstract int getType(); //0 - mob, 10 - sand, 11 - gravel
81 }