summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 727e20d)
raw | patch | inline | side by side (parent: 727e20d)
author | fredboy <fredboy@protonmail.com> | |
Mon, 22 Apr 2024 16:10:56 +0000 (23:10 +0700) | ||
committer | fredboy <fredboy@protonmail.com> | |
Mon, 22 Apr 2024 16:10:56 +0000 (23:10 +0700) |
index 4f08f56183628fc9674836bd784d56dfea209d46..be444541df17b151ebc9e24604b62d471076caf8 100644 (file)
"texture": "lava_still",
"animated": true,
"frames": 16,
- "state": 0
+ "state": 0,
+ "damage": 4
},
"sand": {
"hp": 45,
"transparent": true,
"block_required": true,
"drop": "cactus",
- "texture": "cactus"
+ "texture": "cactus",
+ "damage": 1
},
"water_16": {
"collision": false,
"texture": "lava_flow",
"animated": true,
"frames": 16,
- "state": 1
+ "state": 1,
+ "damage": 4
},
"lava_12": {
"top": 4,
"texture": "lava_flow",
"animated": true,
"frames": 16,
- "state": 2
+ "state": 2,
+ "damage": 4
},
"lava_8": {
"top": 8,
"texture": "lava_flow",
"animated": true,
"frames": 16,
- "state": 3
+ "state": 3,
+ "damage": 4
},
"lava_4": {
"top": 12,
"texture": "lava_flow",
"animated": true,
"frames": 16,
- "state": 4
+ "state": 4,
+ "damage": 4
},
"obsidian": {
"hp": 1500,
diff --git a/core/src/ru/deadsoftware/cavedroid/game/GameProc.java b/core/src/ru/deadsoftware/cavedroid/game/GameProc.java
index 184e376cba5c448991c67c303e73f132c613cb3a..75605bf058dd6b9ee2d4fbc6a88a627202aecf7a 100644 (file)
import ru.deadsoftware.cavedroid.game.mobs.MobsController;
import ru.deadsoftware.cavedroid.game.world.GameWorldBlocksLogicControllerTask;
import ru.deadsoftware.cavedroid.game.world.GameWorldFluidsLogicControllerTask;
+import ru.deadsoftware.cavedroid.game.world.GameWorldMobDamageControllerTask;
import javax.inject.Inject;
private final MobsController mMobsController;
private final GameWorldFluidsLogicControllerTask mGameWorldFluidsLogicControllerTask;
private final GameWorldBlocksLogicControllerTask mGameWorldBlocksLogicControllerTask;
+ private final GameWorldMobDamageControllerTask mGameWorldMobDamageControllerTask;
private final Timer mWorldLogicTimer = new Timer();
GameRenderer gameRenderer,
MobsController mobsController,
GameWorldFluidsLogicControllerTask gameWorldFluidsLogicControllerTask,
- GameWorldBlocksLogicControllerTask gameWorldBlocksLogicControllerTask
+ GameWorldBlocksLogicControllerTask gameWorldBlocksLogicControllerTask,
+ GameWorldMobDamageControllerTask gameWorldMobDamageControllerTask
) {
mGamePhysics = gamePhysics;
mGameInput = gameInput;
mMobsController = mobsController;
mGameWorldFluidsLogicControllerTask = gameWorldFluidsLogicControllerTask;
mGameWorldBlocksLogicControllerTask = gameWorldBlocksLogicControllerTask;
+ mGameWorldMobDamageControllerTask = gameWorldMobDamageControllerTask;
GameWorldFluidsLogicControllerTask.FLUID_UPDATE_INTERVAL_SEC);
mWorldLogicTimer.scheduleTask(gameWorldBlocksLogicControllerTask, 0,
GameWorldBlocksLogicControllerTask.WORLD_BLOCKS_LOGIC_UPDATE_INTERVAL_SEC);
+ mWorldLogicTimer.scheduleTask(gameWorldMobDamageControllerTask, 0,
+ GameWorldMobDamageControllerTask.ENVIRONMENTAL_MOB_DAMAGE_INTERVAL_SEC);
}
public void setPlayerGameMode(int gameMode) {
mWorldLogicTimer.stop();
mGameWorldFluidsLogicControllerTask.cancel();
mGameWorldBlocksLogicControllerTask.cancel();
+ mGameWorldMobDamageControllerTask.cancel();
}
}
diff --git a/core/src/ru/deadsoftware/cavedroid/game/mobs/Mob.java b/core/src/ru/deadsoftware/cavedroid/game/mobs/Mob.java
index 394346f2b9252f31d4982d7b2c4771d9d42bcf1c..415ef30376503a491a3eefd9eb8c127d53089b77 100644 (file)
}
public void damage(int damage) {
+ if (damage == 0) {
+ return;
+ }
+
if (damage < 0) {
Gdx.app.error(this.getClass().getSimpleName(), "Damage cant be negative!");
return;
diff --git a/core/src/ru/deadsoftware/cavedroid/game/mobs/Player.java b/core/src/ru/deadsoftware/cavedroid/game/mobs/Player.java
index 6e0dfe394700d5f1e63eeb9b5e33c0f5b2c2a930..b1896e4fdb8f858a3f32fd3c91bd7d36e9e4ba1c 100644 (file)
if (gameMode == 1) {
return;
}
+
+ if (damage > 0) {
+ getVelocity().y += JUMP_VELOCITY / 3f;
+ }
+
super.damage(damage);
}
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 584e7376298d4fa103d36b88ed8d9c4e2ee8e6cf..202b191bf21d9859fb56d44642d8d5dc043e4655 100644 (file)
val texture: Texture?,
val spriteMargins: BlockMargins,
val toolLevel: Int,
- val toolType: Class<out Item.Tool>?
+ val toolType: Class<out Item.Tool>?,
+ val damage: Int,
)
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 1a7dc4b3bf5a813354d65678b69a11b684bbe09d..b8c63268825acc07430df7e9bfaee7aa5c7b10fe 100644 (file)
@SerialName("other_part") val otherPart: String? = null,
@SerialName("tool_level") val toolLevel: Int = 0,
@SerialName("tool_type") val toolType: String? = null,
+ @SerialName("damage") val damage: Int = 0,
)
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 8373e02febd5189095af8919f9ae594b7da9cb70..e97659a953a83e8b69dbb0bc90e0df9c188f504f 100644 (file)
),
toolLevel = dto.toolLevel,
toolType = mapToolType(dto),
+ damage = dto.damage,
)
}
diff --git a/core/src/ru/deadsoftware/cavedroid/game/render/DebugRenderer.kt b/core/src/ru/deadsoftware/cavedroid/game/render/DebugRenderer.kt
index 03f62534522264f008936a451faaa9d2139ea989..8145324ee9b1ac88d8f10316645196bd845fe1d4 100644 (file)
override fun draw(spriteBatch: SpriteBatch, shapeRenderer: ShapeRenderer, viewport: Rectangle, delta: Float) {
if (mainConfig.isShowInfo) {
drawDebugInfo(spriteBatch)
+
+ spriteBatch.end();
+ shapeRenderer.begin(ShapeRenderer.ShapeType.Line);
+ forEachBlockInArea(mobsController.player) { x: Int, y: Int ->
+ shapeRenderer.color = Color.CYAN
+ shapeRenderer.rect(x.px - viewport.x, y.px - viewport.y, 16f, 16f)
+ }
+ shapeRenderer.end()
+ spriteBatch.begin()
}
if (mainConfig.isShowMap) {
diff --git a/core/src/ru/deadsoftware/cavedroid/game/world/GameWorldMobDamageControllerTask.kt b/core/src/ru/deadsoftware/cavedroid/game/world/GameWorldMobDamageControllerTask.kt
--- /dev/null
@@ -0,0 +1,38 @@
+package ru.deadsoftware.cavedroid.game.world
+
+import com.badlogic.gdx.utils.Timer
+import ru.deadsoftware.cavedroid.game.GameItemsHolder
+import ru.deadsoftware.cavedroid.game.GameScope
+import ru.deadsoftware.cavedroid.game.mobs.MobsController
+import ru.deadsoftware.cavedroid.misc.utils.forEachBlockInArea
+import javax.inject.Inject
+import kotlin.math.max
+
+@GameScope
+class GameWorldMobDamageControllerTask @Inject constructor(
+ private val mobsController: MobsController,
+ private val gameWorld: GameWorld,
+ private val gameItemsHolder: GameItemsHolder,
+) : Timer.Task() {
+
+ override fun run() {
+ sequence {
+ yield(mobsController.player)
+ yieldAll(mobsController.mobs)
+ }.forEach { mob ->
+ forEachBlockInArea(mob) { x, y ->
+ val foregroundBlock = gameWorld.getForeMap(x, y)
+ val backgroundBlock = gameWorld.getBackMap(x, y)
+
+ mob.damage(max(foregroundBlock.params.damage, backgroundBlock.params.damage))
+ }
+ }
+
+
+ }
+
+ companion object {
+ const val ENVIRONMENTAL_MOB_DAMAGE_INTERVAL_SEC = 0.5f
+ }
+
+}
\ No newline at end of file
diff --git a/core/src/ru/deadsoftware/cavedroid/misc/utils/RenderingUtils.kt b/core/src/ru/deadsoftware/cavedroid/misc/utils/RenderingUtils.kt
index 5849f03c79f02356a2e14a3f3c58df7102421f0a..d197229578bfb8a92e989eb228b05a2bf05f0c69 100644 (file)
fun forEachBlockInArea(
area: Rectangle,
- func: (x: Int, y: Int) -> Unit
+ func: (x: Int, y: Int) -> Unit,
) {
val startMapX = area.x.bl
- val endMapX = startMapX + area.width.bl + 1
+ val endMapX = (area.x + area.width - 1f).bl
val startMapY = area.y.bl
- val endMapY = startMapY + area.height.bl + 1
+ val endMapY = (area.y + area.height - 1f).bl
for (x in startMapX..endMapX) {
for (y in startMapY..endMapY) {