DEADSOFTWARE

Fix codestyle
[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 private final Sprite tex;
19 private final boolean coll;
20 private final boolean bg;
21 private final boolean tp;
22 private final boolean rb;
23 private final boolean fluid;
25 /**
26 * @param left margin from left edge
27 * @param top margin from top edge
28 * @param right margin from right edge
29 * @param bottom margin from bottom edge
30 * @param hp hit points
31 * @param drop id of an item the block will drop when destroyed
32 * @param coll true if block has collision
33 * @param bg true if block should be drawn behind player
34 * @param tp true if block is transparent and renderer should draw a block behind it
35 * @param rb true if block should break when there is no block with collision under it
36 * @param fluid true if fluid
37 * @param meta extra info for storing
38 * @param tex block's texture
39 */
40 public Block(int left, int top, int right, int bottom, int hp, String drop, boolean coll, boolean bg, boolean tp,
41 boolean rb, boolean fluid, String meta, @CheckForNull Sprite tex) {
42 this.x = left;
43 this.y = top;
44 this.w = 16 - right - left;
45 this.h = 16 - top - bottom;
46 this.hp = hp;
47 this.drop = drop;
48 this.coll = coll;
49 this.bg = bg;
50 this.tp = tp;
51 this.rb = rb;
52 this.fluid = fluid;
53 this.meta = meta;
54 this.tex = tex;
55 if (this.tex != null) {
56 this.tex.flip(false, true);
57 }
58 }
60 public boolean hasCollision() {
61 return coll;
62 }
64 public boolean isBackground() {
65 return bg;
66 }
68 public boolean isTransparent() {
69 return tp;
70 }
72 public boolean requiresBlock() {
73 return rb;
74 }
76 public int getHp() {
77 return hp;
78 }
80 public String getDrop() {
81 return drop;
82 }
84 public boolean hasDrop() {
85 return !drop.equals("none");
86 }
88 public Sprite getTex() {
89 return tex;
90 }
92 public Rectangle getRect(int x, int y) {
93 x *= 16;
94 y *= 16;
95 return new Rectangle(x + this.x, y + this.y, w, h);
96 }
98 public boolean isFluid() {
99 return fluid;
102 public String getMeta() {
103 return meta;
106 public boolean toJump() {
107 return (y < 8 && coll);