DEADSOFTWARE

9dc4777e0374dc7d0e28b54647273dd7fd5b587e
[cavedroid.git] / core / src / ru / deadsoftware / cavedroid / game / input / handler / keyboard / SwimUpKeyboardInputHandler.kt
1 package ru.deadsoftware.cavedroid.game.input.handler.keyboard
3 import ru.deadsoftware.cavedroid.MainConfig
4 import ru.deadsoftware.cavedroid.game.GameScope
5 import ru.deadsoftware.cavedroid.game.input.IKeyboardInputHandler
6 import ru.deadsoftware.cavedroid.game.input.KeyboardInputHandler
7 import ru.deadsoftware.cavedroid.game.input.action.KeyboardInputAction
8 import ru.deadsoftware.cavedroid.game.input.action.keys.KeyboardInputActionKey
9 import ru.deadsoftware.cavedroid.game.mobs.MobsController
10 import ru.deadsoftware.cavedroid.game.mobs.player.Player
11 import ru.deadsoftware.cavedroid.game.world.GameWorld
12 import javax.inject.Inject
14 @GameScope
15 @KeyboardInputHandler
16 class SwimUpKeyboardInputHandler @Inject constructor(
17 private val mainConfig: MainConfig,
18 private val mobsController: MobsController,
19 private val gameWorld: GameWorld,
20 ) : IKeyboardInputHandler {
22 private fun checkSwim(): Boolean {
23 return gameWorld.getForeMap(mobsController.player.mapX, mobsController.player.lowerMapY).isFluid()
24 }
26 override fun checkConditions(action: KeyboardInputAction): Boolean {
27 return action.actionKey is KeyboardInputActionKey.Up && action.isKeyDown &&
28 !mobsController.player.swim &&
29 !mobsController.player.canJump() &&
30 checkSwim() && !mobsController.player.isFlyMode &&
31 (mobsController.player.controlMode == Player.ControlMode.WALK || !mainConfig.isTouch)
32 }
34 override fun handle(action: KeyboardInputAction) {
35 mobsController.player.swim = true
36 }
38 }