DEADSOFTWARE

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