controller fixes

This commit is contained in:
Waylon Walker 2023-01-12 17:47:31 -06:00
parent 6c9033bcd5
commit db22a7a168
No known key found for this signature in database
GPG key ID: 66E2BF2B4190EFE4

View file

@ -522,43 +522,45 @@ class Creeper(Game):
self.inventory_open_debounce = 1 self.inventory_open_debounce = 1
for joystick in self.joysticks.values(): for joystick in self.joysticks.values():
if joystick.get_axis(5) > 0:
if self.attack():
joystick.rumble(0.1, 0.0, 100)
if joystick.get_button(4) and self.hotbar_back_debounce: if joystick.get_button(4) and self.controller_hotbar_back_debounce:
print(self.hotbar_back_debounce) print(self.controller_hotbar_back_debounce)
self.hotbar.next(-1) self.hotbar.next(-1)
self.hotbar_back_debounce = 0 self.controller_hotbar_back_debounce = 0
print(self.hotbar_back_debounce) print(self.hotbar_back_debounce)
if not joystick.get_button(4): if not joystick.get_button(4):
print("resetting") self.controller_hotbar_back_debounce = 1
self.hotbar_back_debounce = 1
if joystick.get_button(5) and self.hotbar_forward_debounce: if joystick.get_button(5) and self.controller_hotbar_forward_debounce:
self.hotbar.next(1) self.hotbar.next(1)
self.hotbar_forward_debounce = 0 self.controller_hotbar_forward_debounce = 0
elif not joystick.get_button(5): elif not joystick.get_button(5):
self.hotbar_forward_debounce = 1 self.controller_hotbar_forward_debounce = 1
if ( if (
keys[pygame.K_e] or joystick.get_button(2) keys[pygame.K_e] or joystick.get_button(2)
) and self.inventory_open_debounce: ) and self.controller_inventory_open_debounce:
self.inventory_menu.is_open = not self.inventory_menu.is_open self.inventory_menu.is_open = not self.inventory_menu.is_open
self.inventory_open_debounce = 0 self.controller_inventory_open_debounce = 0
elif not (keys[pygame.K_e] or joystick.get_button(2)): elif not keys[pygame.K_e] and not joystick.get_button(2):
self.inventory_open_debounce = 1 self.controller_inventory_open_debounce = 1
if ( if (
keys[pygame.K_ESCAPE] or joystick.get_button(9) keys[pygame.K_ESCAPE] or joystick.get_button(9)
) and self.main_open_debounce: ) and self.controller_main_open_debounce:
self.main_menu.is_open = not self.main_menu.is_open self.main_menu.is_open = not self.main_menu.is_open
self.main_open_debounce = 0 self.controller_main_open_debounce = 0
elif not (keys[pygame.K_ESCAPE] or joystick.get_button(9)): elif not (keys[pygame.K_ESCAPE] or joystick.get_button(9)):
self.main_open_debounce = 1 self.controller_main_open_debounce = 1
if keys[pygame.K_F3] and self.debug_open_debounce: if keys[pygame.K_F3] and self.controller_debug_open_debounce:
self.debug_menu.is_open = not self.debug_menu.is_open self.debug_menu.is_open = not self.debug_menu.is_open
self.debug_open_debounce = 0 self.controller_debug_open_debounce = 0
elif not keys[pygame.K_F3]: elif not keys[pygame.K_F3]:
self.debug_open_debounce = 1 self.controller_debug_open_debounce = 1
hats = joystick.get_numhats() hats = joystick.get_numhats()
for i in range(hats): for i in range(hats):