player number enum

This commit is contained in:
Anthony Samms
2025-11-14 15:20:35 -05:00
parent d06e5276b6
commit aef634ef3d
24 changed files with 301 additions and 356 deletions

View File

@@ -10,7 +10,7 @@ from libs.bg_objects.don_bg import DonBG
from libs.bg_objects.fever import Fever
from libs.bg_objects.footer import Footer
from libs.bg_objects.renda import RendaController
from libs.global_data import Difficulty
from libs.global_data import Difficulty, PlayerNum
from libs.texture import TextureWrapper
logger = logging.getLogger(__name__)
@@ -30,7 +30,7 @@ class Background:
"PRACTICE": (libs.bg_collabs.practice.Background, 'background/collab/practice', 1)
}
def __init__(self, player_num: int, bpm: float, scene_preset: str = ''):
def __init__(self, player_num: PlayerNum, bpm: float, scene_preset: str = ''):
"""
Initialize the background class.
@@ -41,12 +41,12 @@ class Background:
"""
self.tex_wrapper = TextureWrapper()
self.tex_wrapper.load_animations('background')
if player_num == 3:
if player_num == PlayerNum.TWO_PLAYER:
if scene_preset == '':
self.max_dancers = 5
don_bg_num = random.randint(0, 5)
self.don_bg = DonBG.create(self.tex_wrapper, don_bg_num, 1)
self.don_bg_2 = DonBG.create(self.tex_wrapper, don_bg_num, 2)
self.don_bg = DonBG.create(self.tex_wrapper, don_bg_num, PlayerNum.P1)
self.don_bg_2 = DonBG.create(self.tex_wrapper, don_bg_num, PlayerNum.P2)
self.renda = RendaController(self.tex_wrapper, random.randint(0, 2))
self.chibi = ChibiController(self.tex_wrapper, random.randint(0, 13), bpm)
self.bg_normal = None
@@ -56,7 +56,7 @@ class Background:
self.dancer = None
else:
bg_obj, path, max_dancers = Background.COLLABS[scene_preset]
collab_bg = bg_obj(self.tex_wrapper, 1, bpm, path, max_dancers)
collab_bg = bg_obj(self.tex_wrapper, PlayerNum.P1, bpm, path, max_dancers)
self.max_dancers = max_dancers
self.don_bg = collab_bg.don_bg
self.don_bg_2 = collab_bg.don_bg
@@ -80,7 +80,7 @@ class Background:
self.chibi = ChibiController(self.tex_wrapper, random.randint(0, 13), bpm)
else:
bg_obj, path, max_dancers = Background.COLLABS[scene_preset]
collab_bg = bg_obj(self.tex_wrapper, 1, bpm, path, max_dancers)
collab_bg = bg_obj(self.tex_wrapper, PlayerNum.P1, bpm, path, max_dancers)
self.max_dancers = max_dancers
self.don_bg = collab_bg.don_bg
self.don_bg_2 = None

View File

@@ -6,10 +6,11 @@ from libs.bg_objects.chibi import ChibiController
from libs.bg_objects.dancer import BaseDancer, BaseDancerGroup
from libs.bg_objects.don_bg import DonBGBase
from libs.bg_objects.renda import RendaController
from libs.global_data import PlayerNum
from libs.texture import TextureWrapper
class Background:
def __init__(self, tex: TextureWrapper, player_num: int, bpm: float, path: str, max_dancers: int):
def __init__(self, tex: TextureWrapper, player_num: PlayerNum, bpm: float, path: str, max_dancers: int):
self.tex_wrapper = tex
self.max_dancers = max_dancers
self.don_bg = DonBG(self.tex_wrapper, 0, 1, path)

View File

@@ -6,12 +6,13 @@ from libs.bg_objects.dancer import BaseDancer, BaseDancerGroup
from libs.bg_objects.fever import Fever3
from libs.bg_objects.footer import Footer
from libs.bg_objects.renda import RendaController
from libs.global_data import PlayerNum
from libs.texture import TextureWrapper
from libs.bg_objects.don_bg import DonBG4
class Background:
def __init__(self, tex: TextureWrapper, player_num: int, bpm: float, path: str, max_dancers: int):
def __init__(self, tex: TextureWrapper, player_num: PlayerNum, bpm: float, path: str, max_dancers: int):
self.tex_wrapper = tex
self.max_dancers = max_dancers
self.don_bg = DonBG4(self.tex_wrapper, 4, player_num, 'background')

View File

@@ -5,12 +5,13 @@ from libs.bg_objects.chibi import ChibiController
from libs.bg_objects.dancer import BaseDancer, BaseDancerGroup
from libs.bg_objects.fever import Fever3
from libs.bg_objects.renda import RendaController
from libs.global_data import PlayerNum
from libs.texture import TextureWrapper
from libs.bg_objects.don_bg import DonBG4
class Background:
def __init__(self, tex: TextureWrapper, player_num: int, bpm: float, path: str, max_dancers: int):
def __init__(self, tex: TextureWrapper, player_num: PlayerNum, bpm: float, path: str, max_dancers: int):
self.tex_wrapper = tex
self.max_dancers = max_dancers
self.don_bg = DonBG4(self.tex_wrapper, 4, player_num, 'background')

View File

@@ -3,13 +3,14 @@ from libs.bg_objects.bg_normal import BGNormalBase
from libs.bg_objects.chibi import ChibiController
from libs.bg_objects.don_bg import DonBG6
from libs.bg_objects.footer import Footer
from libs.global_data import PlayerNum
from libs.texture import TextureWrapper
class Background:
def __init__(self, tex: TextureWrapper, player_num: int, bpm: float, path: str, max_dancers: int):
def __init__(self, tex: TextureWrapper, player_num: PlayerNum, bpm: float, path: str, max_dancers: int):
self.tex_wrapper = tex
self.max_dancers = max_dancers
self.don_bg = DonBG(self.tex_wrapper, 0, 1, path)
self.don_bg = DonBG(self.tex_wrapper, 0, PlayerNum.P1, path)
self.bg_normal = BGNormalBase(self.tex_wrapper, 0, path)
self.bg_fever = None
self.footer = Footer(self.tex_wrapper, 0, path)
@@ -19,7 +20,7 @@ class Background:
self.chibi = ChibiController(self.tex_wrapper, 2, bpm, path)
class DonBG(DonBG6):
def __init__(self, tex: TextureWrapper, index: int, player_num: int, path: str):
def __init__(self, tex: TextureWrapper, index: int, player_num: PlayerNum, path: str):
super().__init__(tex, index, player_num, path)
self.overlay_move_2 = Animation.create_move(8000, total_distance=-760)
self.overlay_move_2.loop = True

View File

@@ -6,6 +6,7 @@ from libs.bg_objects.dancer import BaseDancerGroup
from libs.bg_objects.fever import BaseFever
from libs.bg_objects.footer import Footer
from libs.bg_objects.renda import RendaController
from libs.global_data import PlayerNum
from libs.texture import TextureWrapper
from libs.bg_objects.don_bg import DonBGBase
@@ -13,7 +14,7 @@ import pyray as ray
class Background:
def __init__(self, tex: TextureWrapper, player_num: int, bpm: float, path: str, max_dancers: int):
def __init__(self, tex: TextureWrapper, player_num: PlayerNum, bpm: float, path: str, max_dancers: int):
self.tex_wrapper = tex
self.max_dancers = max_dancers
self.don_bg = DonBGBase(self.tex_wrapper, 0, player_num, path)

View File

@@ -6,12 +6,13 @@ from libs.bg_objects.chibi import ChibiController
from libs.bg_objects.dancer import BaseDancerGroup
from libs.bg_objects.footer import Footer
from libs.bg_objects.renda import RendaController
from libs.global_data import PlayerNum
from libs.texture import TextureWrapper
from libs.bg_objects.don_bg import DonBGBase
class Background:
def __init__(self, tex: TextureWrapper, player_num: int, bpm: float, path: str, max_dancers: int):
def __init__(self, tex: TextureWrapper, player_num: PlayerNum, bpm: float, path: str, max_dancers: int):
self.tex_wrapper = tex
self.max_dancers = max_dancers
self.don_bg = DonBG(self.tex_wrapper, 0, player_num, path)
@@ -24,7 +25,7 @@ class Background:
self.chibi = ChibiController(self.tex_wrapper, 0, bpm, path)
class DonBG(DonBGBase):
def __init__(self, tex: TextureWrapper, index: int, player_num: int, path: str):
def __init__(self, tex: TextureWrapper, index: int, player_num: PlayerNum, path: str):
super().__init__(tex, index, player_num, path)
self.move = Animation.create_move(3000, total_distance=-304)
self.move.loop = True
@@ -35,8 +36,8 @@ class DonBG(DonBGBase):
tex.draw_texture(self.name, 'background', frame=self.is_clear, fade=fade, x=(i*304)+self.move.attribute, y=y)
class BGNormal(BGNormalBase):
def __init__(self, tex: TextureWrapper, player_num: int, path: str):
super().__init__(tex, player_num, path)
def __init__(self, tex: TextureWrapper, index: int, path: str):
super().__init__(tex, index, path)
self.screen_change = Animation.create_texture_change(8000, textures=[(0, 2000, 0), (2000, 4000, 1), (4000, 6000, 2), (6000, 8000, 3)])
self.screen_change.loop = True
self.screen_change.start()
@@ -51,8 +52,8 @@ class BGNormal(BGNormalBase):
tex.draw_texture(self.name, 'overlay')
class BGFever(BGFeverBase):
def __init__(self, tex: TextureWrapper, player_num: int, path: str):
super().__init__(tex, player_num, path)
def __init__(self, tex: TextureWrapper, index: int, path: str):
super().__init__(tex, index, path)
self.screen_change = Animation.create_texture_change(8000, textures=[(0, 2000, 0), (2000, 4000, 1), (4000, 6000, 2), (6000, 8000, 3)])
self.screen_change.loop = True
self.screen_change.start()

View File

@@ -7,13 +7,14 @@ from libs.bg_objects.dancer import BaseDancer, BaseDancerGroup
from libs.bg_objects.don_bg import DonBGBase
from libs.bg_objects.footer import Footer
from libs.bg_objects.renda import RendaController
from libs.global_data import PlayerNum
from libs.texture import TextureWrapper
class Background:
def __init__(self, tex: TextureWrapper, player_num: int, bpm: float, path: str, max_dancers: int):
def __init__(self, tex: TextureWrapper, player_num: PlayerNum, bpm: float, path: str, max_dancers: int):
self.tex_wrapper = tex
self.max_dancers = max_dancers
self.don_bg = DonBG(self.tex_wrapper, 0, 1, path)
self.don_bg = DonBG(self.tex_wrapper, 0, player_num, path)
self.bg_normal = BGNormalBase(self.tex_wrapper, 0, path)
self.bg_fever = BGFever(self.tex_wrapper, 0, path)
self.footer = Footer(self.tex_wrapper, 0, path)
@@ -37,7 +38,7 @@ class DancerGroup(BaseDancerGroup):
self.add_dancer()
class DonBG(DonBGBase):
def __init__(self, tex: TextureWrapper, index: int, player_num: int, path: str):
def __init__(self, tex: TextureWrapper, index: int, player_num: PlayerNum, path: str):
super().__init__(tex, index, player_num, path)
self.move = Animation.create_move(20000, total_distance=-1344)
self.move.start()

View File

@@ -1,10 +1,11 @@
from libs.bg_objects.bg_normal import BGNormalBase
from libs.global_data import PlayerNum
from libs.texture import TextureWrapper
from libs.bg_objects.don_bg import DonBG1
class Background:
def __init__(self, tex: TextureWrapper, player_num: int, bpm: float, path: str, max_dancers: int):
def __init__(self, tex: TextureWrapper, player_num: PlayerNum, bpm: float, path: str, max_dancers: int):
self.tex_wrapper = tex
self.max_dancers = max_dancers
self.don_bg = DonBG1(self.tex_wrapper, 0, 1, path)

View File

@@ -1,3 +1,4 @@
from libs.global_data import PlayerNum
from libs.texture import TextureWrapper
@@ -10,7 +11,7 @@ class DonBG:
return selected_obj(tex, index, player_num, path)
class DonBGBase:
def __init__(self, tex: TextureWrapper, index: int, player_num: int, path: str):
def __init__(self, tex: TextureWrapper, index: int, player_num: PlayerNum, path: str):
self.name = f'{index}_{player_num}'
tex.load_zip(path, f'donbg/{self.name}')
self.move = tex.get_animation(0)
@@ -34,7 +35,7 @@ class DonBGBase:
self.clear_fade.update(current_time_ms)
class DonBG1(DonBGBase):
def __init__(self, tex: TextureWrapper, index: int, player_num: int, path: str):
def __init__(self, tex: TextureWrapper, index: int, player_num: PlayerNum, path: str):
super().__init__(tex, index, player_num, path)
self.overlay_move = tex.get_animation(2)
def update(self, current_time_ms: float, is_clear: bool):
@@ -49,7 +50,7 @@ class DonBG1(DonBGBase):
tex.draw_texture(self.name, 'footer', frame=self.is_clear, fade=fade, x=(i*56)+self.move.attribute*((56/328)*3), y=self.overlay_move.attribute+y)
class DonBG2(DonBGBase):
def __init__(self, tex: TextureWrapper, index: int, player_num: int, path: str):
def __init__(self, tex: TextureWrapper, index: int, player_num: PlayerNum, path: str):
super().__init__(tex, index, player_num, path)
self.overlay_move = tex.get_animation(3)
def update(self, current_time_ms: float, is_clear: bool):
@@ -61,7 +62,7 @@ class DonBG2(DonBGBase):
tex.draw_texture(self.name, 'overlay', frame=self.is_clear, fade=fade, x=(i*328)+self.move.attribute, y=self.overlay_move.attribute+y)
class DonBG3(DonBGBase):
def __init__(self, tex: TextureWrapper, index: int, player_num: int, path: str):
def __init__(self, tex: TextureWrapper, index: int, player_num: PlayerNum, path: str):
super().__init__(tex, index, player_num, path)
self.bounce_up = tex.get_animation(4)
self.bounce_down = tex.get_animation(5)
@@ -88,7 +89,7 @@ class DonBG3(DonBGBase):
tex.draw_texture(self.name, 'overlay', frame=self.is_clear, fade=fade, x=(i*328)+(self.move.attribute*2), y=y_pos+y)
class DonBG4(DonBGBase):
def __init__(self, tex: TextureWrapper, index: int, player_num: int, path: str):
def __init__(self, tex: TextureWrapper, index: int, player_num: PlayerNum, path: str):
super().__init__(tex, index, player_num, path)
self.overlay_move = tex.get_animation(2)
def update(self, current_time_ms: float, is_clear: bool):
@@ -101,7 +102,7 @@ class DonBG4(DonBGBase):
tex.draw_texture(self.name, 'overlay', frame=self.is_clear, fade=fade, x=(i*328)+self.move.attribute, y=self.overlay_move.attribute+y)
class DonBG5(DonBGBase):
def __init__(self, tex: TextureWrapper, index: int, player_num: int, path: str):
def __init__(self, tex: TextureWrapper, index: int, player_num: PlayerNum, path: str):
super().__init__(tex, index, player_num, path)
self.bounce_up = tex.get_animation(4)
self.bounce_down = tex.get_animation(5)
@@ -125,7 +126,7 @@ class DonBG5(DonBGBase):
tex.draw_texture(self.name, 'overlay', frame=self.is_clear, fade=fade, x=(i*368)+(self.move.attribute * ((184/328)*2)), y=self.bounce_up.attribute - self.bounce_down.attribute - self.adjust.attribute + y)
class DonBG6(DonBGBase):
def __init__(self, tex: TextureWrapper, index: int, player_num: int, path: str):
def __init__(self, tex: TextureWrapper, index: int, player_num: PlayerNum, path: str):
super().__init__(tex, index, player_num, path)
self.overlay_move = tex.get_animation(2)
def update(self, current_time_ms: float, is_clear: bool):

View File

@@ -3,6 +3,14 @@ from enum import IntEnum
from pathlib import Path
from typing import Any, TypedDict
class PlayerNum(IntEnum):
ALL = 0
P1 = 1
P2 = 2
TWO_PLAYER = 3
DAN = 4
class Difficulty(IntEnum):
EASY = 0
NORMAL = 1
@@ -40,8 +48,8 @@ class NameplateConfig(TypedDict):
rainbow: bool
class PathsConfig(TypedDict):
tja_path: list[str]
video_path: list[str]
tja_path: list[Path]
video_path: list[Path]
class KeysConfig(TypedDict):
exit_key: str
@@ -204,7 +212,7 @@ class GlobalData:
song_progress (float): The progress of the loading bar.
total_songs (int): The total number of songs.
hit_sound (list[int]): The indices of the hit sounds currently used.
player_num (int): The player number. Either 1 or 2.
player_num (PlayerNum): The player number.
input_locked (int): The input lock status. 0 means unlocked, 1 or greater means locked.
modifiers (list[Modifiers]): The modifiers for the game.
session_data (list[SessionData]): Session data for both players.
@@ -215,15 +223,15 @@ class GlobalData:
song_paths: dict[Path, str] = field(default_factory=lambda: dict()) #path to hash
song_progress: float = 0.0
total_songs: int = 0
hit_sound: list[int] = field(default_factory=lambda: [0, 0])
player_num: int = 1
hit_sound: list[int] = field(default_factory=lambda: [0, 0, 0])
player_num: PlayerNum = PlayerNum.P1
input_locked: int = 0
modifiers: list[Modifiers] = field(default_factory=lambda: [Modifiers(), Modifiers()])
session_data: list[SessionData] = field(default_factory=lambda: [SessionData(), SessionData()])
modifiers: list[Modifiers] = field(default_factory=lambda: [Modifiers(), Modifiers(), Modifiers()])
session_data: list[SessionData] = field(default_factory=lambda: [SessionData(), SessionData(), SessionData()])
global_data = GlobalData()
def reset_session():
"""Reset the session data."""
global_data.session_data[0] = SessionData()
global_data.session_data[1] = SessionData()
global_data.session_data[2] = SessionData()

View File

@@ -1,13 +1,14 @@
from enum import Enum
import pyray as ray
from libs.global_data import PlayerNum
from libs.utils import OutlinedText, get_config, global_tex
from libs.audio import audio
class Nameplate:
"""Nameplate for displaying player information."""
def __init__(self, name: str, title: str, player_num: int, dan: int, is_gold: bool, is_rainbow: bool, title_bg: int):
def __init__(self, name: str, title: str, player_num: PlayerNum, dan: int, is_gold: bool, is_rainbow: bool, title_bg: int):
"""Initialize a Nameplate object.
Args:
@@ -54,7 +55,7 @@ class Nameplate:
"""
tex = global_tex
tex.draw_texture('nameplate', 'shadow', x=x, y=y, fade=min(0.5, fade))
if self.player_num == -1:
if self.player_num == 0:
frame = 2
title_offset = 0
else:
@@ -75,7 +76,7 @@ class Nameplate:
else:
tex.draw_texture('nameplate', 'dan_emblem', x=x, y=y, frame=self.dan_index, fade=fade)
offset = 34
if self.player_num != -1:
if self.player_num != 0:
tex.draw_texture('nameplate', f'{self.player_num}p', x=x, y=y, fade=fade)
self.name.draw(outline_color=ray.BLACK, x=x+136 - (min(255 - offset*4, self.name.texture.width)//2) + offset, y=y+24, x2=min(255 - offset*4, self.name.texture.width)-self.name.texture.width, color=ray.fade(ray.WHITE, fade))

View File

@@ -1,11 +1,10 @@
import ctypes
import hashlib
import math
import sys
import logging
import time
import json
from libs.global_data import Config, global_data
from libs.global_data import Config, PlayerNum, global_data
from functools import lru_cache
from pathlib import Path
from typing import Optional
@@ -103,149 +102,73 @@ def get_key_code(key: str) -> int:
raise ValueError(f"Invalid key: {key}")
return key_code
def is_l_don_pressed(player_num: str = '0') -> bool:
"""Check if the left don button is pressed"""
def is_input_key_pressed(keys: list[str], gamepad_buttons: list[int]):
if global_data.input_locked:
return False
if player_num == '0':
for key in keys:
key_code = get_key_code(key)
if ray.is_key_pressed(key_code):
return True
if ray.is_gamepad_available(0):
for button in gamepad_buttons:
if ray.is_gamepad_button_pressed(0, button):
return True
return False
def is_l_don_pressed(player_num: PlayerNum = PlayerNum.ALL) -> bool:
"""Check if the left don button is pressed"""
if player_num == PlayerNum.ALL:
keys = global_data.config["keys_1p"]["left_don"] + global_data.config["keys_2p"]["left_don"]
elif player_num == '1':
elif player_num == PlayerNum.P1:
keys = global_data.config["keys_1p"]["left_don"]
elif player_num == '2':
elif player_num == PlayerNum.P2:
keys = global_data.config["keys_2p"]["left_don"]
else:
return False
for key in keys:
key_code = get_key_code(key)
if ray.is_key_pressed(key_code):
return True
gamepad_buttons = global_data.config["gamepad"]["left_don"]
if ray.is_gamepad_available(0):
for button in gamepad_buttons:
if ray.is_gamepad_button_pressed(0, button):
return True
return is_input_key_pressed(keys, gamepad_buttons)
if not global_data.config["general"]["touch_enabled"]:
return False
mid_x, mid_y = (1280//2, 720)
allowed_gestures = {ray.Gesture.GESTURE_TAP, ray.Gesture.GESTURE_DOUBLETAP}
if ray.get_gesture_detected() in allowed_gestures and ray.is_gesture_detected(ray.get_gesture_detected()):
for i in range(min(ray.get_touch_point_count(), 10)):
tap_pos = (ray.get_touch_position(i).x, ray.get_touch_position(i).y)
if math.dist(tap_pos, (mid_x, mid_y)) < 300 and tap_pos[0] <= mid_x:
return True
return False
def is_r_don_pressed(player_num: str = '0') -> bool:
def is_r_don_pressed(player_num: PlayerNum = PlayerNum.ALL) -> bool:
"""Check if the right don button is pressed"""
if global_data.input_locked:
return False
if player_num == '0':
if player_num == PlayerNum.ALL:
keys = global_data.config["keys_1p"]["right_don"] + global_data.config["keys_2p"]["right_don"]
elif player_num == '1':
elif player_num == PlayerNum.P1:
keys = global_data.config["keys_1p"]["right_don"]
elif player_num == '2':
elif player_num == PlayerNum.P2:
keys = global_data.config["keys_2p"]["right_don"]
else:
return False
for key in keys:
key_code = get_key_code(key)
if ray.is_key_pressed(key_code):
return True
gamepad_buttons = global_data.config["gamepad"]["right_don"]
if ray.is_gamepad_available(0):
for button in gamepad_buttons:
if ray.is_gamepad_button_pressed(0, button):
return True
return is_input_key_pressed(keys, gamepad_buttons)
if not global_data.config["general"]["touch_enabled"]:
return False
mid_x, mid_y = (1280//2, 720)
allowed_gestures = {ray.Gesture.GESTURE_TAP, ray.Gesture.GESTURE_DOUBLETAP}
if ray.get_gesture_detected() in allowed_gestures and ray.is_gesture_detected(ray.get_gesture_detected()):
for i in range(min(ray.get_touch_point_count(), 10)):
tap_pos = (ray.get_touch_position(i).x, ray.get_touch_position(i).y)
if math.dist(tap_pos, (mid_x, mid_y)) < 300 and tap_pos[0] > mid_x:
return True
return False
def is_l_kat_pressed(player_num: str = '0') -> bool:
def is_l_kat_pressed(player_num: PlayerNum = PlayerNum.ALL) -> bool:
"""Check if the left kat button is pressed"""
if global_data.input_locked:
return False
if player_num == '0':
if player_num == PlayerNum.ALL:
keys = global_data.config["keys_1p"]["left_kat"] + global_data.config["keys_2p"]["left_kat"]
elif player_num == '1':
elif player_num == PlayerNum.P1:
keys = global_data.config["keys_1p"]["left_kat"]
elif player_num == '2':
elif player_num == PlayerNum.P2:
keys = global_data.config["keys_2p"]["left_kat"]
else:
return False
for key in keys:
key_code = get_key_code(key)
if ray.is_key_pressed(key_code):
return True
gamepad_buttons = global_data.config["gamepad"]["left_kat"]
if ray.is_gamepad_available(0):
for button in gamepad_buttons:
if ray.is_gamepad_button_pressed(0, button):
return True
return is_input_key_pressed(keys, gamepad_buttons)
if not global_data.config["general"]["touch_enabled"]:
return False
mid_x, mid_y = (1280//2, 720)
allowed_gestures = {ray.Gesture.GESTURE_TAP, ray.Gesture.GESTURE_DOUBLETAP}
if ray.get_gesture_detected() in allowed_gestures and ray.is_gesture_detected(ray.get_gesture_detected()):
for i in range(min(ray.get_touch_point_count(), 10)):
tap_pos = (ray.get_touch_position(i).x, ray.get_touch_position(i).y)
if math.dist(tap_pos, (mid_x, mid_y)) >= 300 and tap_pos[0] <= mid_x:
return True
return False
def is_r_kat_pressed(player_num: str = '0') -> bool:
def is_r_kat_pressed(player_num: PlayerNum = PlayerNum.ALL) -> bool:
"""Check if the right kat button is pressed"""
if global_data.input_locked:
return False
if player_num == '0':
if player_num == PlayerNum.ALL:
keys = global_data.config["keys_1p"]["right_kat"] + global_data.config["keys_2p"]["right_kat"]
elif player_num == '1':
elif player_num == PlayerNum.P1:
keys = global_data.config["keys_1p"]["right_kat"]
elif player_num == '2':
elif player_num == PlayerNum.P2:
keys = global_data.config["keys_2p"]["right_kat"]
else:
return False
for key in keys:
key_code = get_key_code(key)
if ray.is_key_pressed(key_code):
return True
gamepad_buttons = global_data.config["gamepad"]["right_kat"]
if ray.is_gamepad_available(0):
for button in gamepad_buttons:
if ray.is_gamepad_button_pressed(0, button):
return True
if not global_data.config["general"]["touch_enabled"]:
return False
mid_x, mid_y = (1280//2, 720)
allowed_gestures = {ray.Gesture.GESTURE_TAP, ray.Gesture.GESTURE_DOUBLETAP}
if ray.get_gesture_detected() in allowed_gestures and ray.is_gesture_detected(ray.get_gesture_detected()):
for i in range(min(ray.get_touch_point_count(), 10)):
tap_pos = (ray.get_touch_position(i).x, ray.get_touch_position(i).y)
if math.dist(tap_pos, (mid_x, mid_y)) >= 300 and tap_pos[0] > mid_x:
return True
return False
return is_input_key_pressed(keys, gamepad_buttons)
global_tex = TextureWrapper()