[cavedroid.git] / core / src / ru / deadsoftware / cavedroid / game / input / handler / keyboard / GoLeftKeyboardInputHandler.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.action.KeyboardInputAction
7 import ru.deadsoftware.cavedroid.game.input.action.keys.KeyboardInputActionKey
8 import ru.deadsoftware.cavedroid.game.mobs.Mob
9 import ru.deadsoftware.cavedroid.game.mobs.MobsController
10 import ru.deadsoftware.cavedroid.game.mobs.player.Player
11 import ru.deadsoftware.cavedroid.misc.annotations.multibinding.BindKeyboardInputHandler
12 import javax.inject.Inject
14 @GameScope
15 @BindKeyboardInputHandler
16 class GoLeftKeyboardInputHandler @Inject constructor(
17 private val mainConfig: MainConfig,
18 private val mobsController: MobsController,
19 ) : IKeyboardInputHandler {
21 override fun checkConditions(action: KeyboardInputAction): Boolean {
22 return action.actionKey is KeyboardInputActionKey.Left &&
23 (mobsController.player.controlMode == Player.ControlMode.WALK || !mainConfig.isTouch) &&
24 (mobsController.player.controlMode == Player.ControlMode.WALK || !mainConfig.isTouch)
25 }
27 override fun handle(action: KeyboardInputAction) {
28 if (action.isKeyDown) {
29 mobsController.player.velocity.x = -mobsController.player.speed
30 mobsController.player.setDir(Mob.Direction.LEFT)
31 } else {
32 mobsController.player.velocity.x = 0f
33 }
34 }
35 }