Skip to content
Snippets Groups Projects
Commit a4fe5a07 authored by Annika Österdiekhoff's avatar Annika Österdiekhoff
Browse files

fix interaction error

parent 6ba1f773
No related branches found
No related tags found
1 merge request!45Resolve "Controller Support"
Pipeline #46219 passed
......@@ -258,7 +258,6 @@ class PyGameGUI:
if np.linalg.norm(move_vec) != 0:
move_vec = move_vec / np.linalg.norm(move_vec)
print("move vector keys", move_vec)
action = Action(
current_player_name,
ActionType.MOVEMENT,
......@@ -276,6 +275,7 @@ class PyGameGUI:
# Axis 1: joy stick left: -1 = up, ~0 = center, 1 = down
# see control stuff here (at the end of the page): https://www.pygame.org/docs/ref/joystick.html
for key_set in self.key_sets:
current_player_name = str(key_set.current_player)
# if a joystick is connected for current player
if joysticks[key_set.joystick]:
# Usually axis run in pairs, up/down for one, and left/right for the other. Triggers count as axes.
......@@ -297,9 +297,8 @@ class PyGameGUI:
if np.linalg.norm(move_vec) != 0:
move_vec = move_vec / np.linalg.norm(move_vec)
print("move_vec", move_vec)
action = Action(
str(key_set.joystick), ActionType.MOVEMENT, move_vec, duration=1 / self.FPS
current_player_name, ActionType.MOVEMENT, move_vec, duration=1 / self.FPS
)
self.send_action(action)
......@@ -344,26 +343,25 @@ class PyGameGUI:
"""
for key_set in self.key_sets:
current_player_name = str(key_set.current_player)
# if a joystick is connected for current player
if joysticks[key_set.joystick]:
# pickup = Button A <-> 0
if joysticks[key_set.joystick].get_button(0):
action = Action(str(key_set.joystick), ActionType.PUT, "pickup")
if joysticks[key_set.joystick].get_button(0) and event.type == pygame.JOYBUTTONDOWN:
action = Action(current_player_name, ActionType.PUT, "pickup")
self.send_action(action)
# FIXME: when clicking X without cutboard and then A to lay it on the cutboard,
# it is automatically cutted when laying down
# FIXME: does it work with button up and down?
# interact = Button X <-> 2
if joysticks[key_set.joystick].get_button(2):
if event.button == 2:
if event.type == pygame.JOYBUTTONDOWN:
action = Action(
str(key_set.joystick), ActionType.INTERACT, InterActionData.START
current_player_name, ActionType.INTERACT, InterActionData.START
)
self.send_action(action)
# stop interaction if last pressed button was X <-> 2
elif event.type == pygame.JOYBUTTONUP:
action = Action(
str(key_set.joystick), ActionType.INTERACT, InterActionData.STOP
current_player_name, ActionType.INTERACT, InterActionData.STOP
)
self.send_action(action)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment