榆树2玩家相同的键盘输入

时间:2018-03-25 04:23:39

标签: keyboard elm

如何从键盘输入两个不同的播放器( up down left right )和( W A S D )并且不会中断其他玩家的移动?

这是我的代码:

update : Msg -> Model -> ( Model, Cmd.Cmd Msg )
update (KeyMsg keyCode) model =
case keyCode of
    39 ->
        ( { model | counterH = model.counterH + 10 }, Cmd.none )

    40 ->
        ( { model | counterV = model.counterV + 10 }, Cmd.none )

    37 ->
        ( { model | counterH = checkerfunc model.counterH }, Cmd.none )

    38 ->
        ( { model | counterV = checkerfunc model.counterV }, Cmd.none )

    83 ->
        ( { model | counterV2 = model.counterV2 + 10 }, Cmd.none )

    65 ->
        ( { model | counterH2 = checkerfunc model.counterH2 }, Cmd.none )

    68 ->
        ( { model | counterH2 = model.counterH2 + 10 }, Cmd.none )

    87 ->
        ( { model | counterV2 = checkerfunc model.counterV2 }, Cmd.none )

    _ ->
        ( model, Cmd.none )

我希望代码的结构类似。

0 个答案:

没有答案