X-Git-Url: http://deadsoftware.ru/gitweb?a=blobdiff_plain;f=core%2Fsrc%2Fru%2Fdeadsoftware%2Fcavedroid%2Fgame%2Fobjects%2FBlock.java;h=0800b5b5cb8d8f713aef6e017a4c7af355675c79;hb=8a04988798e25c00b8ea18f5cc4fa2b18eeca8e2;hp=2a4491610caae37ea8207e1e46e2205c3fd49740;hpb=4eb1f6f24fb76c0336394b85393e801fd0b99da4;p=cavedroid.git diff --git a/core/src/ru/deadsoftware/cavedroid/game/objects/Block.java b/core/src/ru/deadsoftware/cavedroid/game/objects/Block.java index 2a44916..0800b5b 100644 --- a/core/src/ru/deadsoftware/cavedroid/game/objects/Block.java +++ b/core/src/ru/deadsoftware/cavedroid/game/objects/Block.java @@ -3,18 +3,43 @@ package ru.deadsoftware.cavedroid.game.objects; import com.badlogic.gdx.graphics.g2d.Sprite; import com.badlogic.gdx.math.Rectangle; -public class Block { - - private int x, y, w, h; - private int hp; - private String drop, meta; - private Sprite tex; +import javax.annotation.CheckForNull; - //coll - collision, bg - background, tp - transparent, rb - requires block under it - private boolean coll, bg, tp, rb, fluid; +public class Block { - public Block(int left, int top, int right, int bottom, int hp, - String drop, boolean coll, boolean bg, boolean tp, boolean rb, boolean fluid, String meta, Sprite tex) { + private final int x; + private final int y; + private final int w; + private final int h; + private final int hp; + private final String drop; + private final String meta; + @CheckForNull + private final Sprite tex; + + private final boolean coll; + private final boolean bg; + private final boolean tp; + private final boolean rb; + private final boolean fluid; + + /** + * @param left margin from left edge + * @param top margin from top edge + * @param right margin from right edge + * @param bottom margin from bottom edge + * @param hp hit points + * @param drop id of an item the block will drop when destroyed + * @param coll true if block has collision + * @param bg true if block should be drawn behind player + * @param tp true if block is transparent and renderer should draw a block behind it + * @param rb true if block should break when there is no block with collision under it + * @param fluid true if fluid + * @param meta extra info for storing + * @param tex block's texture + */ + public Block(int left, int top, int right, int bottom, int hp, String drop, boolean coll, boolean bg, boolean tp, + boolean rb, boolean fluid, String meta, @CheckForNull Sprite tex) { this.x = left; this.y = top; this.w = 16 - right - left; @@ -28,7 +53,9 @@ public class Block { this.fluid = fluid; this.meta = meta; this.tex = tex; - if (this.tex != null) this.tex.flip(false, true); + if (this.tex != null) { + this.tex.flip(false, true); + } } public boolean hasCollision() { @@ -59,11 +86,12 @@ public class Block { return !drop.equals("none"); } - public Sprite getTex() { + public Sprite getTexture() { + assert tex != null; return tex; } - public Rectangle getRect(int x, int y) { + public Rectangle getRectangle(int x, int y) { x *= 16; y *= 16; return new Rectangle(x + this.x, y + this.y, w, h);