32c63cc26514d674c777f6f5a777104c68508fe4
1 package ru
.deadsoftware
.cavedroid
.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
;
12 public abstract class Mob
implements Serializable
{
14 public static final int LEFT
= 0;
15 public static final int RIGHT
= 1;
17 private final float width
;
18 private final float height
;
21 public boolean flyMode
;
22 public final Vector2 pos
;
27 protected int animDelta
= 6;
28 public boolean canJump
;
35 * @param width in pixels
36 * @param height in pixels
37 * @param dir integer representing a direction where 0 is left and 1 is right.
38 * You should use {@link #LEFT} and {@link #RIGHT} constants
40 protected Mob(float x
, float y
, float width
, float height
, int dir
) {
41 pos
= new Vector2(x
, y
);
42 mov
= new Vector2(0, 0);
53 * @return The X coordinate of a mob in blocks
55 public int getMapX() {
56 return (int) (pos
.x
+ (getWidth() / 2)) / 16;
61 * @return The Y coordinate of mob's upper edge in blocks
63 public int getUpperMapY() {
64 return (int) (pos
.y
/ 16);
69 * @return The Y coordinate if mob's vertical center in blocks
71 public int getMiddleMapY() {
72 return (int) (pos
.y
+ (getHeight() / 2)) / 16;
77 * @return The Y coordinate of mob's legs in blocks
79 public int getLowerMapY() {
80 return (int) (pos
.y
+ getHeight()) / 16;
83 public float getWidth() {
87 public float getHeight() {
93 * @return Integer representing a direction in which mob is looking, where 0 is left and 1 is right
95 public int getDirection() {
99 public boolean looksLeft() {
100 return getDirection() == LEFT
;
103 public boolean looksRight() {
104 return getDirection() == RIGHT
;
108 * Switches direction in which mob is looking
110 protected void switchDir() {
111 dir
= looksLeft() ? RIGHT
: LEFT
;
114 public boolean isDead() {
119 * Set's mob's dead variable to true and nothing else. It doesn't delete the mob.
127 * @return A {@link Rectangle} with mob's coordinates and size
129 public Rectangle
getRect() {
130 return new Rectangle(pos
.x
, pos
.y
, getWidth(), getHeight());
133 public abstract void ai();
135 public abstract void changeDir();
137 public abstract void draw(SpriteBatch spriteBatch
, float x
, float y
);
141 * @return 0 - if regular mob. <br>
142 * 10 - if instance of {@link FallingSand} <br> 11 - if instance of {@link FallingGravel}
144 public abstract int getType(); //0 - mob, 10 - sand, 11 - gravel