0

我正在用Java(Jogl,JInput)编写游戏。我不确定我的代码。如何记录按键强度?首先,我在任何键盘的事件上记录一对 (keyName, millisTime)。然后我尝试用新键的值更新游戏的状态。

我认为我对代码的第一部分有错误。

                PositionButton pb = positionButtonList.get(comp.getName());
                System.out.println(comp.getName());
                pb.nanotimeEllapsed = System.nanoTime() - pb.startTime;
                pb.startTime = System.nanoTime() - pb.nanotimeEllapsed;


public void on(String compName, float value) {
    System.out.println(compName + "|" + value);

    if (positionButtonList.get(compName) == null) {
        System.exit(-1);
    }
    long move;
    System.out.println("Move intensity: "+(move = (long) (value * positionButtonList.get(compName).nanotimeEllapsed / 1000.0)));
    switch (compName) {
        case "Axe X":
            if (move > 0) {
                if (positionButtonList.get(compName) != null) {
                    positionUpdate.rotationDroite(move);

                }
            } else if (positionButtonList.get(compName) != null) {
                positionUpdate.rotationGauche(-move);
            }
            break;
        case "Axe Y":
            if (move > 0) {
                if (positionButtonList.get(compName) != null) {
                    positionUpdate.acc(move);

                }
            } else if (positionButtonList.get(compName) != null) {
                positionUpdate.dec(-move);
            }
            break;
    }
}

完整代码: https ://gitlab.com/LaboManu/Power-and-Damages/blob/master/src/be/manudahmen/emptycanvas/apps/darz/input/Joystick.java

4

0 回答 0