DEADSOFTWARE

0cb74d7d0ff20bd0d01ceafa873b46f5bdea863c
[cavedroid.git] /
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.Player
10 import ru.deadsoftware.cavedroid.game.world.GameWorld
11 import javax.inject.Inject
13 @GameScope
14 class MoveCursorControlsModeKeyboardInputHandler @Inject constructor(
15 private val mainConfig: MainConfig,
16 private val mobsController: MobsController,
17 private val gameWorld: GameWorld,
18 ) : IGameInputHandler<KeyboardInputAction> {
20 override fun checkConditions(action: KeyboardInputAction): Boolean {
21 return mainConfig.isTouch &&
22 mobsController.player.controlMode == Player.ControlMode.CURSOR && action.isKeyDown &&
23 (action.actionKey is KeyboardInputActionKey.Left ||
24 action.actionKey is KeyboardInputActionKey.Right ||
25 action.actionKey is KeyboardInputActionKey.Up ||
26 action.actionKey is KeyboardInputActionKey.Down)
27 }
29 override fun handle(action: KeyboardInputAction) {
30 val player = mobsController.player
32 when (action.actionKey) {
33 KeyboardInputActionKey.Left -> player.cursorX--
34 KeyboardInputActionKey.Right -> player.cursorX++
35 KeyboardInputActionKey.Up -> player.cursorY--
36 KeyboardInputActionKey.Down -> player.cursorY++
37 else -> return
38 }
40 player.checkCursorBounds(gameWorld);
41 }
43 companion object {
44 private const val SURVIVAL_CURSOR_RANGE = 4
45 }
46 }