DEADSOFTWARE

Fix swimming
authorfredboy <fredboy@protonmail.com>
Fri, 3 May 2024 12:44:15 +0000 (19:44 +0700)
committerfredboy <fredboy@protonmail.com>
Fri, 3 May 2024 12:44:15 +0000 (19:44 +0700)
core/src/ru/deadsoftware/cavedroid/game/input/KeyboardInputHandlersModule.kt
core/src/ru/deadsoftware/cavedroid/game/input/action/keys/KeyboardInputActionKey.kt
core/src/ru/deadsoftware/cavedroid/game/input/handler/keyboard/FlyUpKeyboardInputHandler.kt
core/src/ru/deadsoftware/cavedroid/game/input/handler/keyboard/JumpKeyboardInputHandler.kt
core/src/ru/deadsoftware/cavedroid/game/input/handler/keyboard/MoveCursorControlsModeKeyboardInputHandler.kt
core/src/ru/deadsoftware/cavedroid/game/input/handler/keyboard/StopSwimKeyboardInputHandler.kt [new file with mode: 0644]
core/src/ru/deadsoftware/cavedroid/game/input/handler/keyboard/SwimUpKeyboardInputHandler.kt [new file with mode: 0644]
core/src/ru/deadsoftware/cavedroid/game/input/handler/keyboard/TurnOnFlyModeKeyboardInputHandler.kt
core/src/ru/deadsoftware/cavedroid/game/input/mapper/KeyboardInputActionMapper.kt

index f590398c30db185354b2ae2738c664649be7e4fa..80533d9a8a356530ed89f3139489ec65300dc516 100644 (file)
@@ -115,4 +115,18 @@ object KeyboardInputHandlersModule {
         return handler
     }
 
+    @Binds
+    @IntoSet
+    @GameScope
+    fun bindSwimUpKeyboardInputHandler(handler: SwimUpKeyboardInputHandler): IGameInputHandler<KeyboardInputAction> {
+        return handler
+    }
+
+    @Binds
+    @IntoSet
+    @GameScope
+    fun bindStopSwimKeyboardInputHandler(handler: StopSwimKeyboardInputHandler): IGameInputHandler<KeyboardInputAction> {
+        return handler
+    }
+
 }
\ No newline at end of file
index fb59efbf4dae71cc79b726ca51f28717ee66c655..cfac1328881d7de1171a66bbeb09bd521924b255 100644 (file)
@@ -5,8 +5,7 @@ sealed interface KeyboardInputActionKey {
     data object Left : KeyboardInputActionKey
     data object Right : KeyboardInputActionKey
     data object Down : KeyboardInputActionKey
-
-    data object Jump : KeyboardInputActionKey
+    data object Up : KeyboardInputActionKey
 
     data object Crouch : KeyboardInputActionKey
 
index 2c6efc90beb2dee1f4efaab5127ca7814312e6c6..6038c271940e3a381ca937316b2d7fca208993fd 100644 (file)
@@ -16,7 +16,8 @@ class FlyUpKeyboardInputHandler @Inject constructor(
 ) : IGameInputHandler<KeyboardInputAction> {
 
     override fun checkConditions(action: KeyboardInputAction): Boolean {
-        return action.actionKey is KeyboardInputActionKey.Jump &&
+        return action.actionKey is KeyboardInputActionKey.Up &&
+                !mobsController.player.swim &&
                 mobsController.player.isFlyMode &&
                 (mobsController.player.controlMode == Player.ControlMode.WALK || !mainConfig.isTouch)
     }
index 1fbc9fb76b02c7926d9d6881336db5d1465adc12..762763b2d293b515699a9a75c272d65942fc26a1 100644 (file)
@@ -16,7 +16,7 @@ class JumpKeyboardInputHandler @Inject constructor(
 ) : IGameInputHandler<KeyboardInputAction> {
 
     override fun checkConditions(action: KeyboardInputAction): Boolean {
-        return action.actionKey is KeyboardInputActionKey.Jump &&
+        return action.actionKey is KeyboardInputActionKey.Up &&
                 mobsController.player.canJump() && !mobsController.player.isFlyMode &&
                 action.isKeyDown &&
                 (mobsController.player.controlMode == Player.ControlMode.WALK || !mainConfig.isTouch)
index ac82cb8f62e6887a8be27ebf87b08361b14eadde..acae4b15b2e07a6af0b5f2cf5210463b26d5d684 100644 (file)
@@ -23,7 +23,7 @@ class MoveCursorControlsModeKeyboardInputHandler @Inject constructor(
                 mobsController.player.controlMode == Player.ControlMode.CURSOR && action.isKeyDown &&
                 (action.actionKey is KeyboardInputActionKey.Left ||
                 action.actionKey is KeyboardInputActionKey.Right ||
-                        action.actionKey is KeyboardInputActionKey.Jump ||
+                        action.actionKey is KeyboardInputActionKey.Up ||
                         action.actionKey is KeyboardInputActionKey.Down)
     }
 
@@ -48,7 +48,7 @@ class MoveCursorControlsModeKeyboardInputHandler @Inject constructor(
         when (action.actionKey) {
             KeyboardInputActionKey.Left -> player.cursorX--
             KeyboardInputActionKey.Right -> player.cursorX++
-            KeyboardInputActionKey.Jump -> player.cursorY--
+            KeyboardInputActionKey.Up -> player.cursorY--
             KeyboardInputActionKey.Down -> player.cursorY++
             else -> return
         }
diff --git a/core/src/ru/deadsoftware/cavedroid/game/input/handler/keyboard/StopSwimKeyboardInputHandler.kt b/core/src/ru/deadsoftware/cavedroid/game/input/handler/keyboard/StopSwimKeyboardInputHandler.kt
new file mode 100644 (file)
index 0000000..317ddf6
--- /dev/null
@@ -0,0 +1,30 @@
+package ru.deadsoftware.cavedroid.game.input.handler.keyboard
+
+import ru.deadsoftware.cavedroid.MainConfig
+import ru.deadsoftware.cavedroid.game.GameScope
+import ru.deadsoftware.cavedroid.game.input.IGameInputHandler
+import ru.deadsoftware.cavedroid.game.input.action.KeyboardInputAction
+import ru.deadsoftware.cavedroid.game.input.action.keys.KeyboardInputActionKey
+import ru.deadsoftware.cavedroid.game.mobs.MobsController
+import ru.deadsoftware.cavedroid.game.mobs.Player
+import ru.deadsoftware.cavedroid.game.world.GameWorld
+import javax.inject.Inject
+
+@GameScope
+class StopSwimKeyboardInputHandler @Inject constructor(
+    private val mainConfig: MainConfig,
+    private val mobsController: MobsController,
+    private val gameWorld: GameWorld,
+) : IGameInputHandler<KeyboardInputAction> {
+
+    override fun checkConditions(action: KeyboardInputAction): Boolean {
+        return action.actionKey is KeyboardInputActionKey.Up && !action.isKeyDown &&
+                mobsController.player.swim &&
+                (mobsController.player.controlMode == Player.ControlMode.WALK || !mainConfig.isTouch)
+    }
+
+    override fun handle(action: KeyboardInputAction) {
+        mobsController.player.swim = false
+    }
+
+}
\ No newline at end of file
diff --git a/core/src/ru/deadsoftware/cavedroid/game/input/handler/keyboard/SwimUpKeyboardInputHandler.kt b/core/src/ru/deadsoftware/cavedroid/game/input/handler/keyboard/SwimUpKeyboardInputHandler.kt
new file mode 100644 (file)
index 0000000..ef0d5eb
--- /dev/null
@@ -0,0 +1,36 @@
+package ru.deadsoftware.cavedroid.game.input.handler.keyboard
+
+import ru.deadsoftware.cavedroid.MainConfig
+import ru.deadsoftware.cavedroid.game.GameScope
+import ru.deadsoftware.cavedroid.game.input.IGameInputHandler
+import ru.deadsoftware.cavedroid.game.input.action.KeyboardInputAction
+import ru.deadsoftware.cavedroid.game.input.action.keys.KeyboardInputActionKey
+import ru.deadsoftware.cavedroid.game.mobs.MobsController
+import ru.deadsoftware.cavedroid.game.mobs.Player
+import ru.deadsoftware.cavedroid.game.world.GameWorld
+import javax.inject.Inject
+
+@GameScope
+class SwimUpKeyboardInputHandler @Inject constructor(
+    private val mainConfig: MainConfig,
+    private val mobsController: MobsController,
+    private val gameWorld: GameWorld,
+) : IGameInputHandler<KeyboardInputAction> {
+
+    private fun checkSwim(): Boolean {
+        return gameWorld.getForeMap(mobsController.player.mapX, mobsController.player.lowerMapY).isFluid()
+    }
+
+    override fun checkConditions(action: KeyboardInputAction): Boolean {
+        return action.actionKey is KeyboardInputActionKey.Up && action.isKeyDown &&
+                !mobsController.player.swim &&
+                !mobsController.player.canJump() &&
+                checkSwim() && !mobsController.player.isFlyMode &&
+                (mobsController.player.controlMode == Player.ControlMode.WALK || !mainConfig.isTouch)
+    }
+
+    override fun handle(action: KeyboardInputAction) {
+        mobsController.player.swim = true
+    }
+
+}
\ No newline at end of file
index 6a73a9bc54f316db61c68134ce2f8355035aaf46..05989775e0a5b9245c27e9ef51bc8919a6f92f08 100644 (file)
@@ -16,7 +16,8 @@ class TurnOnFlyModeKeyboardInputHandler @Inject constructor(
 ) : IGameInputHandler<KeyboardInputAction> {
 
     override fun checkConditions(action: KeyboardInputAction): Boolean {
-        return mobsController.player.gameMode == 1 && action.actionKey is KeyboardInputActionKey.Jump &&
+        return mobsController.player.gameMode == 1 && action.actionKey is KeyboardInputActionKey.Up &&
+                !mobsController.player.swim &&
                 !mobsController.player.isFlyMode && !mobsController.player.canJump() && action.isKeyDown &&
                 (mobsController.player.controlMode == Player.ControlMode.WALK || !mainConfig.isTouch)
     }
index ca91f486951fdf0b737ede5f84d8fbd3e92df3dd..f2ed1260b476365b917e6c527efa066e4fe0cb45 100644 (file)
@@ -13,7 +13,7 @@ class KeyboardInputActionMapper @Inject constructor() {
         val actionKey = when (key) {
             Input.Keys.A, Input.Keys.LEFT -> KeyboardInputActionKey.Left
             Input.Keys.D, Input.Keys.RIGHT -> KeyboardInputActionKey.Right
-            Input.Keys.W, Input.Keys.SPACE -> KeyboardInputActionKey.Jump
+            Input.Keys.W, Input.Keys.SPACE -> KeyboardInputActionKey.Up
             Input.Keys.S -> KeyboardInputActionKey.Down
 
             Input.Keys.E -> KeyboardInputActionKey.OpenInventory