DEADSOFTWARE

e8ed1e752cd33e1990bd6c08a0dc12345bab5248
[cavedroid.git] / core / src / ru / deadsoftware / cavedroid / game / objects / Block.kt
1 @file:Suppress("DeprecatedCallableAddReplaceWith")
3 package ru.deadsoftware.cavedroid.game.objects
5 import com.badlogic.gdx.graphics.g2d.Sprite
6 import com.badlogic.gdx.math.Rectangle
8 private const val DEPRECATION_MESSAGE =
9 "Deprecated since moved to Kotlin. Use generated getter or kotlin property access."
11 /**
12 * @param left margin from left edge
13 * @param top margin from top edge
14 * @param right margin from right edge
15 * @param bottom margin from bottom edge
16 * @param hp hit points
17 * @param drop id of an item the block will drop when destroyed
18 * @param collision true if block has collision
19 * @param background true if block should be drawn behind player
20 * @param transparent true if block is transparent and renderer should draw a block behind it
21 * @param requiresBlock true if block should break when there is no block with collision under it
22 * @param fluid true if fluid
23 * @param meta extra info for storing
24 * @param sprite block's texture
25 */
26 data class Block(
27 val left: Int,
28 val top: Int,
29 val right: Int,
30 val bottom: Int,
31 val hp: Int,
32 val drop: String,
33 val collision: Boolean,
34 val background: Boolean,
35 val transparent: Boolean,
36 val requiresBlock: Boolean,
37 val fluid: Boolean,
38 val meta: String,
39 val sprite: Sprite?
40 ) {
42 init {
43 sprite?.flip(false, true)
44 }
46 val width = 16 - right - left
47 val height = 16 - top - bottom
49 fun getRectangle(x: Int, y: Int) =
50 Rectangle(x * 16f + left, y * 16f + this.top, width.toFloat(), height.toFloat())
52 fun requireSprite() = sprite ?: throw IllegalStateException("Sprite is null")
54 fun hasDrop() = drop != "none"
56 fun toJump() = top < 8 && collision
58 @Deprecated(DEPRECATION_MESSAGE)
59 fun hasCollision() = collision
61 @Deprecated(DEPRECATION_MESSAGE)
62 fun isBackground() = background
64 @Deprecated(DEPRECATION_MESSAGE)
65 fun isTransparent() = transparent
67 @Deprecated(DEPRECATION_MESSAGE)
68 fun isFluid() = fluid
70 @Deprecated(DEPRECATION_MESSAGE)
71 fun requiresBlock() = requiresBlock
73 @Deprecated("Was renamed to Sprite to comply with variable type.", ReplaceWith("getSprite()"))
74 fun getTexture() = sprite
76 }