From: fredboy <fredboy@protonmail.com>
Date: Sat, 20 Apr 2024 10:25:15 +0000 (+0700)
Subject: Add mob attach to controller
X-Git-Tag: alpha0.6.0~19
X-Git-Url: http://deadsoftware.ru/gitweb?a=commitdiff_plain;h=1b645eda9f49799923666a57804fb3058cda1582;p=cavedroid.git

Add mob attach to controller
---

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!");