I'm programing a game with Java (Jogl, JInput). I'm not sure about my code. How to record keys strength? First I record a pair (keyName, millisTime) on any keypad's event. Then I try to update game's state with new key's value.
I think I have an error with the first part of the code.
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;
}
}