DEADSOFTWARE

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