From: fredboy Date: Sun, 21 Apr 2024 16:30:28 +0000 (+0700) Subject: Add top slabs X-Git-Tag: alpha0.6.0~3 X-Git-Url: http://deadsoftware.ru/gitweb?a=commitdiff_plain;h=8b34480aaaf0112671d319accff573030079c7b6;p=cavedroid.git Add top slabs --- diff --git a/android/assets/json/game_items.json b/android/assets/json/game_items.json index 5600fb2..25b8db3 100644 --- a/android/assets/json/game_items.json +++ b/android/assets/json/game_items.json @@ -340,7 +340,7 @@ "drop": "iron_block", "texture": "iron_block" }, - "stone_slab": { + "stone_slab_bottom": { "id": 51, "top": 8, "sprite_top": 8, @@ -349,15 +349,29 @@ "drop": "stone_slab", "meta": "slab", "texture": "stone_slab", - "full_block": "double_stone_slab" + "full_block": "double_stone_slab", + "other_part": "stone_slab_top" + }, + "stone_slab_top": { + "id": 51, + "hp": 600, + "bottom": 8, + "sprite_bottom": 8, + "transparent": true, + "drop": "stone_slab", + "meta": "slab", + "texture": "stone_slab", + "full_block": "double_stone_slab", + "other_part": "stone_slab_bottom" }, "double_stone_slab": { "id": 52, "hp": 600, "drop": "stone_slab", + "drop_count": 2, "texture": "stone_slab" }, - "sandstone_slab": { + "sandstone_slab_bottom": { "id": 53, "top": 8, "sprite_top": 8, @@ -366,9 +380,22 @@ "drop": "sandstone_slab", "meta": "slab", "texture": "sandstone", - "full_block": "sandstone" + "full_block": "sandstone", + "other_part": "sandstone_slab_top" }, - "oak_slab": { + "sandstone_slab_top": { + "id": 53, + "bottom": 8, + "sprite_bottom": 8, + "hp": 600, + "transparent": true, + "drop": "sandstone_slab", + "meta": "slab", + "texture": "sandstone", + "full_block": "sandstone", + "other_part": "sandstone_slab_bottom" + }, + "oak_slab_bottom": { "id": 54, "top": 8, "sprite_top": 8, @@ -377,17 +404,46 @@ "drop": "oak_slab", "meta": "slab", "texture": "planks_oak", - "full_block": "planks_oak" + "full_block": "planks_oak", + "other_part": "oak_slab_top" }, - "cobblestone_slab": { + "oak_slab_top": { + "id": 54, + "bottom": 8, + "sprite_bottom": 8, + "hp": 180, + "transparent": true, + "drop": "oak_slab", + "meta": "slab", + "texture": "planks_oak", + "full_block": "planks_oak", + "other_part": "oak_slab_bottom" + }, + "cobblestone_slab_bottom": { "id": 55, "top": 8, + "sprite_top": 8, "hp": 600, "transparent": true, + "meta": "slab", "drop": "cobblestone_slab", - "texture": "cobblestone" + "texture": "cobblestone", + "full_block": "cobblestone", + "other_part": "cobblestone_slab_top" }, - "brick_slab": { + "cobblestone_slab_top": { + "id": 55, + "bottom": 8, + "sprite_bottom": 8, + "hp": 600, + "transparent": true, + "meta": "slab", + "drop": "cobblestone_slab", + "texture": "cobblestone", + "full_block": "cobblestone", + "other_part": "cobblestone_slab_bottom" + }, + "brick_slab_bottom": { "id": 56, "top": 8, "sprite_top": 8, @@ -396,7 +452,20 @@ "drop": "brick_slab", "meta": "slab", "texture": "bricks", - "full_block": "bricks" + "full_block": "bricks", + "other_part": "brick_slab_top" + }, + "brick_slab_top": { + "id": 56, + "bottom": 8, + "sprite_bottom": 8, + "hp": 600, + "transparent": true, + "drop": "brick_slab", + "meta": "slab", + "texture": "bricks", + "full_block": "bricks", + "other_part": "brick_slab_bottom" }, "stonebrick": { "id": 57, @@ -404,7 +473,7 @@ "drop": "stonebrick", "texture": "stonebrick" }, - "stonebrick_slab": { + "stonebrick_slab_bottom": { "id": 58, "top": 8, "sprite_top": 8, @@ -413,7 +482,20 @@ "drop": "stonebrick_slab", "meta": "slab", "texture": "stonebrick", - "full_block": "stonebrick" + "full_block": "stonebrick", + "other_part": "stonebrick_slab_top" + }, + "stonebrick_slab_top": { + "id": 58, + "bottom": 8, + "sprite_bottom": 8, + "hp": 450, + "transparent": true, + "drop": "stonebrick_slab", + "meta": "slab", + "texture": "stonebrick", + "full_block": "stonebrick", + "other_part": "brick_slab_bottom" }, "cactus": { "id": 59, @@ -820,32 +902,42 @@ "stone_slab": { "id": 47, "name": "Stone Slab", - "type": "block", - "texture": "stone_slab" + "type": "slab", + "texture": "stone_slab", + "top_slab_block": "stone_slab_top", + "bottom_slab_block": "stone_slab_bottom" }, "sandstone_slab": { "id": 48, "name": "Sandstone Slab", - "type": "block", - "texture": "sandstone_slab" + "type": "slab", + "texture": "sandstone_slab", + "top_slab_block": "sandstone_slab_top", + "bottom_slab_block": "sandstone_slab_bottom" }, "oak_slab": { "id": 49, "name": "Oak Slab", - "type": "block", - "texture": "oak_slab" + "type": "slab", + "texture": "oak_slab", + "top_slab_block": "oak_slab_top", + "bottom_slab_block": "oak_slab_bottom" }, "cobblestone_slab": { "id": 50, "name": "Cobblestone Slab", - "type": "block", - "texture": "cobblestone_slab" + "type": "slab", + "texture": "cobblestone_slab", + "top_slab_block": "cobblestone_slab_top", + "bottom_slab_block": "cobblestone_slab_bottom" }, "brick_slab": { "id": 51, "name": "Brick Slab", - "type": "block", - "texture": "brick_slab" + "type": "slab", + "texture": "brick_slab", + "top_slab_block": "brick_slab_top", + "bottom_slab_block": "brick_slab_bottom" }, "stonebrick": { "id": 52, @@ -856,8 +948,10 @@ "stonebrick_slab": { "id": 53, "name": "Stone Brick Slab", - "type": "block", - "texture": "stonebrick_slab" + "type": "slab", + "texture": "stonebrick_slab", + "top_slab_block": "stonebrick_slab_top", + "bottom_slab_block": "stonebrick_slab_bottom" }, "cactus": { "id": 54, diff --git a/android/assets/json/texture_regions.json b/android/assets/json/texture_regions.json index 9254986..01507d4 100644 --- a/android/assets/json/texture_regions.json +++ b/android/assets/json/texture_regions.json @@ -37,57 +37,6 @@ "h": 26 } }, - "break": { - "break_0": { - "w": 16, - "h": 16 - }, - "break_1": { - "x": 16, - "w": 16, - "h": 16 - }, - "break_2": { - "x": 32, - "w": 16, - "h": 16 - }, - "break_3": { - "x": 48, - "w": 16, - "h": 16 - }, - "break_4": { - "x": 64, - "w": 16, - "h": 16 - }, - "break_5": { - "x": 80, - "w": 16, - "h": 16 - }, - "break_6": { - "x": 96, - "w": 16, - "h": 16 - }, - "break_7": { - "x": 112, - "w": 16, - "h": 16 - }, - "break_8": { - "x": 128, - "w": 16, - "h": 16 - }, - "break_9": { - "x": 144, - "w": 16, - "h": 16 - } - }, "allitems": { "creative": { "w": 176, diff --git a/core/src/ru/deadsoftware/cavedroid/game/GameItemsHolder.kt b/core/src/ru/deadsoftware/cavedroid/game/GameItemsHolder.kt index 075af6f..7a7ccab 100644 --- a/core/src/ru/deadsoftware/cavedroid/game/GameItemsHolder.kt +++ b/core/src/ru/deadsoftware/cavedroid/game/GameItemsHolder.kt @@ -49,7 +49,18 @@ class GameItemsHolder @Inject constructor( } dtoMap.forEach { (key, dto) -> - itemsMap[key] = itemMapper.map(key, dto, blocksMap[key]) + try { + itemsMap[key] = itemMapper.map( + key = key, + dto = dto, + block = blocksMap[key], + slabTopBlock = blocksMap[dto.topSlabBlock] as? Block.Slab, + slabBottomBlock = blocksMap[dto.bottomSlabBlock] as? Block.Slab + ) + } catch (e: Exception) { + Gdx.app.error(TAG, "Failed to map item $key. Reason: ${e.message}") + e.printStackTrace() + } } fallbackItem = itemsMap[FALLBACK_ITEM_KEY] diff --git a/core/src/ru/deadsoftware/cavedroid/game/actions/PlaceBlockActionsModule.kt b/core/src/ru/deadsoftware/cavedroid/game/actions/PlaceBlockActionsModule.kt index 23f711a..f2c5a23 100644 --- a/core/src/ru/deadsoftware/cavedroid/game/actions/PlaceBlockActionsModule.kt +++ b/core/src/ru/deadsoftware/cavedroid/game/actions/PlaceBlockActionsModule.kt @@ -8,6 +8,7 @@ import ru.deadsoftware.cavedroid.game.GameScope import ru.deadsoftware.cavedroid.game.actions.placeblock.IPlaceBlockAction import ru.deadsoftware.cavedroid.game.actions.placeblock.PlaceBlockItemToBackgroundAction import ru.deadsoftware.cavedroid.game.actions.placeblock.PlaceBlockItemToForegroundAction +import ru.deadsoftware.cavedroid.game.actions.placeblock.PlaceSlabAction @Module class PlaceBlockActionsModule { @@ -28,4 +29,12 @@ class PlaceBlockActionsModule { return action } + @Binds + @IntoMap + @StringKey(PlaceSlabAction.ACTION_KEY) + @GameScope + fun bindPlaceSlabAction(action: PlaceSlabAction): IPlaceBlockAction { + return action + } + } \ No newline at end of file diff --git a/core/src/ru/deadsoftware/cavedroid/game/actions/placeblock/PlaceBlockItemToForegroundAction.kt b/core/src/ru/deadsoftware/cavedroid/game/actions/placeblock/PlaceBlockItemToForegroundAction.kt index 1f74448..d409a80 100644 --- a/core/src/ru/deadsoftware/cavedroid/game/actions/placeblock/PlaceBlockItemToForegroundAction.kt +++ b/core/src/ru/deadsoftware/cavedroid/game/actions/placeblock/PlaceBlockItemToForegroundAction.kt @@ -8,10 +8,15 @@ import javax.inject.Inject @GameScope class PlaceBlockItemToForegroundAction @Inject constructor( private val gameWorld: GameWorld, + private val placeSlabAction: PlaceSlabAction, ) : IPlaceBlockAction { override fun place(placeable: Item.Placeable, x: Int, y: Int) { - gameWorld.placeToForeground(x, y, placeable.block) + if (placeable.isSlab()) { + placeSlabAction.place(placeable, x, y) + } else { + gameWorld.placeToForeground(x, y, placeable.block) + } } companion object { diff --git a/core/src/ru/deadsoftware/cavedroid/game/actions/placeblock/PlaceSlabAction.kt b/core/src/ru/deadsoftware/cavedroid/game/actions/placeblock/PlaceSlabAction.kt new file mode 100644 index 0000000..079d225 --- /dev/null +++ b/core/src/ru/deadsoftware/cavedroid/game/actions/placeblock/PlaceSlabAction.kt @@ -0,0 +1,33 @@ +package ru.deadsoftware.cavedroid.game.actions.placeblock + +import com.badlogic.gdx.Gdx +import ru.deadsoftware.cavedroid.game.GameItemsHolder +import ru.deadsoftware.cavedroid.game.GameScope +import ru.deadsoftware.cavedroid.game.mobs.MobsController +import ru.deadsoftware.cavedroid.game.model.item.Item +import ru.deadsoftware.cavedroid.game.world.GameWorld +import javax.inject.Inject +import kotlin.random.Random + +@GameScope +class PlaceSlabAction @Inject constructor( + private val gameWorld: GameWorld, + private val mobsController: MobsController, + private val gameItemsHolder: GameItemsHolder, +) : IPlaceBlockAction { + + override fun place(placeable: Item.Placeable, x: Int, y: Int) { + if (placeable !is Item.Slab) { + Gdx.app.debug(TAG, "Place slab action called on ${placeable.params.key} which is not a slab") + return + } + + val slabPart = if (Random.nextBoolean()) placeable.topPartBlock else placeable.bottomPartBlock + gameWorld.placeToForeground(x, y, slabPart) + } + + companion object { + private const val TAG = "PlaceSlabAction" + const val ACTION_KEY = "place_slab" + } +} \ No newline at end of file diff --git a/core/src/ru/deadsoftware/cavedroid/game/model/block/Block.kt b/core/src/ru/deadsoftware/cavedroid/game/model/block/Block.kt index 4a0c31a..9669a53 100644 --- a/core/src/ru/deadsoftware/cavedroid/game/model/block/Block.kt +++ b/core/src/ru/deadsoftware/cavedroid/game/model/block/Block.kt @@ -16,8 +16,8 @@ sealed class Block { val width: Float get() = 16f - params.collisionMargins.left - params.collisionMargins.right val height: Float get() = 16f - params.collisionMargins.top - params.collisionMargins.bottom - private val spriteWidth: Float get() = 16f - params.spriteMargins.left - params.spriteMargins.right - private val spriteHeight: Float get() = 16f - params.spriteMargins.top - params.spriteMargins.bottom + val spriteWidth: Float get() = 16f - params.spriteMargins.left - params.spriteMargins.right + val spriteHeight: Float get() = 16f - params.spriteMargins.top - params.spriteMargins.bottom private var animation: Array? = null @@ -129,6 +129,7 @@ sealed class Block { data class Slab( override val params: CommonBlockParams, val fullBlockKey: String, + val otherPartBlockKey: String, ): Block() sealed class Fluid: Block() { diff --git a/core/src/ru/deadsoftware/cavedroid/game/model/dto/BlockDto.kt b/core/src/ru/deadsoftware/cavedroid/game/model/dto/BlockDto.kt index ae1bfba..e30ae52 100644 --- a/core/src/ru/deadsoftware/cavedroid/game/model/dto/BlockDto.kt +++ b/core/src/ru/deadsoftware/cavedroid/game/model/dto/BlockDto.kt @@ -27,4 +27,5 @@ data class BlockDto( @SerialName("drop_count") val dropCount: Int = 1, @SerialName("full_block") val fullBlock: String? = null, @SerialName("state") val state: Int? = null, + @SerialName("other_part") val otherPart: String? = null, ) diff --git a/core/src/ru/deadsoftware/cavedroid/game/model/dto/ItemDto.kt b/core/src/ru/deadsoftware/cavedroid/game/model/dto/ItemDto.kt index d46eddd..4d57886 100644 --- a/core/src/ru/deadsoftware/cavedroid/game/model/dto/ItemDto.kt +++ b/core/src/ru/deadsoftware/cavedroid/game/model/dto/ItemDto.kt @@ -14,4 +14,6 @@ data class ItemDto( @SerialName("action_key") val actionKey: String? = null, @SerialName("mob_damage_multiplier") val mobDamageMultiplier: Float = 1f, @SerialName("block_damage_multiplier") val blockDamageMultiplier: Float = 1f, + @SerialName("top_slab_block") val topSlabBlock: String? = null, + @SerialName("bottom_slab_block") val bottomSlabBlock: String? = null, ) diff --git a/core/src/ru/deadsoftware/cavedroid/game/model/item/Item.kt b/core/src/ru/deadsoftware/cavedroid/game/model/item/Item.kt index 80a9625..b56f068 100644 --- a/core/src/ru/deadsoftware/cavedroid/game/model/item/Item.kt +++ b/core/src/ru/deadsoftware/cavedroid/game/model/item/Item.kt @@ -1,8 +1,8 @@ package ru.deadsoftware.cavedroid.game.model.item -import com.badlogic.gdx.Gdx import com.badlogic.gdx.graphics.g2d.Sprite import ru.deadsoftware.cavedroid.game.model.block.Block +import ru.deadsoftware.cavedroid.game.model.block.Block as BlockModel import kotlin.contracts.ExperimentalContracts import kotlin.contracts.contract @@ -30,6 +30,12 @@ sealed class Item { return this is Placeable } + fun isSlab(): Boolean { + contract { returns(true) implies (this@Item is Slab) } + return this is Slab + } + + fun isTool(): Boolean { contract { returns(true) implies (this@Item is Tool) } return this is Tool @@ -54,6 +60,11 @@ sealed class Item { abstract val useActionKey: String } + sealed class Placeable : Item() { + abstract val block: BlockModel + override val sprite: Sprite get() = block.sprite + } + data class None( override val params: CommonItemParams, ): Item() { @@ -61,11 +72,17 @@ sealed class Item { get() = throw IllegalAccessException("Trying to get sprite of None") } - data class Placeable( + data class Block( override val params: CommonItemParams, - val block: Block - ) : Item() { - override val sprite: Sprite get() = block.sprite + override val block: BlockModel + ) : Placeable() + + data class Slab( + override val params: CommonItemParams, + val topPartBlock: BlockModel.Slab, + val bottomPartBlock: BlockModel.Slab + ) : Placeable() { + override val block get() = bottomPartBlock } data class Sword( diff --git a/core/src/ru/deadsoftware/cavedroid/game/model/mapper/BlockMapper.kt b/core/src/ru/deadsoftware/cavedroid/game/model/mapper/BlockMapper.kt index bc29783..a122754 100644 --- a/core/src/ru/deadsoftware/cavedroid/game/model/mapper/BlockMapper.kt +++ b/core/src/ru/deadsoftware/cavedroid/game/model/mapper/BlockMapper.kt @@ -18,7 +18,7 @@ class BlockMapper @Inject constructor() { return when (dto.meta) { "water" -> Water(commonBlockParams, requireNotNull(dto.state)) "lava" -> Lava(commonBlockParams, requireNotNull(dto.state)) - "slab" -> Slab(commonBlockParams, requireNotNull(dto.fullBlock)) + "slab" -> Slab(commonBlockParams, requireNotNull(dto.fullBlock), requireNotNull(dto.otherPart)) "none" -> None(commonBlockParams) else -> Normal(commonBlockParams) } diff --git a/core/src/ru/deadsoftware/cavedroid/game/model/mapper/ItemMapper.kt b/core/src/ru/deadsoftware/cavedroid/game/model/mapper/ItemMapper.kt index ad79cbd..7646e22 100644 --- a/core/src/ru/deadsoftware/cavedroid/game/model/mapper/ItemMapper.kt +++ b/core/src/ru/deadsoftware/cavedroid/game/model/mapper/ItemMapper.kt @@ -15,14 +15,15 @@ import javax.inject.Inject @Reusable class ItemMapper @Inject constructor() { - fun map(key: String, dto: ItemDto, block: Block?): Item { + fun map(key: String, dto: ItemDto, block: Block?, slabTopBlock: Block.Slab?, slabBottomBlock: Block.Slab?): Item { val params = mapCommonParams(key, dto) return when (dto.type) { "bucket" -> Bucket(params, requireNotNull(loadSprite(dto)), requireNotNull(dto.actionKey)) "shovel" -> Shovel(params, requireNotNull(loadSprite(dto)), dto.mobDamageMultiplier, dto.blockDamageMultiplier) "sword" -> Sword(params, requireNotNull(loadSprite(dto)), dto.mobDamageMultiplier, dto.blockDamageMultiplier) - "block" -> Placeable(params, requireNotNull(block)) + "block" -> Block(params, requireNotNull(block)) + "slab" -> Slab(params, requireNotNull(slabTopBlock), requireNotNull(slabBottomBlock)) "none" -> None(params) else -> throw IllegalArgumentException("Unknown item type ${dto.type}") } diff --git a/core/src/ru/deadsoftware/cavedroid/game/render/BlocksRenderer.kt b/core/src/ru/deadsoftware/cavedroid/game/render/BlocksRenderer.kt index ae243a3..60a9ef8 100644 --- a/core/src/ru/deadsoftware/cavedroid/game/render/BlocksRenderer.kt +++ b/core/src/ru/deadsoftware/cavedroid/game/render/BlocksRenderer.kt @@ -1,11 +1,11 @@ package ru.deadsoftware.cavedroid.game.render +import com.badlogic.gdx.graphics.g2d.Sprite import com.badlogic.gdx.graphics.g2d.SpriteBatch import com.badlogic.gdx.graphics.g2d.TextureRegion import com.badlogic.gdx.graphics.glutils.ShapeRenderer import com.badlogic.gdx.math.MathUtils import com.badlogic.gdx.math.Rectangle -import ru.deadsoftware.cavedroid.game.GameInput import ru.deadsoftware.cavedroid.game.mobs.MobsController import ru.deadsoftware.cavedroid.game.model.block.Block import ru.deadsoftware.cavedroid.game.world.GameWorld @@ -22,12 +22,11 @@ abstract class BlocksRenderer( private val Block.canSeeThrough get() = isNone() || params.isTransparent - private fun blockDamageTexture(index: Int): TextureRegion? { + private fun blockDamageSprite(index: Int): Sprite? { if (index !in 0..MAX_BLOCK_DAMAGE_INDEX) { return null } - val textureKey = "$BLOCK_DAMAGE_TEXTURE_PREFIX$index" - return Assets.textureRegions[textureKey] + return Assets.blockDamageSprites[index] } protected fun drawBlockDamage(spriteBatch: SpriteBatch, viewport: Rectangle) { @@ -44,10 +43,16 @@ abstract class BlocksRenderer( val index = (MAX_BLOCK_DAMAGE_INDEX.toFloat() * (blockDamage.toFloat() / block.params.hitPoints.toFloat())) .let(MathUtils::floor) - val texture = blockDamageTexture(index) ?: return + val sprite = blockDamageSprite(index) ?: return if (gameWorld.hasForeAt(cursorX, cursorY) != background) { - spriteBatch.draw(texture, cursorX.px - viewport.x, cursorY.px - viewport.y) + sprite.setBounds( + /* x = */ cursorX.px - viewport.x + block.params.spriteMargins.left, + /* y = */ cursorY.px - viewport.y + block.params.spriteMargins.top, + /* width = */ block.spriteWidth, + /* height = */ block.spriteHeight + ) + sprite.draw(spriteBatch) } } @@ -97,7 +102,6 @@ abstract class BlocksRenderer( } companion object { - private const val BLOCK_DAMAGE_TEXTURE_PREFIX = "break_" private const val MAX_BLOCK_DAMAGE_INDEX = 10 } diff --git a/core/src/ru/deadsoftware/cavedroid/game/world/GameWorld.java b/core/src/ru/deadsoftware/cavedroid/game/world/GameWorld.java index 91793c8..32fef76 100644 --- a/core/src/ru/deadsoftware/cavedroid/game/world/GameWorld.java +++ b/core/src/ru/deadsoftware/cavedroid/game/world/GameWorld.java @@ -114,6 +114,15 @@ public class GameWorld { } } + private boolean isSameSlab(Block slab1, Block slab2) { + if (!(slab1 instanceof Block.Slab) || !(slab2 instanceof Block.Slab)) { + return false; + } + + return slab1.getParams().getKey().equals(((Block.Slab) slab2).getOtherPartBlockKey()) + || slab1.getParams().getKey().equals(slab2.getParams().getKey()); + } + public boolean hasForeAt(int x, int y) { return getMap(x, y, 0) != mGameItemsHolder.getFallbackBlock(); } @@ -145,7 +154,7 @@ public class GameWorld { public void placeToForeground(int x, int y, Block value) { if (!hasForeAt(x, y) || value == mGameItemsHolder.getFallbackBlock() || !getForeMap(x, y).hasCollision()) { setForeMap(x, y, value); - } else if (value instanceof Block.Slab && getForeMap(x, y) == value) { + } else if (value instanceof Block.Slab && isSameSlab(value, getForeMap(x, y))) { setForeMap(x, y, mGameItemsHolder.getBlock(((Block.Slab) value).getFullBlockKey())); } } diff --git a/core/src/ru/deadsoftware/cavedroid/misc/Assets.java b/core/src/ru/deadsoftware/cavedroid/misc/Assets.java index a6318d7..abec0a0 100644 --- a/core/src/ru/deadsoftware/cavedroid/misc/Assets.java +++ b/core/src/ru/deadsoftware/cavedroid/misc/Assets.java @@ -19,12 +19,17 @@ import java.util.Map; public class Assets { + private static final int BLOCK_DAMAGE_STAGES = 10; + public static final JsonReader jsonReader = new JsonReader(); private static final List loadedTextures = new LinkedList<>(); public static final Sprite[][] playerSprite = new Sprite[2][4]; public static final Sprite[][] pigSprite = new Sprite[2][2]; + + public static final Sprite[] blockDamageSprites = new Sprite[10]; + public static final HashMap textureRegions = new HashMap<>(); public static final ArrayMap guiMap = new ArrayMap<>(); private static final GlyphLayout glyphLayout = new GlyphLayout(); @@ -71,6 +76,13 @@ public class Assets { } } + private static void loadBlockDamage(AssetLoader assetLoader) { + final Texture blockDamageTexture = loadTexture(assetLoader.getAssetHandle("break.png")); + for (int i = 0; i < BLOCK_DAMAGE_STAGES; i++) { + blockDamageSprites[i] = new Sprite(flippedRegion(blockDamageTexture, i * 16, 0, 16, 16)); + } + } + private static void setPlayerHeadOrigin() { for (Sprite[] sprites : playerSprite) { sprites[0].setOrigin(sprites[0].getWidth() / 2, sprites[0].getHeight()); @@ -119,6 +131,7 @@ public class Assets { public static void load(final AssetLoader assetLoader) { loadMob(assetLoader, playerSprite, "char"); loadMob(assetLoader, pigSprite, "pig"); + loadBlockDamage(assetLoader); loadJSON(assetLoader); loadBlocks(assetLoader); loadItems(assetLoader);