From 1b645eda9f49799923666a57804fb3058cda1582 Mon Sep 17 00:00:00 2001 From: fredboy Date: Sat, 20 Apr 2024 17:25:15 +0700 Subject: [PATCH] Add mob attach to controller --- core/src/ru/deadsoftware/cavedroid/game/GameInput.java | 3 ++- .../cavedroid/game/actions/updateblock/UpdateGravelAction.kt | 4 ++-- .../cavedroid/game/actions/updateblock/UpdateSandAction.kt | 3 ++- core/src/ru/deadsoftware/cavedroid/game/mobs/Mob.java | 4 ++++ 4 files changed, 10 insertions(+), 4 deletions(-) diff --git a/core/src/ru/deadsoftware/cavedroid/game/GameInput.java b/core/src/ru/deadsoftware/cavedroid/game/GameInput.java index fd22574..bab16fd 100644 --- a/core/src/ru/deadsoftware/cavedroid/game/GameInput.java +++ b/core/src/ru/deadsoftware/cavedroid/game/GameInput.java @@ -332,7 +332,8 @@ public class GameInput { break; case Input.Keys.G: - mMobsController.addMob(new Pig(mCurX * 16, mCurY * 16)); + final Mob pig = new Pig(mCurX * 16, mCurY * 16); + pig.attachToController(mMobsController); break; case Input.Keys.Q: diff --git a/core/src/ru/deadsoftware/cavedroid/game/actions/updateblock/UpdateGravelAction.kt b/core/src/ru/deadsoftware/cavedroid/game/actions/updateblock/UpdateGravelAction.kt index 53fcd62..4d39acf 100644 --- a/core/src/ru/deadsoftware/cavedroid/game/actions/updateblock/UpdateGravelAction.kt +++ b/core/src/ru/deadsoftware/cavedroid/game/actions/updateblock/UpdateGravelAction.kt @@ -2,7 +2,6 @@ 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.FallingSand import ru.deadsoftware.cavedroid.game.mobs.MobsController import ru.deadsoftware.cavedroid.game.world.GameWorld import javax.inject.Inject @@ -18,7 +17,8 @@ class UpdateGravelAction @Inject constructor( if (shouldFall) { gameWorld.setForeMap(x, y, 0) - mobsController.addMob(FallingGravel(x * 16f, y * 16f)) + FallingGravel(x * 16f, y * 16f) + .apply { attachToController(mobsController) } } } diff --git a/core/src/ru/deadsoftware/cavedroid/game/actions/updateblock/UpdateSandAction.kt b/core/src/ru/deadsoftware/cavedroid/game/actions/updateblock/UpdateSandAction.kt index 26fb978..c90899c 100644 --- a/core/src/ru/deadsoftware/cavedroid/game/actions/updateblock/UpdateSandAction.kt +++ b/core/src/ru/deadsoftware/cavedroid/game/actions/updateblock/UpdateSandAction.kt @@ -17,7 +17,8 @@ class UpdateSandAction @Inject constructor( if (shouldFall) { gameWorld.setForeMap(x, y, 0) - mobsController.addMob(FallingSand(x * 16f, y * 16f)) + FallingSand(x * 16f, y * 16f) + .apply { attachToController(mobsController) } } } diff --git a/core/src/ru/deadsoftware/cavedroid/game/mobs/Mob.java b/core/src/ru/deadsoftware/cavedroid/game/mobs/Mob.java index 592f78d..feb5ceb 100644 --- a/core/src/ru/deadsoftware/cavedroid/game/mobs/Mob.java +++ b/core/src/ru/deadsoftware/cavedroid/game/mobs/Mob.java @@ -236,6 +236,10 @@ public abstract class Mob extends Rectangle implements Serializable { return mHealth; } + public final void attachToController(MobsController controller) { + controller.addMob(this); + } + public void damage(int damage) { if (damage < 0) { Gdx.app.error(this.getClass().getSimpleName(), "Damage cant be negative!"); -- 2.29.2