X-Git-Url: https://deadsoftware.ru/gitweb?p=cavedroid.git;a=blobdiff_plain;f=core%2Fsrc%2Fru%2Fdeadsoftware%2Fcavecraft%2Fgame%2Fmobs%2FMob.java;h=f776ff5111ca0800b25c7ff127c969d182023cab;hp=c52e78ff47dac0b895b4586182375464027d0f72;hb=99a56427db13dd0ecd025e433a438b77245cb739;hpb=385255cc7b49fbfd3290497367cbc69919b24d4f diff --git a/core/src/ru/deadsoftware/cavecraft/game/mobs/Mob.java b/core/src/ru/deadsoftware/cavecraft/game/mobs/Mob.java index c52e78f..f776ff5 100644 --- a/core/src/ru/deadsoftware/cavecraft/game/mobs/Mob.java +++ b/core/src/ru/deadsoftware/cavecraft/game/mobs/Mob.java @@ -3,29 +3,79 @@ package ru.deadsoftware.cavecraft.game.mobs; import com.badlogic.gdx.graphics.g2d.SpriteBatch; import com.badlogic.gdx.math.Rectangle; import com.badlogic.gdx.math.Vector2; -import com.badlogic.gdx.utils.Array; -import ru.deadsoftware.cavecraft.Assets; -public abstract class Mob { +import java.io.Serializable; + +public abstract class Mob implements Serializable { + + public boolean flyMode; + private float width, height; + private int dir; + + public Vector2 pos; + public Vector2 mov; + + private boolean dead; - public static int ANIM_SPEED = 6; - public static int ANIMATION = 0; - public Vector2 position; - public Vector2 moveX, moveY; - public int width, height, dir; public boolean canJump; + protected int anim, animDelta = 6; + + protected Mob(float x, float y, float width, float height, int dir, boolean player) { + 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); + } + + public int getMapX() { + return (int) (pos.x + (getWidth() / 2)) / 16; + } + + public int getMapY() { + return (int) (pos.y + (getHeight() / 2)) / 16; + } + + public float getWidth() { + return width; + } + + public float getHeight() { + return height; + } + + public int getDir() { + return dir; + } + + protected void switchDir() { + dir = -dir + 1; + } - public static void animateMobs() { - Assets.pigSprite[0][1].setRotation(ANIMATION); - Assets.pigSprite[1][1].setRotation(-ANIMATION); - ANIMATION+=ANIM_SPEED; - if (ANIMATION>=60 || ANIMATION<=-60) { - ANIM_SPEED = -ANIM_SPEED; - } + public boolean isDead() { + return dead; + } + + public void kill() { + dead = true; + } + + public Rectangle getRect() { + return new Rectangle(pos.x, pos.y, getWidth(), getHeight()); } public abstract void ai(); + + public abstract void changeDir(); + public abstract void draw(SpriteBatch spriteBatch, float x, float y); - public abstract Rectangle getRect(); + public abstract int getType(); //0 - mob, 10 - sand, 11 - gravel }