summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 1e28524)
raw | patch | inline | side by side (parent: 1e28524)
author | fredboy <fredboy@protonmail.com> | |
Sun, 19 May 2024 12:57:04 +0000 (19:57 +0700) | ||
committer | fredboy <fredboy@protonmail.com> | |
Sun, 19 May 2024 12:57:04 +0000 (19:57 +0700) |
14 files changed:
index 5c1157690a9141876f5d96311f711677e3a70d14..245ebb04c8b169875bbab55d0ff5c7e9e4a44ee8 100644 (file)
"drop": "sand",
"texture": "sand",
"tool_level": 0,
- "tool_type": "shovel"
+ "tool_type": "shovel",
+ "fallable": true
},
"gravel": {
"hp": 54,
"drop": "gravel",
"texture": "gravel",
"tool_level": 0,
- "tool_type": "shovel"
+ "tool_type": "shovel",
+ "fallable": true
},
"gold_ore": {
"hp": 900,
diff --git a/core/src/ru/deadsoftware/cavedroid/game/actions/updateblock/UpdateBedLeftAction.kt b/core/src/ru/deadsoftware/cavedroid/game/actions/updateblock/UpdateBedLeftAction.kt
index 55075508c20897c4cb75651d22871eda5e79d547..c23b80f310e637497e0bd4fea6f3e92ef2cf3c7e 100644 (file)
import ru.deadsoftware.cavedroid.game.GameItemsHolder
import ru.deadsoftware.cavedroid.game.GameScope
-import ru.deadsoftware.cavedroid.game.mobs.FallingGravel
-import ru.deadsoftware.cavedroid.game.mobs.MobsController
import ru.deadsoftware.cavedroid.game.world.GameWorld
import ru.deadsoftware.cavedroid.misc.annotations.multibinding.BindUpdateBlockAction
import javax.inject.Inject
diff --git a/core/src/ru/deadsoftware/cavedroid/game/actions/updateblock/UpdateBedRightAction.kt b/core/src/ru/deadsoftware/cavedroid/game/actions/updateblock/UpdateBedRightAction.kt
index 42f551ed16505453c12711d9acebd3c02d98d6ca..cd8b2d37fbb8fcb6c8f36ac65212e66e940ef36b 100644 (file)
import ru.deadsoftware.cavedroid.game.GameItemsHolder
import ru.deadsoftware.cavedroid.game.GameScope
-import ru.deadsoftware.cavedroid.game.mobs.FallingGravel
-import ru.deadsoftware.cavedroid.game.mobs.MobsController
import ru.deadsoftware.cavedroid.game.world.GameWorld
import ru.deadsoftware.cavedroid.misc.annotations.multibinding.BindUpdateBlockAction
import javax.inject.Inject
diff --git a/core/src/ru/deadsoftware/cavedroid/game/actions/updateblock/UpdateGravelAction.kt b/core/src/ru/deadsoftware/cavedroid/game/actions/updateblock/UpdateGravelAction.kt
+++ /dev/null
@@ -1,30 +0,0 @@
-package ru.deadsoftware.cavedroid.game.actions.updateblock
-
-import ru.deadsoftware.cavedroid.game.GameScope
-import ru.deadsoftware.cavedroid.game.mobs.FallingGravel
-import ru.deadsoftware.cavedroid.game.mobs.MobsController
-import ru.deadsoftware.cavedroid.game.world.GameWorld
-import ru.deadsoftware.cavedroid.misc.annotations.multibinding.BindUpdateBlockAction
-import javax.inject.Inject
-
-@GameScope
-@BindUpdateBlockAction(stringKey = UpdateGravelAction.BLOCK_KEY)
-class UpdateGravelAction @Inject constructor(
- private val gameWorld: GameWorld,
- private val mobsController: MobsController,
-) : IUpdateBlockAction {
-
- override fun update(x: Int, y: Int) {
- val shouldFall = gameWorld.getForeMap(x, y + 1).params.hasCollision.not()
-
- if (shouldFall) {
- gameWorld.resetForeMap(x, y)
- FallingGravel(x * 16f, y * 16f)
- .apply { attachToController(mobsController) }
- }
- }
-
- companion object {
- const val BLOCK_KEY = "gravel"
- }
-}
\ No newline at end of file
diff --git a/core/src/ru/deadsoftware/cavedroid/game/actions/updateblock/UpdateRequiresBlockAction.kt b/core/src/ru/deadsoftware/cavedroid/game/actions/updateblock/UpdateRequiresBlockAction.kt
index 05d986357aa0086a67b24b19dcc0301133022c5d..53f56e3ff682181133244d3eb0f3098e782b4687 100644 (file)
package ru.deadsoftware.cavedroid.game.actions.updateblock
import ru.deadsoftware.cavedroid.game.GameScope
+import ru.deadsoftware.cavedroid.game.mobs.FallingBlock
+import ru.deadsoftware.cavedroid.game.mobs.MobsController
import ru.deadsoftware.cavedroid.game.world.GameWorld
import ru.deadsoftware.cavedroid.misc.annotations.multibinding.BindUpdateBlockAction
+import ru.deadsoftware.cavedroid.misc.utils.px
import javax.inject.Inject
@GameScope
@BindUpdateBlockAction(stringKey = UpdateRequiresBlockAction.ACTION_KEY)
class UpdateRequiresBlockAction @Inject constructor(
private val gameWorld: GameWorld,
+ private val mobsController: MobsController,
) : IUpdateBlockAction {
override fun update(x: Int, y: Int) {
if (gameWorld.getForeMap(x, y + 1).params.hasCollision.not()) {
- gameWorld.destroyForeMap(x, y)
+ val block = gameWorld.getForeMap(x, y)
+
+ if (block.params.isFallable) {
+ gameWorld.resetForeMap(x, y)
+ FallingBlock(block.params.key, x.px, y.px)
+ .attachToController(mobsController)
+ } else {
+ gameWorld.destroyForeMap(x, y)
+ }
}
}
diff --git a/core/src/ru/deadsoftware/cavedroid/game/actions/updateblock/UpdateSandAction.kt b/core/src/ru/deadsoftware/cavedroid/game/actions/updateblock/UpdateSandAction.kt
+++ /dev/null
@@ -1,30 +0,0 @@
-package ru.deadsoftware.cavedroid.game.actions.updateblock
-
-import ru.deadsoftware.cavedroid.game.GameScope
-import ru.deadsoftware.cavedroid.game.mobs.FallingSand
-import ru.deadsoftware.cavedroid.game.mobs.MobsController
-import ru.deadsoftware.cavedroid.game.world.GameWorld
-import ru.deadsoftware.cavedroid.misc.annotations.multibinding.BindUpdateBlockAction
-import javax.inject.Inject
-
-@GameScope
-@BindUpdateBlockAction(stringKey = UpdateSandAction.BLOCK_KEY)
-class UpdateSandAction @Inject constructor(
- private val gameWorld: GameWorld,
- private val mobsController: MobsController,
-) : IUpdateBlockAction {
-
- override fun update(x: Int, y: Int) {
- val shouldFall = gameWorld.getForeMap(x, y + 1).params.hasCollision.not()
-
- if (shouldFall) {
- gameWorld.resetForeMap(x, y)
- FallingSand(x * 16f, y * 16f)
- .apply { attachToController(mobsController) }
- }
- }
-
- companion object {
- const val BLOCK_KEY = "sand"
- }
-}
\ No newline at end of file
diff --git a/core/src/ru/deadsoftware/cavedroid/game/mobs/FallingBlock.kt b/core/src/ru/deadsoftware/cavedroid/game/mobs/FallingBlock.kt
--- /dev/null
@@ -0,0 +1,53 @@
+package ru.deadsoftware.cavedroid.game.mobs
+
+import com.badlogic.gdx.graphics.g2d.SpriteBatch
+import ru.deadsoftware.cavedroid.game.GameItemsHolder
+import ru.deadsoftware.cavedroid.game.model.block.Block
+import ru.deadsoftware.cavedroid.game.world.GameWorld
+import ru.deadsoftware.cavedroid.misc.utils.bl
+import ru.deadsoftware.cavedroid.misc.utils.px
+
+class FallingBlock(
+ private val blockKey: String,
+ x: Float,
+ y: Float,
+) : Mob(x, y, 1.px, 1.px, Direction.RIGHT, Type.FALLING_BLOCK, Int.MAX_VALUE) {
+
+ @Transient
+ private var _block: Block? = null
+
+ init {
+ velocity.y = 1f
+ }
+
+ override fun changeDir() = Unit
+
+ override fun getSpeed() = 0f
+
+ override fun jump() = Unit
+
+ override fun ai(
+ gameWorld: GameWorld,
+ gameItemsHolder: GameItemsHolder,
+ mobsController: MobsController,
+ delta: Float
+ ) {
+ if (_block == null) {
+ _block = gameItemsHolder.getBlock(blockKey)
+ }
+
+ if (velocity.isZero) {
+ gameWorld.setForeMap(x.bl, y.bl, _block)
+ kill()
+ }
+ }
+
+ override fun draw(
+ spriteBatch: SpriteBatch,
+ x: Float,
+ y: Float,
+ delta: Float
+ ) {
+ _block?.draw(spriteBatch, x, y)
+ }
+}
\ No newline at end of file
diff --git a/core/src/ru/deadsoftware/cavedroid/game/mobs/FallingGravel.java b/core/src/ru/deadsoftware/cavedroid/game/mobs/FallingGravel.java
+++ /dev/null
@@ -1,72 +0,0 @@
-package ru.deadsoftware.cavedroid.game.mobs;
-
-import com.badlogic.gdx.Gdx;
-import com.badlogic.gdx.graphics.Texture;
-import com.badlogic.gdx.graphics.g2d.SpriteBatch;
-import com.badlogic.gdx.math.Vector2;
-import ru.deadsoftware.cavedroid.game.GameItemsHolder;
-import ru.deadsoftware.cavedroid.game.world.GameWorld;
-import ru.deadsoftware.cavedroid.misc.Assets;
-
-import javax.annotation.CheckForNull;
-
-/**
- * Falling gravel is actually a mob, that spawns in place of gravel when there is no block under it,
- * falls down to the next block and becomes a block of gravel again.
- */
-public class FallingGravel extends Mob {
-
- private static final String TAG = "FallingGravel";
-
- /**
- * Creates a FallingGravel mob at coordinates
- *
- * @param x X in pixels
- * @param y Y in pixels
- */
- public FallingGravel(float x, float y) {
- super(x, y, 16, 16, Direction.LEFT, Type.GRAVEL, Integer.MAX_VALUE);
- mVelocity = new Vector2(0, 1);
- }
-
- @Override
- public float getSpeed() {
- return 0;
- }
-
- @Override
- public void jump() {
- // no-op
- }
-
- @Override
- public void ai(GameWorld gameWorld, GameItemsHolder gameItemsHolder, MobsController mobsController, float delta) {
- if (mVelocity.isZero()) {
- gameWorld.setForeMap(getMapX(), getUpperMapY(), gameItemsHolder.getBlock("gravel"));
- kill();
- }
- }
-
- @Override
- public void changeDir() {
- }
-
- @Override
- public void damage(int damage) {
- // no-op
- }
-
- @Override
- public void draw(SpriteBatch spriteBatch, float x, float y, float delta) {
- @CheckForNull final Texture texture = Assets.blockTextures.get("gravel");
-
- if (texture == null) {
- Gdx.app.error(TAG, "Couldn't draw: texture not found");
- kill();
- return;
- }
-
- spriteBatch.draw(texture, x, y);
- }
-
-}
diff --git a/core/src/ru/deadsoftware/cavedroid/game/mobs/FallingSand.java b/core/src/ru/deadsoftware/cavedroid/game/mobs/FallingSand.java
+++ /dev/null
@@ -1,73 +0,0 @@
-package ru.deadsoftware.cavedroid.game.mobs;
-
-import com.badlogic.gdx.Gdx;
-import com.badlogic.gdx.graphics.Texture;
-import com.badlogic.gdx.graphics.g2d.SpriteBatch;
-import com.badlogic.gdx.math.Vector2;
-import ru.deadsoftware.cavedroid.game.GameItemsHolder;
-import ru.deadsoftware.cavedroid.game.world.GameWorld;
-import ru.deadsoftware.cavedroid.misc.Assets;
-
-import javax.annotation.CheckForNull;
-
-
-/**
- * Falling sand is actually a mob, that spawns in place of gravel when there is no block under it,
- * falls down to the next block and becomes a block of sand again.
- */
-public class FallingSand extends Mob {
-
- private static final String TAG = "FallingSand";
-
- /**
- * Creates a FallingSand mob at coordinates
- *
- * @param x X in pixels
- * @param y Y in pixels
- */
- public FallingSand(float x, float y) {
- super(x, y, 16, 16, Direction.LEFT, Type.SAND, Integer.MAX_VALUE);
- mVelocity = new Vector2(0, 1);
- }
-
- @Override
- public float getSpeed() {
- return 0;
- }
-
- @Override
- public void jump() {
- // no-op
- }
-
- @Override
- public void ai(GameWorld gameWorld, GameItemsHolder gameItemsHolder, MobsController mobsController, float delta) {
- if (mVelocity.isZero()) {
- gameWorld.setForeMap(getMapX(), getUpperMapY(), gameItemsHolder.getBlock("sand"));
- kill();
- }
- }
-
- @Override
- public void changeDir() {
- }
-
- @Override
- public void damage(int damage) {
- // no-op
- }
-
- @Override
- public void draw(SpriteBatch spriteBatch, float x, float y, float delta) {
- @CheckForNull final Texture texture = Assets.blockTextures.get("sand");
-
- if (texture == null) {
- Gdx.app.error(TAG, "Couldn't draw: texture not found");
- kill();
- return;
- }
-
- spriteBatch.draw(texture, x, y);
- }
-
-}
diff --git a/core/src/ru/deadsoftware/cavedroid/game/mobs/Mob.java b/core/src/ru/deadsoftware/cavedroid/game/mobs/Mob.java
index 62ddc50d4df7a6e00217a3a1f161cee8e745cb44..04fa1bbe91f8b88ca6879094dbf343f5dbbef068 100644 (file)
public enum Type {
MOB,
- SAND,
- GRAVEL
+ FALLING_BLOCK
}
public enum Direction {
diff --git a/core/src/ru/deadsoftware/cavedroid/game/model/block/CommonBlockParams.kt b/core/src/ru/deadsoftware/cavedroid/game/model/block/CommonBlockParams.kt
index 369f7523430927e4f9d5a2c55e93b0ec3fc3fa80..19454629f6d475c127162b623a434168ab8c9015 100644 (file)
val toolType: Class<out Item.Tool>?,
val damage: Int,
val tint: String?,
+ val isFallable: Boolean,
)
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 69b1f18379bad1a778a62fa5e979e7f16abc93b9..ecbe5bf0e7c3cc4b1564b92d4e03ba8fe20c5b3d 100644 (file)
@SerialName("tool_type") val toolType: String? = null,
@SerialName("damage") val damage: Int = 0,
@SerialName("tint") val tint: String? = null,
+ @SerialName("fallable") val fallable: Boolean = false,
)
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 1b641ed338a420a3cf502af7a9cd50f3e92e98b0..19d8c4757d125235a8dfd62b482bbfb467c87862 100644 (file)
toolType = mapToolType(dto),
damage = dto.damage,
tint = dto.tint,
+ isFallable = dto.fallable,
)
}
diff --git a/core/src/ru/deadsoftware/cavedroid/game/world/GameWorldBlocksLogicControllerTask.kt b/core/src/ru/deadsoftware/cavedroid/game/world/GameWorldBlocksLogicControllerTask.kt
index 387407a841e482fc85dd50a7ff8ab7af1c0f280c..e92b9e2ffb6f6278a01a2fe9d4d82c63454368a4 100644 (file)
val blockKey = block.params.key
val action = updateBlockActions[blockKey]
- ?: updateBlockActions.getRequiresBlockAction().takeIf { block.params.requiresBlock }
+ ?: updateBlockActions.getRequiresBlockAction().takeIf { block.params.run { requiresBlock || isFallable } }
action?.update(x, y)
}