X-Git-Url: https://deadsoftware.ru/gitweb?a=blobdiff_plain;f=core%2Fsrc%2Fru%2Fdeadsoftware%2Fcavedroid%2Fgame%2Fmobs%2FMob.java;h=716c3df07f44dc8e45b06c048716fc721fedeb52;hb=84377178320105196ad70bfa798ba8f299f961b2;hp=3b7edae21ed1748870f7b0d663407a11f33e4cd6;hpb=0a855ca3c1d0c84de41a928cc99fd8544a933015;p=cavedroid.git diff --git a/core/src/ru/deadsoftware/cavedroid/game/mobs/Mob.java b/core/src/ru/deadsoftware/cavedroid/game/mobs/Mob.java index 3b7edae..716c3df 100644 --- a/core/src/ru/deadsoftware/cavedroid/game/mobs/Mob.java +++ b/core/src/ru/deadsoftware/cavedroid/game/mobs/Mob.java @@ -1,48 +1,88 @@ package ru.deadsoftware.cavedroid.game.mobs; import com.badlogic.gdx.graphics.g2d.SpriteBatch; +import com.badlogic.gdx.math.MathUtils; import com.badlogic.gdx.math.Rectangle; import com.badlogic.gdx.math.Vector2; import java.io.Serializable; +/** + * Mob class. + */ public abstract class Mob implements Serializable { - public boolean flyMode; - private float width, height; + public static final int LEFT = 0; + public static final int RIGHT = 1; + + private final float width; + private final float height; private int dir; - public Vector2 pos; - public Vector2 mov; + protected final Vector2 pos; + protected Vector2 mov; private boolean dead; - public boolean canJump; - protected int anim, animDelta = 6; + private boolean canJump, flyMode; + protected int animDelta = 6; + protected int anim; + + protected static int randomDir() { + return MathUtils.random(1); + } - protected Mob(float x, float y, float width, float height, int dir, boolean player) { + /** + * + * @param x in pixels + * @param y in pixels + * @param width in pixels + * @param height in pixels + * @param dir integer representing a direction where 0 is left and 1 is right. + * You should use {@link #LEFT} and {@link #RIGHT} constants + */ + protected Mob(float x, float y, float width, float height, int dir) { pos = new Vector2(x, y); mov = new Vector2(0, 0); this.width = width; this.height = height; canJump = false; - flyMode = false; dead = false; this.dir = dir; } - protected Mob(float x, float y, float width, float height, int dir) { - this(x, y, width, height, dir, false); - } - + /** + * + * @return The X coordinate of a mob in blocks + */ public int getMapX() { return (int) (pos.x + (getWidth() / 2)) / 16; } - public int getMapY() { + /** + * + * @return The Y coordinate of mob's upper edge in blocks + */ + public int getUpperMapY() { + return (int) (pos.y / 16); + } + + /** + * + * @return The Y coordinate if mob's vertical center in blocks + */ + public int getMiddleMapY() { return (int) (pos.y + (getHeight() / 2)) / 16; } + /** + * + * @return The Y coordinate of mob's legs in blocks + */ + public int getLowerMapY() { + return (int) (pos.y + getHeight()) / 16; + } + public float getWidth() { return width; } @@ -51,31 +91,94 @@ public abstract class Mob implements Serializable { return height; } - public int getDir() { + /** + * + * @return Integer representing a direction in which mob is looking, where 0 is left and 1 is right + */ + public int getDirection() { return dir; } + public boolean looksLeft() { + return getDirection() == LEFT; + } + + public boolean looksRight() { + return getDirection() == RIGHT; + } + + /** + * Switches direction in which mob is looking + */ protected void switchDir() { - dir = -dir + 1; + dir = looksLeft() ? RIGHT : LEFT; } public boolean isDead() { return dead; } + public int getAnim() { + return anim; + } + + /** + * Set's mob's dead variable to true and nothing else. It doesn't delete the mob. + */ public void kill() { dead = true; } + /** + * + * @return A {@link Rectangle} with mob's coordinates and size + */ public Rectangle getRect() { return new Rectangle(pos.x, pos.y, getWidth(), getHeight()); } - public abstract void ai(); + public Vector2 getPos() { + return pos; + } - public abstract void changeDir(); + public Vector2 getMov() { + return mov; + } + + public float getX() { + return pos.x; + } + + public float getY() { + return pos.y; + } + + public boolean canJump() { + return canJump; + } + + public void setCanJump(boolean canJump) { + this.canJump = canJump; + } + + public boolean isFlyMode() { + return flyMode; + } + + public void setFlyMode(boolean flyMode) { + this.flyMode = flyMode; + } public abstract void draw(SpriteBatch spriteBatch, float x, float y); + public abstract void ai(); + + public abstract void changeDir(); + + /** + * + * @return 0 - if regular mob.
+ * 10 - if instance of {@link FallingSand}
11 - if instance of {@link FallingGravel} + */ public abstract int getType(); //0 - mob, 10 - sand, 11 - gravel }