DEADSOFTWARE

0800b5b5cb8d8f713aef6e017a4c7af355675c79
[cavedroid.git] / core / src / ru / deadsoftware / cavedroid / game / objects / Block.java
1 package ru.deadsoftware.cavedroid.game.objects;
3 import com.badlogic.gdx.graphics.g2d.Sprite;
4 import com.badlogic.gdx.math.Rectangle;
6 import javax.annotation.CheckForNull;
8 public class Block {
10 private final int x;
11 private final int y;
12 private final int w;
13 private final int h;
14 private final int hp;
15 private final String drop;
16 private final String meta;
17 @CheckForNull
18 private final Sprite tex;
20 private final boolean coll;
21 private final boolean bg;
22 private final boolean tp;
23 private final boolean rb;
24 private final boolean fluid;
26 /**
27 * @param left margin from left edge
28 * @param top margin from top edge
29 * @param right margin from right edge
30 * @param bottom margin from bottom edge
31 * @param hp hit points
32 * @param drop id of an item the block will drop when destroyed
33 * @param coll true if block has collision
34 * @param bg true if block should be drawn behind player
35 * @param tp true if block is transparent and renderer should draw a block behind it
36 * @param rb true if block should break when there is no block with collision under it
37 * @param fluid true if fluid
38 * @param meta extra info for storing
39 * @param tex block's texture
40 */
41 public Block(int left, int top, int right, int bottom, int hp, String drop, boolean coll, boolean bg, boolean tp,
42 boolean rb, boolean fluid, String meta, @CheckForNull Sprite tex) {
43 this.x = left;
44 this.y = top;
45 this.w = 16 - right - left;
46 this.h = 16 - top - bottom;
47 this.hp = hp;
48 this.drop = drop;
49 this.coll = coll;
50 this.bg = bg;
51 this.tp = tp;
52 this.rb = rb;
53 this.fluid = fluid;
54 this.meta = meta;
55 this.tex = tex;
56 if (this.tex != null) {
57 this.tex.flip(false, true);
58 }
59 }
61 public boolean hasCollision() {
62 return coll;
63 }
65 public boolean isBackground() {
66 return bg;
67 }
69 public boolean isTransparent() {
70 return tp;
71 }
73 public boolean requiresBlock() {
74 return rb;
75 }
77 public int getHp() {
78 return hp;
79 }
81 public String getDrop() {
82 return drop;
83 }
85 public boolean hasDrop() {
86 return !drop.equals("none");
87 }
89 public Sprite getTexture() {
90 assert tex != null;
91 return tex;
92 }
94 public Rectangle getRectangle(int x, int y) {
95 x *= 16;
96 y *= 16;
97 return new Rectangle(x + this.x, y + this.y, w, h);
98 }
100 public boolean isFluid() {
101 return fluid;
104 public String getMeta() {
105 return meta;
108 public boolean toJump() {
109 return (y < 8 && coll);