package KeyUtils import ClosureEvents public tuple keyTuple(boolean up, boolean down, boolean left, boolean right) keyTuple array keyStatuses public function player.getDownKeys() returns keyTuple return keyStatuses[this.getId()] EventListener firstKeyListener = null public function addKeyListener(EventListener listener) returns EventListener if firstKeyListener != null firstKeyListener.prev = listener listener.next = firstKeyListener firstKeyListener = listener return listener public function removeKeyListener(EventListener listener) if firstKeyListener == listener firstKeyListener = null destroy listener function onKeyEvent() var keyStatus = keyStatuses[GetTriggerPlayer().getId()] let id = GetTriggerEventId() if id == EVENT_PLAYER_ARROW_DOWN_DOWN keyStatus.down = true else if id == EVENT_PLAYER_ARROW_DOWN_UP keyStatus.down = false else if id == EVENT_PLAYER_ARROW_UP_DOWN keyStatus.up = true else if id == EVENT_PLAYER_ARROW_UP_UP keyStatus.up = false else if id == EVENT_PLAYER_ARROW_LEFT_DOWN keyStatus.left = true else if id == EVENT_PLAYER_ARROW_LEFT_UP keyStatus.left = false else if id == EVENT_PLAYER_ARROW_RIGHT_DOWN keyStatus.right = true else if id == EVENT_PLAYER_ARROW_RIGHT_UP keyStatus.right = false keyStatuses[GetTriggerPlayer().getId()] = keyStatus var listener = firstKeyListener while listener != null listener.onEvent() listener = listener.next init for i = 0 to 11 keyStatuses[i] = keyTuple(false, false, false, false) EventListener.add(EVENT_PLAYER_ARROW_DOWN_DOWN, () -> onKeyEvent()) EventListener.add(EVENT_PLAYER_ARROW_DOWN_UP, () -> onKeyEvent()) EventListener.add(EVENT_PLAYER_ARROW_UP_DOWN, () -> onKeyEvent()) EventListener.add(EVENT_PLAYER_ARROW_UP_UP, () -> onKeyEvent()) EventListener.add(EVENT_PLAYER_ARROW_LEFT_DOWN, () -> onKeyEvent()) EventListener.add(EVENT_PLAYER_ARROW_LEFT_UP, () -> onKeyEvent()) EventListener.add(EVENT_PLAYER_ARROW_RIGHT_DOWN, () -> onKeyEvent()) EventListener.add(EVENT_PLAYER_ARROW_RIGHT_UP, () -> onKeyEvent())