DEADSOFTWARE

ef0d5eb246bac4cdcab553bd4d74ca41bd0148a3
[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.IGameInputHandler
6 import ru.deadsoftware.cavedroid.game.input.action.KeyboardInputAction
7 import ru.deadsoftware.cavedroid.game.input.action.keys.KeyboardInputActionKey
8 import ru.deadsoftware.cavedroid.game.mobs.MobsController
9 import ru.deadsoftware.cavedroid.game.mobs.Player
10 import ru.deadsoftware.cavedroid.game.world.GameWorld
11 import javax.inject.Inject
13 @GameScope
14 class SwimUpKeyboardInputHandler @Inject constructor(
15 private val mainConfig: MainConfig,
16 private val mobsController: MobsController,
17 private val gameWorld: GameWorld,
18 ) : IGameInputHandler<KeyboardInputAction> {
20 private fun checkSwim(): Boolean {
21 return gameWorld.getForeMap(mobsController.player.mapX, mobsController.player.lowerMapY).isFluid()
22 }
24 override fun checkConditions(action: KeyboardInputAction): Boolean {
25 return action.actionKey is KeyboardInputActionKey.Up && action.isKeyDown &&
26 !mobsController.player.swim &&
27 !mobsController.player.canJump() &&
28 checkSwim() && !mobsController.player.isFlyMode &&
29 (mobsController.player.controlMode == Player.ControlMode.WALK || !mainConfig.isTouch)
30 }
32 override fun handle(action: KeyboardInputAction) {
33 mobsController.player.swim = true
34 }
36 }