diff --git a/config.toml b/config.toml index 53d0fa3..fdac99f 100644 --- a/config.toml +++ b/config.toml @@ -7,16 +7,18 @@ tja_path = 'Songs' video_path = 'Videos' [keybinds] -left_kat = 'E' -left_don = 'F' -right_don = 'J' -right_kat = 'I' +left_kat = ['E','R'] +left_don = ['F','K'] +right_don = ['J','D'] +right_kat = ['I','U'] [audio] device_type = 'ASIO' asio_buffer = 6 [video] -fullscreen = true -borderless = true +screen_width = 1280 +screen_height = 720 +fullscreen = false +borderless = false vsync = true diff --git a/libs/animation.py b/libs/animation.py index e203450..d05c9fe 100644 --- a/libs/animation.py +++ b/libs/animation.py @@ -1,5 +1,5 @@ class Animation: - def __init__(self, current_ms, duration, type): + def __init__(self, current_ms: float, duration: float, type: str): self.type = type self.start_ms = current_ms self.attribute = 0 @@ -7,7 +7,7 @@ class Animation: self.params = dict() self.is_finished = False - def update(self, current_ms): + def update(self, current_ms: float): if self.type == 'fade': self.fade(current_ms, self.duration, @@ -50,8 +50,8 @@ class Animation: initial_size=self.params.get('final_size', 1.0), delay=self.params.get('delay', 0.0) + self.duration) - def fade(self, current_ms, duration, initial_opacity, final_opacity, delay, ease_in, ease_out): - def ease_out_progress(progress, ease): + def fade(self, current_ms: float, duration: float, initial_opacity: float, final_opacity: float, delay: float, ease_in: str | None, ease_out: str | None) -> None: + def _ease_out_progress(progress: float, ease: str | None) -> float: if ease == 'quadratic': return progress * (2 - progress) elif ease == 'cubic': @@ -60,7 +60,7 @@ class Animation: return 1 - pow(2, -10 * progress) else: return progress - def ease_in_progress(progress, ease): + def _ease_in_progress(progress: float, ease: str | None) -> float: if ease == 'quadratic': return progress * progress elif ease == 'cubic': @@ -79,15 +79,15 @@ class Animation: self.is_finished = True if ease_in is not None: - progress = ease_in_progress(elapsed_time / duration, ease_in) + progress = _ease_in_progress(elapsed_time / duration, ease_in) elif ease_out is not None: - progress = ease_out_progress(elapsed_time / duration, ease_out) + progress = _ease_out_progress(elapsed_time / duration, ease_out) else: progress = elapsed_time / duration current_opacity = initial_opacity + (final_opacity - initial_opacity) * progress self.attribute = current_opacity - def move(self, current_ms, duration, total_distance, start_position, delay): + def move(self, current_ms: float, duration: float, total_distance: float, start_position: float, delay: float) -> None: elapsed_time = current_ms - self.start_ms if elapsed_time < delay: self.attribute = start_position @@ -99,7 +99,7 @@ class Animation: else: self.attribute = start_position + total_distance self.is_finished = True - def texture_change(self, current_ms, duration, textures): + def texture_change(self, current_ms: float, duration: float, textures: list[tuple[float, float, float]]) -> None: elapsed_time = current_ms - self.start_ms if elapsed_time <= duration: for start, end, index in textures: @@ -107,7 +107,7 @@ class Animation: self.attribute = index else: self.is_finished = True - def text_stretch(self, current_ms, duration): + def text_stretch(self, current_ms: float, duration: float): elapsed_time = current_ms - self.start_ms if elapsed_time <= duration: self.attribute = 2 + 5 * (elapsed_time // 25) @@ -117,7 +117,7 @@ class Animation: else: self.attribute = 0 self.is_finished = True - def texture_resize(self, current_ms, duration, initial_size, final_size, delay): + def texture_resize(self, current_ms: float, duration: float, initial_size: float, final_size: float, delay: float): elapsed_time = current_ms - self.start_ms if elapsed_time < delay: self.attribute = initial_size diff --git a/libs/tja.py b/libs/tja.py index 8b515e3..5c9ed8d 100644 --- a/libs/tja.py +++ b/libs/tja.py @@ -4,7 +4,7 @@ from collections import deque from libs.utils import get_pixels_per_frame, strip_comments -def calculate_base_score(play_note_list: list[dict]) -> int: +def calculate_base_score(play_note_list: deque[dict]) -> int: total_notes = 0 balloon_num = 0 balloon_count = 0 @@ -55,7 +55,7 @@ class TJAParser: self.barline_display = True self.gogo_time = False - def file_to_data(self): + def _file_to_data(self): with open(self.file_path, 'rt', encoding='utf-8-sig') as tja_file: for line in tja_file: line = strip_comments(line).strip() @@ -64,7 +64,7 @@ class TJAParser: return self.data def get_metadata(self): - self.file_to_data() + self._file_to_data() diff_index = 1 highest_diff = -1 for item in self.data: @@ -126,7 +126,7 @@ class TJAParser: self.bpm, self.wave, self.offset, self.demo_start, self.course_data] def data_to_notes(self, diff): - self.file_to_data() + self._file_to_data() #Get notes start and end note_start = -1 note_end = -1 @@ -144,11 +144,23 @@ class TJAParser: bar = [] #Check for measures and separate when comma exists for i in range(note_start, note_end): - item = self.data[i].strip(',') - bar.append(item) - if item != self.data[i]: - notes.append(bar) - bar = [] + line = self.data[i] + if line.startswith("#"): + bar.append(line) + else: + item = line.strip(',') + if item == '': + if bar == []: + bar.append(item) + else: + notes.append(bar) + bar = [] + continue + else: + bar.append(item) + if item != line: + notes.append(bar) + bar = [] return notes, self.course_data[diff][1] def get_se_note(self, play_note_list, ms_per_measure, note, note_ms): diff --git a/libs/utils.py b/libs/utils.py index 0890354..044ff3c 100644 --- a/libs/utils.py +++ b/libs/utils.py @@ -10,6 +10,14 @@ import tomllib #TJA Format creator is unknown. I did not create the format, but I did write the parser though. +def get_zip_filenames(zip_path: str) -> list[str]: + result = [] + with zipfile.ZipFile(zip_path, 'r') as zip_ref: + file_list = zip_ref.namelist() + for file_name in file_list: + result.append(file_name) + return result + def load_image_from_zip(zip_path: str, filename: str) -> ray.Image: with zipfile.ZipFile(zip_path, 'r') as zip_ref: with zip_ref.open(filename) as image_file: @@ -30,6 +38,28 @@ def load_texture_from_zip(zip_path: str, filename: str) -> ray.Texture: os.remove(temp_file_path) return texture +def load_all_textures_from_zip(zip_path: str) -> dict[str, list[ray.Texture]]: + result_dict = dict() + with zipfile.ZipFile(zip_path, 'r') as zip_ref: + files = zip_ref.namelist() + for file in files: + with zip_ref.open(file) as image_file: + with tempfile.NamedTemporaryFile(delete=False, suffix='.png') as temp_file: + temp_file.write(image_file.read()) + temp_file_path = temp_file.name + texture = ray.load_texture(temp_file_path) + os.remove(temp_file_path) + + true_filename, index = file.split('_img') + index = int(index.split('.')[0]) + if true_filename not in result_dict: + result_dict[true_filename] = [] + while len(result_dict[true_filename]) <= index: + result_dict[true_filename].append(None) + result_dict[true_filename][index] = texture + return result_dict + + def rounded(num: float) -> int: sign = 1 if (num >= 0) else -1 num = abs(num) @@ -41,7 +71,7 @@ def rounded(num: float) -> int: def get_current_ms() -> int: return rounded(time.time() * 1000) -def strip_comments(code: str): +def strip_comments(code: str) -> str: result = '' index = 0 for line in code.splitlines(): @@ -53,7 +83,7 @@ def strip_comments(code: str): index += 1 return result -def get_pixels_per_frame(bpm: float, time_signature: float, distance: float): +def get_pixels_per_frame(bpm: float, time_signature: float, distance: float) -> float: beat_duration = 60 / bpm total_time = time_signature * beat_duration total_frames = 60 * total_time @@ -66,6 +96,7 @@ def get_config() -> dict[str, Any]: @dataclass class GlobalData: + videos_cleared = False start_song: bool = False selected_song: str = '' selected_difficulty: int = -1 @@ -73,3 +104,66 @@ class GlobalData: result_ok: int = -1 result_bad: int = -1 result_score: int = -1 + songs_played: int = 0 + +global_data = GlobalData() + +@dataclass +class OutlinedText: + font: ray.Font + text: str + font_size: int + text_color: ray.Color + outline_color: ray.Color + outline_thickness: int = 2 + + def __post_init__(self): + self.texture = self._create_texture() + + def _create_texture(self): + text_size = ray.measure_text_ex(self.font, self.text, self.font_size, 1.0) + + padding = self.outline_thickness * 2 + width = int(text_size.x + padding * 2) + height = int(text_size.y + padding * 2) + + image = ray.gen_image_color(width, height, ray.Color(0, 0, 0, 0)) + + for dx in range(-self.outline_thickness, self.outline_thickness + 1): + for dy in range(-self.outline_thickness, self.outline_thickness + 1): + if dx == 0 and dy == 0: + continue + + distance = (dx * dx + dy * dy) ** 0.5 + if distance <= self.outline_thickness: + ray.image_draw_text_ex( + image, + self.font, + self.text, + ray.Vector2(padding + dx, padding + dy), + self.font_size, + 1.0, + self.outline_color + ) + + ray.image_draw_text_ex( + image, + self.font, + self.text, + ray.Vector2(padding, padding), + self.font_size, + 1.0, + self.text_color + ) + + texture = ray.load_texture_from_image(image) + + ray.unload_image(image) + + return texture + + def draw(self, x: int, y: int, color: ray.Color): + ray.draw_texture(self.texture, x, y, color) + + def unload(self): + ray.unload_texture(self.texture) diff --git a/libs/video.py b/libs/video.py index eb6b95f..b9150f7 100644 --- a/libs/video.py +++ b/libs/video.py @@ -21,25 +21,26 @@ class VideoPlayer: audio_path = path[:-4] + '.ogg' self.audio = audio.load_music_stream(audio_path) - def convert_frames_background(self, index: int): + def _convert_frames_background(self): if not self.cap.isOpened(): raise ValueError("Error: Could not open video file.") total_frames = int(self.cap.get(cv2.CAP_PROP_FRAME_COUNT)) if len(self.frames) == total_frames: return 0 - self.cap.set(cv2.CAP_PROP_POS_FRAMES, index) + self.cap.set(cv2.CAP_PROP_POS_FRAMES, self.frame_index) success, frame = self.cap.read() - timestamp = (index / self.fps * 1000) + timestamp = (self.frame_index / self.fps * 1000) frame_rgb = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB) new_frame = ray.Image(frame_rgb.tobytes(), frame_rgb.shape[1], frame_rgb.shape[0], 1, ray.PixelFormat.PIXELFORMAT_UNCOMPRESSED_R8G8B8) self.frames.append((timestamp, new_frame)) + self.frame_index += 1 - def convert_frames(self): + def _convert_frames(self): if not self.cap.isOpened(): raise ValueError("Error: Could not open video file.") @@ -61,13 +62,13 @@ class VideoPlayer: print(f"Extracted {len(self.frames)} frames.") self.start_ms = get_current_ms() - def check_for_start(self): + def _check_for_start(self): if self.frames == []: - self.convert_frames() + self._convert_frames() if not audio.is_music_stream_playing(self.audio): audio.play_music_stream(self.audio) - def audio_manager(self): + def _audio_manager(self): audio.update_music_stream(self.audio) time_played = audio.get_music_time_played(self.audio) / audio.get_music_time_length(self.audio) ending_lenience = 0.95 @@ -75,8 +76,8 @@ class VideoPlayer: self.is_finished[1] = True def update(self): - self.check_for_start() - self.audio_manager() + self._check_for_start() + self._audio_manager() if self.frame_index == len(self.frames)-1: self.is_finished[0] = True diff --git a/main.py b/main.py index 37f99a8..3d71719 100644 --- a/main.py +++ b/main.py @@ -1,7 +1,7 @@ import pyray as ray from libs.audio import audio -from libs.utils import GlobalData, get_config +from libs.utils import get_config, global_data from scenes.entry import EntryScreen from scenes.game import GameScreen from scenes.result import ResultScreen @@ -17,8 +17,8 @@ class Screens: RESULT = "RESULT" def main(): - screen_width = 1280 - screen_height = 720 + screen_width: int = get_config()["video"]["screen_width"] + screen_height: int = get_config()["video"]["screen_height"] if get_config()["video"]["vsync"]: ray.set_config_flags(ray.ConfigFlags.FLAG_VSYNC_HINT) @@ -65,15 +65,16 @@ def main(): if ray.is_key_pressed(ray.KeyboardKey.KEY_F11): ray.toggle_fullscreen() - ray.is_window_fullscreen() - elif ray.is_key_pressed(ray.KeyboardKey.KEY_F12): - ray.toggle_borderless_windowed() next_screen = screen.update() screen.draw() if screen == title_screen: ray.clear_background(ray.BLACK) else: + if not global_data.videos_cleared: + del title_screen.op_video + del title_screen.attract_video + global_data.videos_cleared = True ray.clear_background(ray.WHITE) if next_screen is not None: diff --git a/scenes/entry.py b/scenes/entry.py index 5c02a04..c8adcd5 100644 --- a/scenes/entry.py +++ b/scenes/entry.py @@ -4,7 +4,7 @@ from libs.utils import load_texture_from_zip class EntryScreen: - def __init__(self, width, height): + def __init__(self, width: int, height: int): self.width = width self.height = height diff --git a/scenes/game.py b/scenes/game.py index 7245870..eddfdd9 100644 --- a/scenes/game.py +++ b/scenes/game.py @@ -8,16 +8,18 @@ from libs.animation import Animation from libs.audio import audio from libs.tja import TJAParser, calculate_base_score from libs.utils import ( - GlobalData, + OutlinedText, get_config, get_current_ms, + global_data, + load_all_textures_from_zip, load_image_from_zip, load_texture_from_zip, ) class GameScreen: - def __init__(self, width, height): + def __init__(self, width: int, height: int): self.width = width self.height = height self.judge_x = 414 @@ -25,25 +27,13 @@ class GameScreen: self.song_is_started = False def load_textures(self): + self.textures = load_all_textures_from_zip('Graphics\\lumendata\\enso_system\\common.zip') zip_file = 'Graphics\\lumendata\\enso_system\\common.zip' - self.texture_judge_circle = load_texture_from_zip(zip_file, 'lane_hit_img00017.png') - self.image_lane = load_image_from_zip(zip_file, 'lane_img00000.png') - ray.image_resize(self.image_lane, 948, 176) - self.texture_lane = ray.load_texture_from_image(self.image_lane) - - self.texture_lane_cover = load_texture_from_zip(zip_file, 'lane_obi_img00000.png') - self.texture_score_cover = load_texture_from_zip(zip_file, 'lane_obi_img00003.png') - - self.texture_don = [load_texture_from_zip(zip_file, 'onp_don_img00000.png'), - load_texture_from_zip(zip_file, 'onp_don_img00001.png')] - self.texture_kat = [load_texture_from_zip(zip_file, 'onp_katsu_img00000.png'), - load_texture_from_zip(zip_file, 'onp_katsu_img00001.png')] - - self.texture_dai_don = [load_texture_from_zip(zip_file, 'onp_don_dai_img00000.png'), - load_texture_from_zip(zip_file, 'onp_don_dai_img00001.png')] - self.texture_dai_kat = [load_texture_from_zip(zip_file, 'onp_katsu_dai_img00000.png'), - load_texture_from_zip(zip_file, 'onp_katsu_dai_img00001.png')] + image = load_image_from_zip(zip_file, 'lane_img00000.png') + ray.image_resize(image, 948, 176) + ray.unload_texture(self.textures['lane'][0]) + self.textures['lane'][0] = ray.load_texture_from_image(image) self.texture_balloon_head = [load_texture_from_zip(zip_file, 'onp_fusen_img00001.png'), load_texture_from_zip(zip_file, 'onp_fusen_img00002.png')] @@ -62,18 +52,12 @@ class GameScreen: load_texture_from_zip(zip_file, 'onp_renda_dai_img00000.png')] self.texture_dai_drumroll_tail = [load_texture_from_zip(zip_file, 'onp_renda_dai_img00001.png'), load_texture_from_zip(zip_file, 'onp_renda_dai_img00001.png')] - self.texture_drumroll_count = load_texture_from_zip(zip_file, 'renda_num_img00000.png') self.texture_drumroll_number = [] for i in range(1, 11): filename = f'renda_num_img{str(i).zfill(5)}.png' self.texture_drumroll_number.append(load_texture_from_zip(zip_file, filename)) - - self.texture_barline = load_texture_from_zip(zip_file, 'lane_syousetsu_img00000.png') - self.texture_good = load_texture_from_zip(zip_file, 'lane_hit_effect_img00009.png') - self.texture_good_hit_center = load_texture_from_zip(zip_file, 'lane_hit_img00019.png') - self.texture_good_hit_center_big = load_texture_from_zip(zip_file, 'lane_hit_img00021.png') self.texture_good_hit_effect = [load_texture_from_zip(zip_file, 'lane_hit_effect_img00005.png'), load_texture_from_zip(zip_file, 'lane_hit_effect_img00006.png'), load_texture_from_zip(zip_file, 'lane_hit_effect_img00007.png'), @@ -99,25 +83,21 @@ class GameScreen: load_texture_from_zip(zip_file, 'lane_hit_effect_img00019.png'), load_texture_from_zip(zip_file, 'lane_hit_effect_img00020.png')] - self.texture_bad = load_texture_from_zip(zip_file, 'lane_hit_effect_img00010.png') - - self.image_lane_effect_good = load_image_from_zip(zip_file, 'lane_hit_img00007.png') - ray.image_resize(self.image_lane_effect_good, 951, 130) - self.image_lane_effect_don = load_image_from_zip(zip_file, 'lane_hit_img00005.png') - ray.image_resize(self.image_lane_effect_don, 951, 130) - self.image_lane_effect_kat = load_image_from_zip(zip_file, 'lane_hit_img00006.png') - ray.image_resize(self.image_lane_effect_kat, 951, 130) - self.texture_lane_effect_good = ray.load_texture_from_image(self.image_lane_effect_good) - self.texture_lane_effect_don = ray.load_texture_from_image(self.image_lane_effect_don) - self.texture_lane_effect_kat = ray.load_texture_from_image(self.image_lane_effect_kat) + image = load_image_from_zip(zip_file, 'lane_hit_img00005.png') + ray.image_resize(image, 951, 130) + ray.unload_texture(self.textures['lane_hit'][5]) + self.textures['lane_hit'][5] = ray.load_texture_from_image(image) + image = load_image_from_zip(zip_file, 'lane_hit_img00006.png') + ray.image_resize(image, 951, 130) + ray.unload_texture(self.textures['lane_hit'][6]) + self.textures['lane_hit'][6] = ray.load_texture_from_image(image) + image = load_image_from_zip(zip_file, 'lane_hit_img00007.png') + ray.image_resize(image, 951, 130) + ray.unload_texture(self.textures['lane_hit'][7]) + self.textures['lane_hit'][7] = ray.load_texture_from_image(image) self.texture_drum = load_texture_from_zip(zip_file, 'lane_obi_img00014.png') - self.texture_don_R = load_texture_from_zip(zip_file, 'lane_obi_img00015.png') - self.texture_don_L = load_texture_from_zip(zip_file, 'lane_obi_img00016.png') - self.texture_kat_R = load_texture_from_zip(zip_file, 'lane_obi_img00017.png') - self.texture_kat_L = load_texture_from_zip(zip_file, 'lane_obi_img00018.png') - self.texture_1p_emblem = load_texture_from_zip(zip_file, 'lane_obi_img00019.png') self.texture_difficulty = [load_texture_from_zip(zip_file, 'lane_obi_img00021.png'), load_texture_from_zip(zip_file, 'lane_obi_img00022.png'), load_texture_from_zip(zip_file, 'lane_obi_img00023.png'), @@ -147,30 +127,8 @@ class GameScreen: filename = 'onp_renda_moji_img00001.png' self.texture_se_moji.append(load_texture_from_zip(zip_file, filename)) - zip_file = 'Graphics\\lumendata\\enso_system\\base1p.zip' - self.texture_balloon_speech_bubble_p1 = load_texture_from_zip(zip_file, 'action_fusen_1p_img00000.png') - self.texture_balloon = [load_texture_from_zip(zip_file, 'action_fusen_1p_img00011.png'), - load_texture_from_zip(zip_file, 'action_fusen_1p_img00012.png'), - load_texture_from_zip(zip_file, 'action_fusen_1p_img00013.png'), - load_texture_from_zip(zip_file, 'action_fusen_1p_img00014.png'), - load_texture_from_zip(zip_file, 'action_fusen_1p_img00015.png'), - load_texture_from_zip(zip_file, 'action_fusen_1p_img00016.png'), - load_texture_from_zip(zip_file, 'action_fusen_1p_img00017.png'), - load_texture_from_zip(zip_file, 'action_fusen_1p_img00018.png')] - self.texture_balloon_number = [load_texture_from_zip(zip_file, 'action_fusen_1p_img00001.png'), - load_texture_from_zip(zip_file, 'action_fusen_1p_img00002.png'), - load_texture_from_zip(zip_file, 'action_fusen_1p_img00003.png'), - load_texture_from_zip(zip_file, 'action_fusen_1p_img00004.png'), - load_texture_from_zip(zip_file, 'action_fusen_1p_img00005.png'), - load_texture_from_zip(zip_file, 'action_fusen_1p_img00006.png'), - load_texture_from_zip(zip_file, 'action_fusen_1p_img00007.png'), - load_texture_from_zip(zip_file, 'action_fusen_1p_img00008.png'), - load_texture_from_zip(zip_file, 'action_fusen_1p_img00009.png'), - load_texture_from_zip(zip_file, 'action_fusen_1p_img00010.png')] - self.texture_base_score_numbers = [] - for i in range(0, 10): - filename = f'score_add_1p_img{str(i).zfill(5)}.png' - self.texture_base_score_numbers.append(load_texture_from_zip(zip_file, filename)) + self.textures.update(load_all_textures_from_zip('Graphics\\lumendata\\enso_system\\base1p.zip')) + self.textures.update(load_all_textures_from_zip('Graphics\\lumendata\\enso_system\\don1p.zip')) def load_sounds(self): self.sound_don = audio.load_sound('Sounds\\inst_00_don.wav') @@ -182,10 +140,10 @@ class GameScreen: self.load_sounds() #Map notes to textures - self.note_type_dict = {'1': self.texture_don, - '2': self.texture_kat, - '3': self.texture_dai_don, - '4': self.texture_dai_kat, + self.note_type_dict = {'1': self.textures['onp_don'], + '2': self.textures['onp_katsu'], + '3': self.textures['onp_don_dai'], + '4': self.textures['onp_katsu_dai'], '5': self.texture_drumroll_head, '6': self.texture_dai_drumroll_head, '7': self.texture_balloon_head, @@ -207,14 +165,16 @@ class GameScreen: def update(self): - if GlobalData.start_song and not self.song_is_started: - self.init_tja(GlobalData.selected_song, GlobalData.selected_difficulty) + if global_data.start_song and not self.song_is_started: + self.init_tja(global_data.selected_song, global_data.selected_difficulty) self.song_is_started = True + self.current_ms = get_current_ms() - self.start_ms self.player_1.update(self) + if len(self.player_1.play_note_list) == 0 and not audio.is_sound_playing(self.song_music): - GlobalData.result_good, GlobalData.result_ok, GlobalData.result_bad, GlobalData.result_score = self.player_1.get_result_score() - GlobalData.start_song = False + global_data.result_good, global_data.result_ok, global_data.result_bad, global_data.result_score = self.player_1.get_result_score() + global_data.start_song = False self.song_is_started = False return 'RESULT' @@ -222,7 +182,7 @@ class GameScreen: self.player_1.draw(self) class Player: - def __init__(self, game_screen, player_number: int, difficulty: int, judge_offset: int): + def __init__(self, game_screen: GameScreen, player_number: int, difficulty: int, judge_offset: int): self.timing_good = 25.0250015258789 self.timing_ok = 75.0750045776367 self.timing_bad = 108.441665649414 @@ -258,38 +218,42 @@ class Player: self.arc_points = 25 - self.draw_judge_list = [] - self.draw_effect_list = [] - self.draw_arc_list = [] - self.draw_drum_hit_list = [] - self.drumroll_counter = [] - self.balloon_list = [] - self.combo_list = [] - self.score_list = [] - self.base_score_list = [] + self.draw_judge_list: list[Judgement] = [] + self.draw_effect_list: list[LaneHitEffect] = [] + self.draw_arc_list: list[NoteArc] = [] + self.draw_drum_hit_list: list[DrumHitEffect] = [] + self.drumroll_counter: list[DrumrollCounter] = [] + self.balloon_list: list[BalloonAnimation] = [] + self.base_score_list: list[ScoreCounterAnimation] = [] + self.combo_display = Combo(self.combo, game_screen.current_ms) + self.score_counter = ScoreCounter(self.score, game_screen.current_ms) + self.song_info = SongInfo(game_screen.current_ms, game_screen.tja.title, 'TEST') + + self.input_log: dict[float, str] = dict() def get_result_score(self): return self.good_count, self.ok_count, self.bad_count, self.score - def get_position(self, game_screen, ms, pixels_per_frame): + def get_position(self, game_screen: GameScreen, ms: float, pixels_per_frame: float): return int(game_screen.width + pixels_per_frame * 60 / 1000 * (ms - game_screen.current_ms + self.judge_offset) - 64) - def animation_manager(self, game_screen, animation_list): + def animation_manager(self, game_screen: GameScreen, animation_list: list): if len(animation_list) <= 0: return + for i in range(len(animation_list)-1, -1, -1): animation = animation_list[i] animation.update(game_screen.current_ms) if animation.is_finished: animation_list.pop(i) - def bar_manager(self, game_screen): + def bar_manager(self, game_screen: GameScreen): #Add bar to current_bars list if it is ready to be shown on screen if len(self.draw_bar_list) > 0 and game_screen.current_ms > self.draw_bar_list[0]['load_ms']: self.current_bars.append(self.draw_bar_list.popleft()) #If a bar is off screen, remove it - if len(self.current_bars) <= 0: + if len(self.current_bars) == 0: return for i in range(len(self.current_bars)-1, -1, -1): @@ -298,12 +262,12 @@ class Player: if position < game_screen.judge_x + 650: self.current_bars.pop(i) - def play_note_manager(self, game_screen): + def play_note_manager(self, game_screen: GameScreen): #Add note to current_notes list if it is ready to be shown on screen if len(self.play_note_list) > 0 and game_screen.current_ms + 1000 >= self.play_note_list[0]['load_ms']: - if self.play_note_list[0]['note'] == '8': - self.current_notes.append(self.play_note_list.popleft()) self.current_notes.append(self.play_note_list.popleft()) + if len(self.play_note_list) > 0 and self.play_note_list[0]['note'] == '8': + self.current_notes.append(self.play_note_list.popleft()) #if a note was not hit within the window, remove it if len(self.current_notes) == 0: @@ -328,7 +292,7 @@ class Player: self.is_drumroll = False self.is_balloon = False - def draw_note_manager(self, game_screen): + def draw_note_manager(self, game_screen: GameScreen): if len(self.draw_note_list) > 0 and game_screen.current_ms + 1000 >= self.draw_note_list[0]['load_ms']: if self.draw_note_list[0]['note'] in {'5', '6', '7'}: while self.draw_note_list[0]['note'] != '8': @@ -345,7 +309,7 @@ class Player: self.current_notes_draw[0]['color'] += 1 note = self.current_notes_draw[0] - if note['note'] in {'5', '6', '7'}: + if note['note'] in {'5', '6', '7'} and len(self.current_notes_draw) > 1: note = self.current_notes_draw[1] position = self.get_position(game_screen, note['ms'], note['ppf']) if position < game_screen.judge_x + 650: @@ -353,12 +317,12 @@ class Player: self.current_notes_draw.pop(0) self.current_notes_draw.pop(0) - def note_manager(self, game_screen): + def note_manager(self, game_screen: GameScreen): self.bar_manager(game_screen) self.play_note_manager(game_screen) self.draw_note_manager(game_screen) - def note_correct(self, game_screen, note): + def note_correct(self, game_screen: GameScreen, note: dict): index = note['index'] if note['note'] == '8': note_type = game_screen.note_type_dict['3'] @@ -376,19 +340,16 @@ class Player: index = self.current_notes_draw.index(note) self.current_notes_draw.pop(index) - def check_drumroll(self, game_screen, drum_type): + def check_drumroll(self, game_screen: GameScreen, drum_type: str): note_type = game_screen.note_type_dict[str(int(drum_type)+self.drumroll_big)] self.draw_arc_list.append(NoteArc(note_type, game_screen.current_ms, self.player_number)) self.curr_drumroll_count += 1 self.score += 100 self.base_score_list.append(ScoreCounterAnimation(game_screen.current_ms, 100)) - color = 255 - (self.curr_drumroll_count*10) - if color < 0: - self.current_notes_draw[0]['color'] = 0 - else: - self.current_notes_draw[0]['color'] = color + color = max(0, 255 - (self.curr_drumroll_count * 10)) + self.current_notes_draw[0]['color'] = color - def check_balloon(self, game_screen, drum_type): + def check_balloon(self, game_screen: GameScreen, drum_type: str): current_note = self.current_notes[0] if current_note['note'] == '7': current_note = self.current_notes[1] @@ -403,8 +364,10 @@ class Player: self.current_notes_draw[0]['popped'] = True audio.play_sound(game_screen.sound_balloon_pop) self.note_correct(game_screen, self.current_notes[0]) + if len(self.current_notes) > 1 and self.current_notes[0]['note'] == '8': + self.note_correct(game_screen, self.current_notes[0]) - def check_note(self, game_screen, drum_type): + def check_note(self, game_screen: GameScreen, drum_type: str): if self.is_drumroll: self.check_drumroll(game_screen, drum_type) elif self.is_balloon and drum_type == '1': @@ -412,12 +375,12 @@ class Player: elif len(self.current_notes) != 0: self.curr_drumroll_count = 0 self.curr_balloon_count = 0 - current_note = self.current_notes[0] - #Fix later - i = 0 - while current_note['note'] in {'5', '6', '7', '8'}: - i += 1 - current_note = self.current_notes[i] + current_note = next( + (note for note in self.current_notes if note['note'] not in {'5', '6', '7', '8'}), + None # Default if no matching note is found + ) + if current_note is None: + return note_type = current_note['note'] note_ms = current_note['ms'] #If the wrong key was hit, stop checking @@ -454,7 +417,7 @@ class Player: self.combo = 0 self.current_notes.popleft() - def drumroll_counter_manager(self, game_screen): + def drumroll_counter_manager(self, game_screen: GameScreen): if self.is_drumroll and self.curr_drumroll_count > 0: if len(self.drumroll_counter) == 0 or self.drumroll_counter[-1].is_finished: self.drumroll_counter.append(DrumrollCounter(game_screen.current_ms)) @@ -467,7 +430,7 @@ class Player: else: self.drumroll_counter[0].update(game_screen, game_screen.current_ms, self.curr_drumroll_count) - def balloon_animation_manager(self, game_screen): + def balloon_animation_manager(self, game_screen: GameScreen): if len(self.balloon_list) <= 0: return @@ -479,49 +442,43 @@ class Player: else: self.balloon_list[0].update(game_screen, game_screen.current_ms, self.curr_balloon_count, True) - def combo_manager(self, game_screen): - if self.combo >= 3 and len(self.combo_list) == 0: - self.combo_list.append(Combo(self.combo, game_screen.current_ms)) - elif self.combo < 3 and len(self.combo_list) != 0: - self.combo_list.pop(0) - elif len(self.combo_list) == 1: - self.combo_list[0].update(game_screen, game_screen.current_ms, self.combo) + def key_manager(self, game_screen: GameScreen): + left_kats = get_config()["keybinds"]["left_kat"] + left_dons = get_config()["keybinds"]["left_don"] + right_dons = get_config()["keybinds"]["right_don"] + right_kats = get_config()["keybinds"]["right_kat"] + for left_don in left_dons: + if ray.is_key_pressed(ord(left_don)): + self.draw_effect_list.append(LaneHitEffect(game_screen.current_ms, 'DON')) + self.draw_drum_hit_list.append(DrumHitEffect(game_screen.current_ms, 'DON', 'L')) + audio.play_sound(game_screen.sound_don) + self.check_note(game_screen, '1') + self.input_log[game_screen.current_ms] = 'DON' + for right_don in right_dons: + if ray.is_key_pressed(ord(right_don)): + self.draw_effect_list.append(LaneHitEffect(game_screen.current_ms, 'DON')) + self.draw_drum_hit_list.append(DrumHitEffect(game_screen.current_ms, 'DON', 'R')) + audio.play_sound(game_screen.sound_don) + self.check_note(game_screen, '1') + self.input_log[game_screen.current_ms] = 'DON' + for left_kat in left_kats: + if ray.is_key_pressed(ord(left_kat)): + self.draw_effect_list.append(LaneHitEffect(game_screen.current_ms, 'KAT')) + self.draw_drum_hit_list.append(DrumHitEffect(game_screen.current_ms, 'KAT', 'L')) + audio.play_sound(game_screen.sound_kat) + self.check_note(game_screen, '2') + self.input_log[game_screen.current_ms] = 'KAT' + for right_kat in right_kats: + if ray.is_key_pressed(ord(right_kat)): + self.draw_effect_list.append(LaneHitEffect(game_screen.current_ms, 'KAT')) + self.draw_drum_hit_list.append(DrumHitEffect(game_screen.current_ms, 'KAT', 'R')) + audio.play_sound(game_screen.sound_kat) + self.check_note(game_screen, '2') + self.input_log[game_screen.current_ms] = 'KAT' - def score_manager(self, game_screen): - if len(self.score_list) == 0: - self.score_list.append(ScoreCounter(self.score, game_screen.current_ms)) - elif len(self.score_list) == 1: - self.score_list[0].update(game_screen.current_ms, self.score) - - def key_manager(self, game_screen): - left_kat = ord(get_config()["keybinds"]["left_kat"]) - left_don = ord(get_config()["keybinds"]["left_don"]) - right_don = ord(get_config()["keybinds"]["right_don"]) - right_kat = ord(get_config()["keybinds"]["right_kat"]) - if ray.is_key_pressed(left_don): - self.draw_effect_list.append(LaneHitEffect(game_screen.current_ms, 'DON')) - self.draw_drum_hit_list.append(DrumHitEffect(game_screen.current_ms, 'DON', 'L')) - audio.play_sound(game_screen.sound_don) - self.check_note(game_screen, '1') - if ray.is_key_pressed(right_don): - self.draw_effect_list.append(LaneHitEffect(game_screen.current_ms, 'DON')) - self.draw_drum_hit_list.append(DrumHitEffect(game_screen.current_ms, 'DON', 'R')) - audio.play_sound(game_screen.sound_don) - self.check_note(game_screen, '1') - if ray.is_key_pressed(left_kat): - self.draw_effect_list.append(LaneHitEffect(game_screen.current_ms, 'KAT')) - self.draw_drum_hit_list.append(DrumHitEffect(game_screen.current_ms, 'KAT', 'L')) - audio.play_sound(game_screen.sound_kat) - self.check_note(game_screen, '2') - if ray.is_key_pressed(right_kat): - self.draw_effect_list.append(LaneHitEffect(game_screen.current_ms, 'KAT')) - self.draw_drum_hit_list.append(DrumHitEffect(game_screen.current_ms, 'KAT', 'R')) - audio.play_sound(game_screen.sound_kat) - self.check_note(game_screen, '2') - - def update(self, game_screen): + def update(self, game_screen: GameScreen): self.note_manager(game_screen) - self.combo_manager(game_screen) + self.combo_display.update(game_screen, game_screen.current_ms, self.combo) self.drumroll_counter_manager(game_screen) self.balloon_animation_manager(game_screen) self.animation_manager(game_screen, self.draw_judge_list) @@ -529,20 +486,20 @@ class Player: self.animation_manager(game_screen, self.draw_drum_hit_list) self.animation_manager(game_screen, self.draw_arc_list) self.animation_manager(game_screen, self.base_score_list) - self.score_manager(game_screen) + self.song_info.update(game_screen.current_ms) + self.score_counter.update(game_screen.current_ms, self.score) self.key_manager(game_screen) - def draw_animation_list(self, game_screen, animation_list): + def draw_animation_list(self, game_screen: GameScreen, animation_list: list): for animation in animation_list: animation.draw(game_screen) - def draw_drumroll(self, game_screen, big, position, index, color): + def draw_drumroll(self, game_screen: GameScreen, big: bool, position: int, index: int, color: int): drumroll_start_position = position - tail = self.current_notes_draw[index+1] - i = 0 - while tail['note'] != '8': + i = 1 + while self.current_notes_draw[index+i]['note'] != '8': i += 1 - tail = self.current_notes_draw[index+i] + tail = self.current_notes_draw[index+i] if big: drumroll_body = 'dai_drumroll_body' drumroll_tail = 'dai_drumroll_tail' @@ -554,14 +511,13 @@ class Player: self.draw_note(game_screen, drumroll_body, (drumroll_start_position+64), color, 8, drumroll_length=length) self.draw_note(game_screen, drumroll_tail, drumroll_end_position, color, 10, drumroll_length=None) - def draw_balloon(self, game_screen, note, position, index): + def draw_balloon(self, game_screen: GameScreen, note: dict, position: int, index: int): if self.current_notes_draw[0].get('popped', None): return - end_time = self.current_notes_draw[index+1] - i = 0 - while end_time['note'] != '8': + i = 1 + while self.current_notes_draw[index+i]['note'] != '8': i += 1 - end_time = self.current_notes_draw[index+i] + end_time = self.current_notes_draw[index+i] end_time_position = self.get_position(game_screen, end_time['load_ms'], end_time['ppf']) if game_screen.current_ms >= end_time['ms']: position = end_time_position @@ -569,11 +525,11 @@ class Player: position = 349 self.draw_note(game_screen, '7', position, 255, 9) - def draw_note(self, game_screen, note, position, color, se_note, drumroll_length=None): + def draw_note(self, game_screen: GameScreen, note: str, position: int, color: int, se_note: int | None, drumroll_length: int | None=None): note_padding = 64 if note == 'barline': y = 184 - ray.draw_texture(game_screen.texture_barline, position+note_padding-4, y+6, ray.WHITE) + ray.draw_texture(game_screen.textures['lane_syousetsu'][0], position+note_padding-4, y+6, ray.WHITE) return if note not in game_screen.note_type_dict: return @@ -610,7 +566,7 @@ class Player: dest_rect = ray.Rectangle(position-offset - (game_screen.texture_se_moji[se_note].width // 2) + 64, 323, drumroll_length,game_screen.texture_se_moji[se_note].height) ray.draw_texture_pro(game_screen.texture_se_moji[se_note], source_rect, dest_rect, ray.Vector2(0,0), 0, ray.WHITE) - def draw_bars(self, game_screen): + def draw_bars(self, game_screen: GameScreen): if len(self.current_bars) <= 0: return @@ -620,7 +576,7 @@ class Player: position = self.get_position(game_screen, load_ms, pixels_per_frame) self.draw_note(game_screen, 'barline', position, 255, None) - def draw_notes(self, game_screen): + def draw_notes(self, game_screen: GameScreen): if len(self.current_notes_draw) <= 0: return @@ -640,28 +596,37 @@ class Player: self.draw_note(game_screen, note_type, position, 255, note['se_note']) #ray.draw_text(str(i), position+64, 192, 25, ray.GREEN) - def draw(self, game_screen): - ray.draw_texture(game_screen.texture_lane, 332, 184, ray.WHITE) + def draw_gauge(self, game_screen: GameScreen): + ray.draw_texture(game_screen.textures['gage_don_1p_hard'][0], 327, 128, ray.WHITE) + ray.draw_texture(game_screen.textures['gage_don_1p_hard'][1], 483, 124, ray.WHITE) + ray.draw_texture(game_screen.textures['gage_don_1p_hard'][10], 483, 124, ray.fade(ray.WHITE, 0.15)) + ray.draw_texture(game_screen.textures['gage_don_1p_hard'][11], 1038, 141, ray.WHITE) + ray.draw_texture(game_screen.textures['gage_don_1p_hard'][12], 1187, 130, ray.WHITE) + + def draw(self, game_screen: GameScreen): + ray.draw_texture(game_screen.textures['lane'][0], 332, 184, ray.WHITE) + self.draw_gauge(game_screen) self.draw_animation_list(game_screen, self.draw_effect_list) - ray.draw_texture(game_screen.texture_judge_circle, 342, 184, ray.WHITE) + ray.draw_texture(game_screen.textures['lane_hit'][17], 342, 184, ray.WHITE) self.draw_animation_list(game_screen, self.draw_judge_list) self.draw_bars(game_screen) self.draw_notes(game_screen) - ray.draw_texture(game_screen.texture_lane_cover, 0, 184, ray.WHITE) + ray.draw_texture(game_screen.textures['lane_obi'][0], 0, 184, ray.WHITE) ray.draw_texture(game_screen.texture_drum, 211, 206, ray.WHITE) self.draw_animation_list(game_screen, self.draw_drum_hit_list) - self.draw_animation_list(game_screen, self.combo_list) - ray.draw_texture(game_screen.texture_score_cover, 0, 184, ray.WHITE) - ray.draw_texture(game_screen.texture_1p_emblem, 0, 225, ray.WHITE) + self.combo_display.draw(game_screen) + ray.draw_texture(game_screen.textures['lane_obi'][3], 0, 184, ray.WHITE) + ray.draw_texture(game_screen.textures['lane_obi'][19], 0, 225, ray.WHITE) ray.draw_texture(game_screen.texture_difficulty[self.difficulty], 50, 222, ray.WHITE) + self.song_info.draw(game_screen) self.draw_animation_list(game_screen, self.drumroll_counter) self.draw_animation_list(game_screen, self.draw_arc_list) self.draw_animation_list(game_screen, self.balloon_list) - self.draw_animation_list(game_screen, self.score_list) + self.score_counter.draw(game_screen) self.draw_animation_list(game_screen, self.base_score_list) class Judgement: - def __init__(self, current_ms, type, big): + def __init__(self, current_ms: float, type: str, big: bool): self.type = type self.big = big self.is_finished = False @@ -680,7 +645,7 @@ class Judgement: self.texture_animation = Animation(current_ms, 100, 'texture_change') self.texture_animation.params['textures'] = [(33, 50, 1), (50, 83, 2), (83, 100, 3), (100, float('inf'), 4)] - def update(self, current_ms): + def update(self, current_ms: float): self.fade_animation_1.update(current_ms) self.fade_animation_2.update(current_ms) self.move_animation.update(current_ms) @@ -689,17 +654,17 @@ class Judgement: if self.fade_animation_2.is_finished: self.is_finished = True - def draw(self, game_screen): + def draw(self, game_screen: GameScreen): y = self.move_animation.attribute - index = self.texture_animation.attribute + index = int(self.texture_animation.attribute) hit_color = ray.fade(ray.WHITE, self.fade_animation_1.attribute) color = ray.fade(ray.WHITE, self.fade_animation_2.attribute) if self.type == 'GOOD': if self.big: - ray.draw_texture(game_screen.texture_good_hit_center_big, 342, 184, color) + ray.draw_texture(game_screen.textures['lane_hit'][21], 342, 184, color) ray.draw_texture(game_screen.texture_good_hit_effect_big[index], 304, 143, hit_color) else: - ray.draw_texture(game_screen.texture_good_hit_center, 342, 184, color) + ray.draw_texture(game_screen.textures['lane_hit'][19], 342, 184, color) ray.draw_texture(game_screen.texture_good_hit_effect[index], 304, 143, hit_color) ray.draw_texture(game_screen.texture_good, 370, int(y), color) elif self.type == 'OK': @@ -711,10 +676,10 @@ class Judgement: ray.draw_texture(game_screen.texture_ok_hit_effect[index], 304, 143, hit_color) ray.draw_texture(game_screen.texture_ok, 370, int(y), color) elif self.type == 'BAD': - ray.draw_texture(game_screen.texture_bad, 370, int(y), color) + ray.draw_texture(game_screen.textures['lane_hit_effect'][10], 370, int(y), color) class LaneHitEffect: - def __init__(self, current_ms, type): + def __init__(self, current_ms: float, type: str): self.type = type self.color = ray.fade(ray.WHITE, 0.5) self.animation = Animation(current_ms, 150, 'fade') @@ -722,23 +687,23 @@ class LaneHitEffect: self.animation.params['initial_opacity'] = 0.5 self.is_finished = False - def update(self, current_ms): + def update(self, current_ms: float): self.animation.update(current_ms) fade_opacity = self.animation.attribute self.color = ray.fade(ray.WHITE, fade_opacity) if self.animation.is_finished: self.is_finished = True - def draw(self, game_screen): + def draw(self, game_screen: GameScreen): if self.type == 'GOOD': - ray.draw_texture(game_screen.texture_lane_effect_good, 328, 192, self.color) + ray.draw_texture(game_screen.textures['lane_hit'][7], 328, 192, self.color) elif self.type == 'DON': - ray.draw_texture(game_screen.texture_lane_effect_don, 328, 192, self.color) + ray.draw_texture(game_screen.textures['lane_hit'][5], 328, 192, self.color) elif self.type == 'KAT': - ray.draw_texture(game_screen.texture_lane_effect_kat, 328, 192, self.color) + ray.draw_texture(game_screen.textures['lane_hit'][6], 328, 192, self.color) class DrumHitEffect: - def __init__(self, current_ms, type, side): + def __init__(self, current_ms: float, type: str, side: str): self.type = type self.side = side self.color = ray.fade(ray.WHITE, 1) @@ -746,7 +711,7 @@ class DrumHitEffect: self.animation = Animation(current_ms, 100, 'fade') self.animation.params['delay'] = 67 - def update(self, current_ms): + def update(self, current_ms: float): self.animation.update(current_ms) fade_opacity = self.animation.attribute self.color = ray.fade(ray.WHITE, fade_opacity) @@ -757,17 +722,17 @@ class DrumHitEffect: x, y = 211, 206 if self.type == 'DON': if self.side == 'L': - ray.draw_texture(game_screen.texture_don_L, x, y, self.color) + ray.draw_texture(game_screen.textures['lane_obi'][16], x, y, self.color) elif self.side == 'R': - ray.draw_texture(game_screen.texture_don_R, x, y, self.color) + ray.draw_texture(game_screen.textures['lane_obi'][15], x, y, self.color) elif self.type == 'KAT': if self.side == 'L': - ray.draw_texture(game_screen.texture_kat_L, x, y, self.color) + ray.draw_texture(game_screen.textures['lane_obi'][18], x, y, self.color) elif self.side == 'R': - ray.draw_texture(game_screen.texture_kat_R, x, y, self.color) + ray.draw_texture(game_screen.textures['lane_obi'][17], x, y, self.color) class NoteArc: - def __init__(self, note_type, current_ms, player_number): + def __init__(self, note_type: list, current_ms: float, player_number: int): self.note_type = note_type self.arc_points = 25 self.create_ms = current_ms @@ -776,7 +741,7 @@ class NoteArc: self.y_i = 168 self.is_finished = False - def update(self, current_ms): + def update(self, current_ms: float): if self.x_i >= 1150: self.is_finished = True radius = 414 @@ -808,7 +773,7 @@ class NoteArc: ray.draw_texture(self.note_type[current_eighth % 2], int(self.x_i), int(self.y_i), ray.WHITE) class DrumrollCounter: - def __init__(self, current_ms): + def __init__(self, current_ms: float): self.create_ms = current_ms self.is_finished = False self.total_duration = 1349 @@ -817,13 +782,13 @@ class DrumrollCounter: self.fade_animation.params['delay'] = self.total_duration - 166 self.stretch_animation = Animation(current_ms, 0, 'text_stretch') - def update_count(self, current_ms, count, elapsed_time): + def update_count(self, current_ms: float, count: int, elapsed_time: float): self.total_duration = elapsed_time + 1349 if self.drumroll_count != count: self.drumroll_count = count self.stretch_animation = Animation(current_ms, 50, 'text_stretch') - def update(self, game_screen, current_ms, drumroll_count): + def update(self, game_screen: GameScreen, current_ms: float, drumroll_count: int): self.stretch_animation.update(current_ms) self.fade_animation.update(current_ms) @@ -833,19 +798,19 @@ class DrumrollCounter: if self.fade_animation.is_finished: self.is_finished = True - def draw(self, game_screen): + def draw(self, game_screen: GameScreen): color = ray.fade(ray.WHITE, self.fade_animation.attribute) - ray.draw_texture(game_screen.texture_drumroll_count, 200, 0, color) + ray.draw_texture(game_screen.textures['renda_num'][0], 200, 0, color) counter = str(self.drumroll_count) total_width = len(counter) * 52 start_x = 344 - (total_width // 2) source_rect = ray.Rectangle(0, 0, game_screen.texture_drumroll_number[0].width, game_screen.texture_drumroll_number[0].height) for i in range(len(counter)): dest_rect = ray.Rectangle(start_x + (i * 52), 50 - self.stretch_animation.attribute, game_screen.texture_drumroll_number[0].width, game_screen.texture_drumroll_number[0].height + self.stretch_animation.attribute) - ray.draw_texture_pro(game_screen.texture_balloon_number[int(counter[i])], source_rect, dest_rect, ray.Vector2(0,0), 0, color) + ray.draw_texture_pro(game_screen.textures['action_fusen_1p'][int(counter[i])+1], source_rect, dest_rect, ray.Vector2(0,0), 0, color) class BalloonAnimation: - def __init__(self, current_ms, balloon_total): + def __init__(self, current_ms: float, balloon_total: int): self.create_ms = current_ms self.is_finished = False self.total_duration = 83.33 @@ -856,12 +821,12 @@ class BalloonAnimation: self.fade_animation = Animation(current_ms, 166, 'fade') self.stretch_animation = Animation(current_ms, 0, 'text_stretch') - def update_count(self, current_ms, balloon_count): + def update_count(self, current_ms: float, balloon_count: int): if self.balloon_count != balloon_count: self.balloon_count = balloon_count self.stretch_animation = Animation(current_ms, 50, 'text_stretch') - def update(self, game_screen, current_ms, balloon_count, is_popped): + def update(self, game_screen: GameScreen, current_ms: float, balloon_count: int, is_popped: bool): self.update_count(current_ms, balloon_count) self.stretch_animation.update(current_ms) self.is_popped = is_popped @@ -876,26 +841,26 @@ class BalloonAnimation: if self.fade_animation.is_finished: self.is_finished = True - def draw(self, game_screen): + def draw(self, game_screen: GameScreen): if self.is_popped: - ray.draw_texture(game_screen.texture_balloon[7], 460, 130, self.color) + ray.draw_texture(game_screen.textures['action_fusen_1p'][18], 460, 130, self.color) elif self.balloon_count >= 1: - balloon_index = (self.balloon_count - 1) * 7 // self.balloon_total - ray.draw_texture(game_screen.texture_balloon[balloon_index], 460, 130, self.color) + balloon_index = (self.balloon_count - 1) * 7 // self.balloon_total + 11 + ray.draw_texture(game_screen.textures['action_fusen_1p'][balloon_index], 460, 130, self.color) if self.balloon_count > 0: - ray.draw_texture(game_screen.texture_balloon_speech_bubble_p1, 414, 40, ray.WHITE) + ray.draw_texture(game_screen.textures['action_fusen_1p'][0], 414, 40, ray.WHITE) counter = str(self.balloon_total - self.balloon_count + 1) x, y = 493, 68 margin = 52 total_width = len(counter) * margin start_x = x - (total_width // 2) - source_rect = ray.Rectangle(0, 0, game_screen.texture_balloon_number[0].width, game_screen.texture_balloon_number[0].height) + source_rect = ray.Rectangle(0, 0, game_screen.textures['action_fusen_1p'][1].width, game_screen.textures['action_fusen_1p'][1].height) for i in range(len(counter)): - dest_rect = ray.Rectangle(start_x + (i * margin), y - self.stretch_animation.attribute, game_screen.texture_balloon_number[0].width, game_screen.texture_balloon_number[0].height + self.stretch_animation.attribute) - ray.draw_texture_pro(game_screen.texture_balloon_number[int(counter[i])], source_rect, dest_rect, ray.Vector2(0,0), 0, self.color) + dest_rect = ray.Rectangle(start_x + (i * margin), y - self.stretch_animation.attribute, game_screen.textures['action_fusen_1p'][1].width, game_screen.textures['action_fusen_1p'][1].height + self.stretch_animation.attribute) + ray.draw_texture_pro(game_screen.textures['action_fusen_1p'][int(counter[i])+1], source_rect, dest_rect, ray.Vector2(0,0), 0, self.color) class Combo: - def __init__(self, combo, current_ms): + def __init__(self, combo: int, current_ms: float): self.combo = combo self.stretch_animation = Animation(current_ms, 0, 'text_stretch') self.color = [ray.fade(ray.WHITE, 1), ray.fade(ray.WHITE, 1), ray.fade(ray.WHITE, 1)] @@ -908,12 +873,12 @@ class Combo: current_ms + (4 / 3) * self.cycle_time ] - def update_count(self, current_ms, combo): + def update_count(self, current_ms: float, combo: int): if self.combo != combo: self.combo = combo self.stretch_animation = Animation(current_ms, 50, 'text_stretch') - def update(self, game_screen, current_ms, combo): + def update(self, game_screen: GameScreen, current_ms: float, combo: int): self.update_count(current_ms, combo) self.stretch_animation.update(current_ms) @@ -935,7 +900,9 @@ class Combo: fade = 0 self.color[i] = ray.fade(ray.WHITE, fade) - def draw(self, game_screen): + def draw(self, game_screen: GameScreen): + if self.combo < 3: + return if self.combo < 100: text_color = 0 margin = 30 @@ -958,21 +925,22 @@ class Combo: ray.draw_texture(game_screen.texture_combo_glimmer, x + (i * 30), y + self.glimmer_dict[j], self.color[j]) class ScoreCounter: - def __init__(self, score, current_ms): + def __init__(self, score: int, current_ms: float): self.score = score self.create_ms = current_ms self.stretch_animation = Animation(current_ms, 0, 'text_stretch') - def update_count(self, current_ms, score): + def update_count(self, current_ms: float, score: int): if self.score != score: self.score = score self.stretch_animation = Animation(current_ms, 50, 'text_stretch') - def update(self, current_ms, score): + def update(self, current_ms: float, score: int): self.update_count(current_ms, score) - self.stretch_animation.update(current_ms) + if self.score > 0: + self.stretch_animation.update(current_ms) - def draw(self, game_screen): + def draw(self, game_screen: GameScreen): counter = str(self.score) x, y = 150, 185 margin = 20 @@ -984,8 +952,8 @@ class ScoreCounter: ray.draw_texture_pro(game_screen.texture_score_numbers[int(counter[i])], source_rect, dest_rect, ray.Vector2(0,0), 0, ray.WHITE) class ScoreCounterAnimation: - def __init__(self, current_ms, counter): - self.counter = int(counter) + def __init__(self, current_ms: float, counter: int): + self.counter = counter self.fade_animation_1 = Animation(current_ms, 50, 'fade') self.fade_animation_1.params['initial_opacity'] = 0.0 self.fade_animation_1.params['final_opacity'] = 1.0 @@ -1016,7 +984,7 @@ class ScoreCounterAnimation: self.is_finished = False self.y_pos_list = [] - def update(self, current_ms): + def update(self, current_ms: float): self.fade_animation_1.update(current_ms) self.move_animation_1.update(current_ms) self.move_animation_2.update(current_ms) @@ -1034,7 +1002,7 @@ class ScoreCounterAnimation: for i in range(1, len(str(self.counter))+1): self.y_pos_list.append(self.move_animation_4.attribute + i*5) - def draw(self, game_screen): + def draw(self, game_screen: GameScreen): if self.move_animation_1.is_finished: x = self.move_animation_2.attribute else: @@ -1045,7 +1013,7 @@ class ScoreCounterAnimation: margin = 20 total_width = len(counter) * margin start_x = x - total_width - source_rect = ray.Rectangle(0, 0, game_screen.texture_base_score_numbers[0].width, game_screen.texture_base_score_numbers[0].height) + source_rect = ray.Rectangle(0, 0, game_screen.textures['score_add_1p'][0].width, game_screen.textures['score_add_1p'][0].height) for i in range(len(counter)): if self.move_animation_3.is_finished: y = self.y_pos_list[i] @@ -1053,5 +1021,44 @@ class ScoreCounterAnimation: y = self.move_animation_3.attribute else: y = 148 - dest_rect = ray.Rectangle(start_x + (i * margin), y, game_screen.texture_base_score_numbers[0].width, game_screen.texture_base_score_numbers[0].height) - ray.draw_texture_pro(game_screen.texture_base_score_numbers[int(counter[i])], source_rect, dest_rect, ray.Vector2(0,0), 0, self.color) + dest_rect = ray.Rectangle(start_x + (i * margin), y, game_screen.textures['score_add_1p'][0].width, game_screen.textures['score_add_1p'][0].height) + ray.draw_texture_pro(game_screen.textures['score_add_1p'][int(counter[i])], source_rect, dest_rect, ray.Vector2(0,0), 0, self.color) + +class SongInfo: + def __init__(self, current_ms: float, song_name: str, genre: str): + self.fade_in = Animation(current_ms, 366, 'fade') + self.fade_in.params['initial_opacity'] = 0.0 + self.fade_in.params['final_opacity'] = 1.0 + + self.fade_out = Animation(current_ms, 366, 'fade') + self.fade_out.params['initial_opacity'] = 1.0 + self.fade_out.params['final_opacity'] = 0.0 + self.fade_out.params['delay'] = 1666 + self.fade_in.duration + + self.is_finished = False + self.song_num_fade = ray.WHITE + self.song_name_fade = ray.WHITE + codepoint_count = ray.ffi.new('int *', 0) + codepoints_no_dup = set() + codepoints_no_dup.update(song_name) + codepoints = ray.load_codepoints(''.join(codepoints_no_dup), codepoint_count) + self.font = ray.load_font_ex('Graphics\\Modified-DFPKanteiryu-XB.ttf', 32, codepoints, 0) + self.song_title = OutlinedText(self.font, song_name, 40, ray.WHITE, ray.BLACK, outline_thickness=5) + + def update(self, current_ms: float): + self.fade_in.update(current_ms) + self.fade_out.update(current_ms) + self.song_num_fade = ray.fade(ray.WHITE, self.fade_in.attribute) + self.song_name_fade = ray.fade(ray.WHITE, 1 - self.fade_in.attribute) + if self.fade_in.is_finished: + self.song_num_fade = ray.fade(ray.WHITE, self.fade_out.attribute) + self.song_name_fade = ray.fade(ray.WHITE, 1 - self.fade_out.attribute) + if self.fade_out.is_finished: + self.fade_in.start_ms = current_ms + 1666 + self.fade_out.start_ms = current_ms + 1666 + self.fade_in.is_finished = False + self.fade_out.is_finished = False + + def draw(self, game_screen: GameScreen): + ray.draw_texture(game_screen.textures['song_info'][(global_data.songs_played % 4) + 8], 1132, 25, self.song_num_fade) + self.song_title.draw(1252 - self.song_title.texture.width, int(50 - self.song_title.texture.height / 2), self.song_name_fade) diff --git a/scenes/result.py b/scenes/result.py index f4be193..8338ab5 100644 --- a/scenes/result.py +++ b/scenes/result.py @@ -1,7 +1,7 @@ import pyray as ray from libs.audio import audio -from libs.utils import GlobalData +from libs.utils import global_data class ResultScreen: @@ -12,12 +12,13 @@ class ResultScreen: def update(self): if ray.is_key_pressed(ray.KeyboardKey.KEY_ENTER): + global_data.songs_played += 1 audio.play_sound(self.sound_don) return "SONG_SELECT" def draw(self): - ray.draw_text(f"{GlobalData.selected_song}", 100, 60, 20, ray.BLACK) - ray.draw_text(f"SCORE: {GlobalData.result_score}", 100, 80, 20, ray.BLACK) - ray.draw_text(f"GOOD: {GlobalData.result_good}", 100, 100, 20, ray.BLACK) - ray.draw_text(f"OK: {GlobalData.result_ok}", 100, 120, 20, ray.BLACK) - ray.draw_text(f"BAD: {GlobalData.result_bad}", 100, 140, 20, ray.BLACK) + ray.draw_text(f"{global_data.selected_song}", 100, 60, 20, ray.BLACK) + ray.draw_text(f"SCORE: {global_data.result_score}", 100, 80, 20, ray.BLACK) + ray.draw_text(f"GOOD: {global_data.result_good}", 100, 100, 20, ray.BLACK) + ray.draw_text(f"OK: {global_data.result_ok}", 100, 120, 20, ray.BLACK) + ray.draw_text(f"BAD: {global_data.result_bad}", 100, 140, 20, ray.BLACK) diff --git a/scenes/song_select.py b/scenes/song_select.py index 0f59a76..fa93ec7 100644 --- a/scenes/song_select.py +++ b/scenes/song_select.py @@ -3,18 +3,19 @@ import os import pyray as ray from libs.audio import audio -from libs.utils import GlobalData, get_config +from libs.utils import get_config, global_data class SongSelectScreen: - def __init__(self, width, height): + def __init__(self, width: int, height: int): self.width = width self.height = height self.is_song_select = True self.is_difficulty_select = False - self.song_list = [] + self.song_list: list[str] = [] self.selected_song = 0 self.selected_difficulty = 0 + self.selected_index = 0 self.sound_don = audio.load_sound('Sounds\\inst_00_don.wav') self.sound_kat = audio.load_sound('Sounds\\inst_00_katsu.wav') for dirpath, dirnames, filenames in os.walk(f'{get_config()["paths"]["tja_path"]}'): @@ -37,9 +38,9 @@ class SongSelectScreen: def update_difficulty_select(self): if ray.is_key_pressed(ray.KeyboardKey.KEY_ENTER): audio.play_sound(self.sound_don) - GlobalData.selected_song = self.song_list[self.selected_song] - GlobalData.selected_difficulty = self.selected_difficulty - GlobalData.start_song = True + global_data.selected_song = self.song_list[self.selected_song] + global_data.selected_difficulty = self.selected_difficulty + global_data.start_song = True self.is_song_select = True self.is_difficulty_select = False return "GAME" @@ -48,10 +49,10 @@ class SongSelectScreen: self.is_difficulty_select = False elif ray.is_key_pressed(ray.KeyboardKey.KEY_UP): audio.play_sound(self.sound_kat) - self.selected_difficulty -= 1 + self.selected_difficulty = (self.selected_difficulty - 1) % 5 elif ray.is_key_pressed(ray.KeyboardKey.KEY_DOWN): audio.play_sound(self.sound_kat) - self.selected_difficulty += 1 + self.selected_difficulty = (self.selected_difficulty + 1) % 5 def update(self): if self.is_song_select: @@ -60,12 +61,22 @@ class SongSelectScreen: return self.update_difficulty_select() def draw_song_select(self): - for i in range(len(self.song_list)): - if i == self.selected_song: + visible_songs = 36 + total_songs = len(self.song_list) + start_index = max(0, self.selected_song - visible_songs // 2) + + if start_index + visible_songs > total_songs: + start_index = max(0, total_songs - visible_songs) + + for i in range(visible_songs): + song_index = (start_index + i) % total_songs + + if song_index == self.selected_song: color = ray.GREEN else: color = ray.BLACK - ray.draw_text(self.song_list[i], 20, (20*i), 20, color) + + ray.draw_text(self.song_list[song_index], 20, (20*i), 20, color) def draw_difficulty_select(self): difficulties = ["Easy", "Normal", "Hard", "Oni", "Ura"] diff --git a/scenes/title.py b/scenes/title.py index 0b4f465..c08af98 100644 --- a/scenes/title.py +++ b/scenes/title.py @@ -1,5 +1,5 @@ -import os import random +from pathlib import Path import pyray as ray @@ -8,6 +8,7 @@ from libs.audio import audio from libs.utils import ( get_config, get_current_ms, + load_all_textures_from_zip, load_texture_from_zip, ) from libs.video import VideoPlayer @@ -17,45 +18,21 @@ class TitleScreen: def __init__(self, width: int, height: int): self.width = width self.height = height - self.op_video_list = [] - self.attract_video_list = [] - for root, folder, files in os.walk(f'{get_config()["paths"]["video_path"]}\\op_videos'): - for file in files: - if file.endswith('.mp4'): - self.op_video_list.append(root + '\\' + file) - for root, folder, files in os.walk(f'{get_config()["paths"]["video_path"]}\\attract_videos'): - for file in files: - if file.endswith('.mp4'): - self.attract_video_list.append(root + '\\' + file) + video_dir = Path(get_config()["paths"]["video_path"]) / "op_videos" + self.op_video_list = [str(file) for file in video_dir.glob("**/*.mp4")] + video_dir = Path(get_config()["paths"]["video_path"]) / "attract_videos" + self.attract_video_list = [str(file) for file in video_dir.glob("**/*.mp4")] self.attract_video = VideoPlayer(random.choice(self.attract_video_list)) self.op_video = VideoPlayer(random.choice(self.op_video_list)) self.scene = 'Opening Video' self.load_textures() - self.warning_board = WarningBoard(get_current_ms(), self) + self.warning_board = WarningScreen(get_current_ms(), self) + + def get_videos(self): + return self.op_video, self.attract_video def load_textures(self): - zip_file = 'Graphics\\lumendata\\attract\\keikoku.zip' - self.texture_bg = load_texture_from_zip(zip_file, 'keikoku_img00000.png') - self.texture_warning = load_texture_from_zip(zip_file, 'keikoku_img00001.png') - self.texture_warning_ch1 = [load_texture_from_zip(zip_file, 'keikoku_img00004.png'), - load_texture_from_zip(zip_file, 'keikoku_img00009.png'), - load_texture_from_zip(zip_file, 'keikoku_img00016.png')] - self.texture_warning_ch1_base = load_texture_from_zip(zip_file, 'keikoku_img00002.png') - self.texture_warning_ch2 = [load_texture_from_zip(zip_file, 'keikoku_img00005.png'), - load_texture_from_zip(zip_file, 'keikoku_img00006.png'), - load_texture_from_zip(zip_file, 'keikoku_img00007.png'), - load_texture_from_zip(zip_file, 'keikoku_img00008.png'), - load_texture_from_zip(zip_file, 'keikoku_img00010.png'), - load_texture_from_zip(zip_file, 'keikoku_img00011.png'), - load_texture_from_zip(zip_file, 'keikoku_img00012.png'), - load_texture_from_zip(zip_file, 'keikoku_img00013.png'), - load_texture_from_zip(zip_file, 'keikoku_img00017.png')] - self.texture_warning_ch2_base = load_texture_from_zip(zip_file, 'keikoku_img00003.png') - self.texture_warning_bachi = load_texture_from_zip(zip_file, 'keikoku_img00019.png') - self.texture_warning_bachi_hit = load_texture_from_zip(zip_file, 'keikoku_img00018.png') - - self.texture_warning_x_1 = load_texture_from_zip(zip_file, 'keikoku_img00014.png') - self.texture_warning_x_2 = load_texture_from_zip(zip_file, 'keikoku_img00015.png') + self.textures = load_all_textures_from_zip('Graphics\\lumendata\\attract\\keikoku.zip') self.sound_bachi_swipe = audio.load_sound('Sounds\\title\\SE_ATTRACT_2.ogg') self.sound_bachi_hit = audio.load_sound('Sounds\\title\\SE_ATTRACT_3.ogg') @@ -69,7 +46,7 @@ class TitleScreen: self.op_video.update() if all(self.op_video.is_finished): self.scene = 'Warning Board' - self.warning_board = WarningBoard(get_current_ms(), self) + self.warning_board = WarningScreen(get_current_ms(), self) elif self.scene == 'Warning Board': self.warning_board.update(get_current_ms(), self) if self.warning_board.is_finished: @@ -90,188 +67,234 @@ class TitleScreen: if self.scene == 'Opening Video': self.op_video.draw() elif self.scene == 'Warning Board': - bg_source = ray.Rectangle(0, 0, self.texture_bg.width, self.texture_bg.height) + bg_source = ray.Rectangle(0, 0, self.textures['keikoku'][0].width, self.textures['keikoku'][0].height) bg_dest = ray.Rectangle(0, 0, self.width, self.height) - ray.draw_texture_pro(self.texture_bg, bg_source, bg_dest, ray.Vector2(0,0), 0, ray.WHITE) + ray.draw_texture_pro(self.textures['keikoku'][0], bg_source, bg_dest, ray.Vector2(0,0), 0, ray.WHITE) self.warning_board.draw(self) elif self.scene == 'Attract Video': self.attract_video.draw() ray.draw_text(f"Scene: {self.scene}", 20, 40, 20, ray.BLUE) -class WarningBoard: - def __init__(self, current_ms, title_screen): +class WarningScreen: + class X: + def __init__(self, current_ms: float): + self.delay = 4250 + self.resize = Animation(current_ms, 166.67, 'texture_resize') + self.resize.params['initial_size'] = 1.0 + self.resize.params['final_size'] = 1.5 + self.resize.params['delay'] = self.delay + self.resize.params['reverse'] = 0 + + self.fadein = Animation(current_ms, 166.67, 'fade') + self.fadein.params['delay'] = self.delay + self.fadein.params['initial_opacity'] = 0.0 + self.fadein.params['final_opacity'] = 1.0 + self.fadein.params['reverse'] = 166.67 + + self.fadein_2 = Animation(current_ms, 166.67, 'fade') + self.fadein_2.params['delay'] = self.delay + 166.67 + 166.67 + self.fadein_2.params['initial_opacity'] = 0.0 + self.fadein_2.params['final_opacity'] = 1.0 + + self.sound_played = False + + def update(self, current_ms: float, sound, elapsed_time): + + self.fadein.update(current_ms) + self.fadein_2.update(current_ms) + self.resize.update(current_ms) + + if self.delay + self.fadein.duration <= elapsed_time and not self.sound_played: + audio.play_sound(sound) + self.sound_played = True + + def draw(self, texture): + scale = self.resize.attribute + width = texture.width + height = texture.height + x_x = 150 + (width//2) - ((width * scale)//2) + x_y = 200 + (height//2) - ((height * scale)//2) + x_source = ray.Rectangle(0, 0, width, height) + x_dest = ray.Rectangle(x_x, x_y, width*scale, height*scale) + ray.draw_texture_pro(texture, x_source, x_dest, ray.Vector2(0,0), 0, ray.fade(ray.WHITE, self.fadein.attribute)) + + class BachiHit: + def __init__(self, current_ms: float): + self.resize = Animation(current_ms, 233.34, 'texture_resize') + self.resize.params['initial_size'] = 0.5 + self.resize.params['final_size'] = 1.5 + + self.fadein = Animation(current_ms, 116.67, 'fade') + self.fadein.params['initial_opacity'] = 0.0 + self.fadein.params['final_opacity'] = 1.0 + self.fadein.params['reverse'] = 0 + + self.sound_played = False + + def update(self, current_ms: float, sound): + if not self.sound_played: + audio.play_sound(sound) + self.sound_played = True + self.resize.start_ms = current_ms + self.fadein.start_ms = current_ms + self.resize.update(current_ms) + self.fadein.update(current_ms) + + def draw(self, texture): + scale = self.resize.attribute + width = texture.width + height = texture.height + hit_x = 350 + (width//2) - ((width * scale)//2) + hit_y = 225 + (height//2) - ((height * scale)//2) + hit_source = ray.Rectangle(0, 0, width, height) + hit_dest = ray.Rectangle(hit_x, hit_y, width*scale, height*scale) + ray.draw_texture_pro(texture, hit_source, hit_dest, ray.Vector2(0,0), 0, ray.fade(ray.WHITE, self.fadein.attribute)) + + class Characters: + def __init__(self, current_ms: float, start_ms: float): + self.start_ms = start_ms + self.current_ms = current_ms + self.shadow_fade = Animation(current_ms, 50, 'fade') + self.shadow_fade.params['delay'] = 16.67 + self.shadow_fade.params['initial_opacity'] = 0.75 + + self.animation_sequence = [(300.00, 5, 4), (183.33, 6, 4), (166.67, 7, 4), (166.67, 8, 9), (166.67, 11, 9), (166.67, 12, 9), (166.67, 13, 9), + (166.67, 5, 4), (150.00, 5, 4), (133.34, 6, 4), (133.34, 7, 4), (133.34, 8, 9), (133.34, 11, 9), (133.34, 12, 9), (133.34, 13, 9), + (133.34, 5, 4), (116.67, 5, 4), (100.00, 6, 4), (100.00, 7, 4), (100.00, 8, 9), (100.00, 11, 9), (100.00, 12, 9), (100.00, 13, 9), + (100.00, 5, 4), (100.00, 5, 4), (83.330, 6, 4), (83.330, 7, 4), (83.330, 8, 9), (83.330, 11, 9), (83.330, 12, 9), (83.330, 13, 9), + (83.330, 5, 4), (83.330, 5, 4), (66.670, 6, 4), (66.670, 7, 4), (66.670, 8, 9), (66.670, 11, 9), (66.670, 12, 9), (66.670, 13, 9), + (66.670, 5, 4), (66.670, 5, 4), (66.670, 6, 4), (66.670, 7, 4), (66.670, 8, 9), (66.670, 11, 9), (66.670, 12, 9), (66.670, 13, 9), + (66.670, 5, 4), (66.670, 5, 4), (66.670, 6, 4), (66.670, 7, 4), (66.670, 8, 9), (66.670, 11, 9), (66.670, 12, 9), (66.670, 13, 9), + (66.670, 17, 16)] + + + self.time = 0 + self.index_val = 0 + self.is_finished = False + + def character_index(self, index: int) -> int: + elapsed_time = self.current_ms - self.start_ms + delay = 566.67 + if self.index_val == len(self.animation_sequence)-1: + return int(self.animation_sequence[len(self.animation_sequence)-1][index]) + elif elapsed_time <= delay: + return int(self.animation_sequence[0][index]) + elif elapsed_time >= delay + self.time: + new_index = self.animation_sequence[self.index_val][index] + self.index_val += 1 + self.shadow_fade.start_ms = self.current_ms + self.shadow_fade.duration = int(self.animation_sequence[self.index_val][0]) + self.time += self.animation_sequence[self.index_val][0] + return int(new_index) + else: + return int(self.animation_sequence[self.index_val][index]) + + def update(self, current_ms: float): + self.shadow_fade.update(current_ms) + self.current_ms = current_ms + self.is_finished = True if self.character_index(1) == self.animation_sequence[-1][1] else False + + def draw(self, textures, fade: ray.Color, fade_2: ray.Color, y: int): + ray.draw_texture(textures['keikoku'][2], 135, y+textures['keikoku'][4].height+110, fade_2) + ray.draw_texture(textures['keikoku'][self.character_index(2)], 115, y+150, fade) + + ray.draw_texture(textures['keikoku'][3], 360, y+textures['keikoku'][5].height+60, fade_2) + + if 6 < self.character_index(1) < 17: + ray.draw_texture(textures['keikoku'][self.character_index(1) - 1], 315, y+100, ray.fade(ray.WHITE, self.shadow_fade.attribute)) + ray.draw_texture(textures['keikoku'][self.character_index(1)], 315, y+100, fade) + if self.character_index(1) == 17: + ray.draw_texture(textures['keikoku'][19], 350, y+135, ray.WHITE) + + class Board: + def __init__(self, current_ms: float, screen_width, screen_height, texture): + #Move warning board down from top of screen + self.move_down = Animation(current_ms, 266.67, 'move') + self.move_down.params['start_position'] = -720 + self.move_down.params['total_distance'] = screen_height + ((screen_height - texture.height)//2) + 20 + + #Move warning board up a little bit + self.move_up = Animation(current_ms, 116.67, 'move') + self.move_up.params['start_position'] = 92 + 20 + self.move_up.params['delay'] = self.move_down.duration + self.move_up.params['total_distance'] = -30 + + #And finally into its correct position + self.move_center = Animation(current_ms, 116.67, 'move') + self.move_center.params['start_position'] = 82 + self.move_center.params['delay'] = self.move_down.duration + self.move_up.duration + self.move_center.params['total_distance'] = 10 + self.y_pos = 0 + + def update(self, current_ms): + self.move_down.update(current_ms) + self.move_up.update(current_ms) + self.move_center.update(current_ms) + if self.move_up.is_finished: + self.y_pos = int(self.move_center.attribute) + elif self.move_down.is_finished: + self.y_pos = int(self.move_up.attribute) + else: + self.y_pos = int(self.move_down.attribute) + + def draw(self, texture): + ray.draw_texture(texture, 0, self.y_pos, ray.WHITE) + + + def __init__(self, current_ms: float, title_screen: TitleScreen): self.start_ms = current_ms - self.error_time = 4250 - #Move warning board down from top of screen - self.move_animation_1 = Animation(current_ms, 266.67, 'move') - self.move_animation_1.params['start_position'] = -720 - self.move_animation_1.params['total_distance'] = title_screen.height + ((title_screen.height - title_screen.texture_warning.height)//2) + 20 - - #Move warning board up a little bit - self.move_animation_2 = Animation(current_ms, 116.67, 'move') - self.move_animation_2.params['start_position'] = 92 + 20 - self.move_animation_2.params['delay'] = 266.67 - self.move_animation_2.params['total_distance'] = -30 - - #And finally into its correct position - self.move_animation_3 = Animation(current_ms, 116.67, 'move') - self.move_animation_3.params['start_position'] = 82 - self.move_animation_3.params['delay'] = 383.34 - self.move_animation_3.params['total_distance'] = 10 - - self.fade_animation_1 = Animation(current_ms, 300, 'fade') - self.fade_animation_1.params['delay'] = 266.67 - self.fade_animation_1.params['initial_opacity'] = 0.0 - self.fade_animation_1.params['final_opacity'] = 1.0 + self.fade_in = Animation(current_ms, 300, 'fade') + self.fade_in.params['delay'] = 266.67 + self.fade_in.params['initial_opacity'] = 0.0 + self.fade_in.params['final_opacity'] = 1.0 #Fade to black - self.fade_animation_2 = Animation(current_ms, 500, 'fade') - self.fade_animation_2.params['initial_opacity'] = 0.0 - self.fade_animation_2.params['final_opacity'] = 1.0 - self.fade_animation_2.params['delay'] = 500 + self.fade_out = Animation(current_ms, 500, 'fade') + self.fade_out.params['initial_opacity'] = 0.0 + self.fade_out.params['final_opacity'] = 1.0 + self.fade_out.params['delay'] = 1000 - self.fade_animation_3 = Animation(current_ms, 50, 'fade') - self.fade_animation_3.params['delay'] = 16.67 - self.fade_animation_3.params['initial_opacity'] = 0.75 - - self.resize_animation_1 = Animation(current_ms, 166.67, 'texture_resize') - self.resize_animation_1.params['initial_size'] = 1.0 - self.resize_animation_1.params['final_size'] = 1.5 - self.resize_animation_1.params['delay'] = self.error_time - self.resize_animation_1.params['reverse'] = 0 - - self.fade_animation_4 = Animation(current_ms, 166.67, 'fade') - self.fade_animation_4.params['delay'] = self.error_time - self.fade_animation_4.params['initial_opacity'] = 0.0 - self.fade_animation_4.params['final_opacity'] = 1.0 - self.fade_animation_4.params['reverse'] = 166.67 - - self.fade_animation_6 = Animation(current_ms, 166.67, 'fade') - self.fade_animation_6.params['delay'] = self.error_time + 166.67 + 166.67 - self.fade_animation_6.params['initial_opacity'] = 0.0 - self.fade_animation_6.params['final_opacity'] = 1.0 - - #Bachi hit - self.resize_animation_3 = Animation(current_ms, 233.34, 'texture_resize') - self.resize_animation_3.params['initial_size'] = 0.5 - self.resize_animation_3.params['final_size'] = 1.5 - - #Bachi hit - self.fade_animation_7 = Animation(current_ms, 116.67, 'fade') - self.fade_animation_7.params['initial_opacity'] = 0.0 - self.fade_animation_7.params['final_opacity'] = 1.0 - self.fade_animation_7.params['reverse'] = 0 + self.board = self.Board(current_ms, title_screen.width, title_screen.height, title_screen.textures['keikoku'][1]) + self.warning_x = self.X(current_ms) + self.warning_bachi_hit = self.BachiHit(current_ms) + self.characters = self.Characters(current_ms, self.start_ms) self.source_rect = ray.Rectangle(0, 0, title_screen.texture_black.width, title_screen.texture_black.height) self.dest_rect = ray.Rectangle(0, 0, title_screen.width, title_screen.height) - self.character_time = 0 - self.character_index_val = 0 - self.hit_played = False - self.error_played = False self.is_finished = False - self.attract_frame_index = 0 - - def load_next_attract(self, title_screen): - if title_screen.current_attract_video.convert_frames_background(self.attract_frame_index) == 0: - return 0 - self.attract_frame_index += 1 - - def update(self, current_ms, title_screen): - self.move_animation_1.update(current_ms) - self.move_animation_2.update(current_ms) - self.move_animation_3.update(current_ms) - self.fade_animation_1.update(current_ms) - self.fade_animation_2.update(current_ms) - self.fade_animation_3.update(current_ms) - self.fade_animation_4.update(current_ms) - self.fade_animation_6.update(current_ms) - self.resize_animation_1.update(current_ms) + def update(self, current_ms: float, title_screen: TitleScreen): + self.board.update(current_ms) + self.fade_in.update(current_ms) + self.fade_out.update(current_ms) delay = 566.67 elapsed_time = current_ms - self.start_ms - if self.character_index(1) != 8: - self.fade_animation_2.params['delay'] = elapsed_time + 500 + self.warning_x.update(current_ms, title_screen.sound_warning_error, elapsed_time) + self.characters.update(current_ms) + + if self.characters.is_finished: + self.warning_bachi_hit.update(current_ms, title_screen.sound_bachi_hit) + else: + self.fade_out.params['delay'] = elapsed_time + 500 if delay <= elapsed_time and not audio.is_sound_playing(title_screen.sound_bachi_swipe): audio.play_sound(title_screen.sound_warning_message) audio.play_sound(title_screen.sound_bachi_swipe) - elif self.character_index(1) == 8: - if not self.hit_played: - self.hit_played = True - audio.play_sound(title_screen.sound_bachi_hit) - self.resize_animation_3.start_ms = current_ms - self.fade_animation_7.start_ms = current_ms - self.resize_animation_3.update(current_ms) - self.fade_animation_7.update(current_ms) - if self.error_time + 166.67 <= elapsed_time and not self.error_played: - self.error_played = True - audio.play_sound(title_screen.sound_warning_error) - if self.fade_animation_2.is_finished: - self.is_finished = True + self.is_finished = self.fade_out.is_finished - def character_index(self, index): - elapsed_time = get_current_ms() - self.start_ms - delay = 566.67 - animation = [(300.00, 1, 0), (183.33, 2, 0), (166.67, 3, 0), (166.67, 4, 1), (166.67, 5, 1), (166.67, 6, 1), (166.67, 7, 1), - (166.67, 0, 0), (150.00, 1, 0), (133.34, 2, 0), (133.34, 3, 0), (133.34, 4, 1), (133.34, 5, 1), (133.34, 6, 1), (133.34, 7, 1), - (133.34, 0, 0), (116.67, 1, 0), (100.00, 2, 0), (100.00, 3, 0), (100.00, 4, 1), (100.00, 5, 1), (100.00, 6, 1), (100.00, 7, 1), - (100.00, 0, 0), (100.00, 1, 0), (83.330, 2, 0), (83.330, 3, 0), (83.330, 4, 1), (83.330, 5, 1), (83.330, 6, 1), (83.330, 7, 1), - (83.330, 0, 0), (83.330, 1, 0), (66.670, 2, 0), (66.670, 3, 0), (66.670, 4, 1), (66.670, 5, 1), (66.670, 6, 1), (66.670, 7, 1), - (66.670, 0, 0), (66.670, 1, 0), (66.670, 2, 0), (66.670, 3, 0), (66.670, 4, 1), (66.670, 5, 1), (66.670, 6, 1), (66.670, 7, 1), - (66.670, 0, 0), (66.670, 1, 0), (66.670, 2, 0), (66.670, 3, 0), (66.670, 4, 1), (66.670, 5, 1), (66.670, 6, 1), (66.670, 7, 1), - (66.670, 8, 2)] - if self.character_index_val == len(animation)-1: - return animation[len(animation)-1][index] - elif elapsed_time <= delay: - return 0 - elif elapsed_time >= delay + self.character_time: - new_index = animation[self.character_index_val][index] - self.character_index_val += 1 - self.fade_animation_3.start_ms = get_current_ms() - self.fade_animation_3.duration = int(animation[self.character_index_val][0]) - self.character_time += animation[self.character_index_val][0] - return new_index - else: - return animation[self.character_index_val][index] + def draw(self, title_screen: TitleScreen): + fade = ray.fade(ray.WHITE, self.fade_in.attribute) + fade_2 = ray.fade(ray.WHITE, self.fade_in.attribute if self.fade_in.attribute < 0.75 else 0.75) + self.board.draw(title_screen.textures['keikoku'][1]) + ray.draw_texture(title_screen.textures['keikoku'][15], 150, 200, ray.fade(ray.WHITE, self.warning_x.fadein_2.attribute)) - def draw(self, title_screen): - if self.move_animation_2.is_finished: - y = self.move_animation_3.attribute - elif self.move_animation_1.is_finished: - y = self.move_animation_2.attribute - else: - y = self.move_animation_1.attribute - ray.draw_texture(title_screen.texture_warning, 0, int(y), ray.WHITE) - fade = ray.fade(ray.WHITE, self.fade_animation_1.attribute) - fade_2 = ray.fade(ray.WHITE, self.fade_animation_1.attribute if self.fade_animation_1.attribute < 0.75 else 0.75) - ray.draw_texture(title_screen.texture_warning_x_2, 150, 200, ray.fade(ray.WHITE, self.fade_animation_6.attribute)) - ray.draw_texture(title_screen.texture_warning_ch1_base, 135, int(y)+title_screen.texture_warning_ch1[0].height+110, fade_2) - ray.draw_texture(title_screen.texture_warning_ch1[self.character_index(2)], 115, int(y)+150, fade) - ray.draw_texture(title_screen.texture_warning_ch2_base, 360, int(y)+title_screen.texture_warning_ch2[0].height+60, fade_2) - if 0 < self.character_index(1): - ray.draw_texture(title_screen.texture_warning_ch2[self.character_index(1)-1], 315, int(y)+100, ray.fade(ray.WHITE, self.fade_animation_3.attribute)) - ray.draw_texture(title_screen.texture_warning_ch2[self.character_index(1)], 315, int(y)+100, fade) - if self.character_index(1) == 8: - ray.draw_texture(title_screen.texture_warning_bachi, 350, int(y)+135, ray.WHITE) + self.characters.draw(title_screen.textures, fade, fade_2, self.board.y_pos) - scale = self.resize_animation_1.attribute - width = title_screen.texture_warning_x_1.width - height = title_screen.texture_warning_x_1.height - x_x = 150 + (width//2) - ((width * scale)//2) - x_y = 200 + (height//2) - ((height * scale)//2) - x_source = ray.Rectangle(0, 0, width, height) - x_dest = ray.Rectangle(x_x, x_y, width*scale, height*scale) - ray.draw_texture_pro(title_screen.texture_warning_x_1, x_source, x_dest, ray.Vector2(0,0), 0, ray.fade(ray.WHITE, self.fade_animation_4.attribute)) + self.warning_x.draw(title_screen.textures['keikoku'][14]) - scale = self.resize_animation_3.attribute - width = title_screen.texture_warning_bachi_hit.width - height = title_screen.texture_warning_bachi_hit.height - hit_x = 350 + (width//2) - ((width * scale)//2) - hit_y = 225 + (height//2) - ((height * scale)//2) - hit_source = ray.Rectangle(0, 0, width, height) - hit_dest = ray.Rectangle(hit_x, hit_y, width*scale, height*scale) - ray.draw_texture_pro(title_screen.texture_warning_bachi_hit, hit_source, hit_dest, ray.Vector2(0,0), 0, ray.fade(ray.WHITE, self.fade_animation_7.attribute)) - ray.draw_texture_pro(title_screen.texture_black, self.source_rect, self.dest_rect, ray.Vector2(0,0), 0, ray.fade(ray.WHITE, self.fade_animation_2.attribute)) + self.warning_bachi_hit.draw(title_screen.textures['keikoku'][18]) + + ray.draw_texture_pro(title_screen.texture_black, self.source_rect, self.dest_rect, ray.Vector2(0,0), 0, ray.fade(ray.WHITE, self.fade_out.attribute))