mirror of
https://github.com/Yonokid/PyTaiko.git
synced 2026-02-04 03:30:13 +01:00
Add animation restart method and new backgrounds
This commit adds a new `restart()` method to animation classes to properly reset their state, avoiding the need to recreate animations. It also adds several new background variations and improves background selection.
This commit is contained in:
@@ -13,6 +13,7 @@ from libs.utils import (
|
||||
is_r_don_pressed,
|
||||
is_r_kat_pressed,
|
||||
load_all_textures_from_zip,
|
||||
load_texture_from_zip,
|
||||
)
|
||||
|
||||
|
||||
@@ -32,6 +33,7 @@ class EntryScreen:
|
||||
|
||||
def load_textures(self):
|
||||
self.textures = load_all_textures_from_zip(Path('Graphics/lumendata/entry.zip'))
|
||||
self.texture_black = load_texture_from_zip(Path('Graphics/lumendata/attract/movie.zip'), 'movie_img00000.png')
|
||||
|
||||
def unload_textures(self):
|
||||
for group in self.textures:
|
||||
@@ -42,6 +44,7 @@ class EntryScreen:
|
||||
sounds_dir = Path("Sounds")
|
||||
self.sound_don = audio.load_sound(sounds_dir / "inst_00_don.wav")
|
||||
self.sound_kat = audio.load_sound(sounds_dir / "inst_00_katsu.wav")
|
||||
self.bgm = audio.load_sound(sounds_dir / "entry" / "JINGLE_ENTRY [1].ogg")
|
||||
|
||||
def on_screen_start(self):
|
||||
if not self.screen_init:
|
||||
@@ -58,14 +61,21 @@ class EntryScreen:
|
||||
self.cloud_resize = None
|
||||
self.cloud_texture_change = None
|
||||
self.cloud_fade = None
|
||||
self.fade_out = None
|
||||
self.cloud_resize_loop = Animation.create_texture_resize(200, initial_size=1.0, final_size=1.1, reverse_delay=200)
|
||||
self.side_select_fade = Animation.create_fade(100, initial_opacity=0.0, final_opacity=1.0)
|
||||
self.bg_flicker = Animation.create_fade(500, initial_opacity=0.5, final_opacity=0.4, reverse_delay=0)
|
||||
audio.play_sound(self.bgm)
|
||||
|
||||
def on_screen_end(self, next_screen: str):
|
||||
self.screen_init = False
|
||||
self.unload_textures()
|
||||
audio.stop_sound(self.bgm)
|
||||
return next_screen
|
||||
|
||||
def handle_input(self):
|
||||
if self.fade_out is not None:
|
||||
return
|
||||
if self.state == State.SELECT_SIDE:
|
||||
if is_l_don_pressed() or is_r_don_pressed():
|
||||
if self.side == 1:
|
||||
@@ -89,10 +99,7 @@ class EntryScreen:
|
||||
elif self.state == State.SELECT_MODE:
|
||||
if is_l_don_pressed() or is_r_don_pressed():
|
||||
audio.play_sound(self.sound_don)
|
||||
if self.selected_box == 0:
|
||||
return self.on_screen_end("SONG_SELECT")
|
||||
elif self.selected_box == 1:
|
||||
return self.on_screen_end("SETTINGS")
|
||||
self.fade_out = Animation.create_fade(160)
|
||||
if is_l_kat_pressed():
|
||||
audio.play_sound(self.sound_kat)
|
||||
self.selected_box = max(0, self.selected_box - 1)
|
||||
@@ -102,6 +109,10 @@ class EntryScreen:
|
||||
|
||||
def update(self):
|
||||
self.on_screen_start()
|
||||
self.side_select_fade.update(get_current_ms())
|
||||
self.bg_flicker.update(get_current_ms())
|
||||
if self.bg_flicker.is_finished:
|
||||
self.bg_flicker.restart()
|
||||
if self.drum_move_1 is not None:
|
||||
self.drum_move_1.update(get_current_ms())
|
||||
if self.drum_move_2 is not None:
|
||||
@@ -117,6 +128,13 @@ class EntryScreen:
|
||||
self.cloud_resize_loop.update(get_current_ms())
|
||||
if self.cloud_resize_loop.is_finished:
|
||||
self.cloud_resize_loop = Animation.create_texture_resize(200, initial_size=1.0, final_size=1.1, reverse_delay=200)
|
||||
if self.fade_out is not None:
|
||||
self.fade_out.update(get_current_ms())
|
||||
if self.fade_out.is_finished:
|
||||
if self.selected_box == 0:
|
||||
return self.on_screen_end("SONG_SELECT")
|
||||
elif self.selected_box == 1:
|
||||
return self.on_screen_end("SETTINGS")
|
||||
return self.handle_input()
|
||||
|
||||
def draw_background(self):
|
||||
@@ -130,7 +148,7 @@ class EntryScreen:
|
||||
ray.draw_texture(self.textures['entry'][371], (self.width // 2) - (self.textures['entry'][371].width // 2), (self.height // 2) - (self.textures['entry'][371].height // 2) + 10, ray.WHITE)
|
||||
ray.draw_texture(self.textures['entry'][372], 0, 0, ray.WHITE)
|
||||
ray.draw_texture(self.textures['entry'][373], self.width - self.textures['entry'][373].width, 0, ray.WHITE)
|
||||
draw_scaled_texture(self.textures['entry'][374], -7, -15, 2.0, ray.fade(ray.WHITE, 0.50))
|
||||
draw_scaled_texture(self.textures['entry'][374], -7, -15, 2.0, ray.fade(ray.WHITE, self.bg_flicker.attribute))
|
||||
|
||||
def draw_footer(self):
|
||||
ray.draw_texture(self.textures['entry'][375], 1, self.height - self.textures['entry'][375].height + 7, ray.WHITE)
|
||||
@@ -139,37 +157,38 @@ class EntryScreen:
|
||||
if self.state == State.SELECT_SIDE or self.side != 2:
|
||||
ray.draw_texture(self.textures['entry'][377], 2 + self.textures['entry'][377].width, self.height - self.textures['entry'][376].height + 1, ray.WHITE)
|
||||
|
||||
def draw_side_select(self):
|
||||
def draw_side_select(self, fade):
|
||||
color = ray.fade(ray.WHITE, fade)
|
||||
left_x, top_y, right_x, bottom_y = 238, 108, 979, 520
|
||||
ray.draw_texture(self.textures['entry'][205], left_x, top_y, ray.WHITE)
|
||||
ray.draw_texture(self.textures['entry'][208], right_x, top_y, ray.WHITE)
|
||||
ray.draw_texture(self.textures['entry'][204], left_x, bottom_y, ray.WHITE)
|
||||
ray.draw_texture(self.textures['entry'][207], right_x, bottom_y, ray.WHITE)
|
||||
ray.draw_texture(self.textures['entry'][205], left_x, top_y, color)
|
||||
ray.draw_texture(self.textures['entry'][208], right_x, top_y, color)
|
||||
ray.draw_texture(self.textures['entry'][204], left_x, bottom_y, color)
|
||||
ray.draw_texture(self.textures['entry'][207], right_x, bottom_y, color)
|
||||
|
||||
texture = self.textures['entry'][209]
|
||||
src = ray.Rectangle(0, 0, texture.width, texture.height)
|
||||
dest = ray.Rectangle(left_x + self.textures['entry'][205].width, top_y, right_x - left_x - (self.textures['entry'][205].width), texture.height)
|
||||
ray.draw_texture_pro(texture, src, dest, ray.Vector2(0, 0), 0, ray.WHITE)
|
||||
ray.draw_texture_pro(texture, src, dest, ray.Vector2(0, 0), 0, color)
|
||||
texture = self.textures['entry'][210]
|
||||
src = ray.Rectangle(0, 0, texture.width, texture.height)
|
||||
dest = ray.Rectangle(left_x + self.textures['entry'][205].width, bottom_y, right_x - left_x - (self.textures['entry'][205].width), texture.height)
|
||||
ray.draw_texture_pro(texture, src, dest, ray.Vector2(0, 0), 0, ray.WHITE)
|
||||
ray.draw_texture_pro(texture, src, dest, ray.Vector2(0, 0), 0, color)
|
||||
|
||||
texture = self.textures['entry'][203]
|
||||
src = ray.Rectangle(0, 0, texture.width, texture.height)
|
||||
dest = ray.Rectangle(left_x, top_y + self.textures['entry'][205].height, texture.width, bottom_y - top_y - (self.textures['entry'][205].height))
|
||||
ray.draw_texture_pro(texture, src, dest, ray.Vector2(0, 0), 0, ray.WHITE)
|
||||
ray.draw_texture_pro(texture, src, dest, ray.Vector2(0, 0), 0, color)
|
||||
texture = self.textures['entry'][206]
|
||||
src = ray.Rectangle(0, 0, texture.width, texture.height)
|
||||
dest = ray.Rectangle(right_x, top_y + self.textures['entry'][205].height, texture.width, bottom_y - top_y - (self.textures['entry'][205].height))
|
||||
ray.draw_texture_pro(texture, src, dest, ray.Vector2(0, 0), 0, ray.WHITE)
|
||||
ray.draw_texture_pro(texture, src, dest, ray.Vector2(0, 0), 0, color)
|
||||
|
||||
texture = self.textures['entry'][202]
|
||||
src = ray.Rectangle(0, 0, texture.width, texture.height)
|
||||
dest = ray.Rectangle(left_x + self.textures['entry'][205].width, top_y + self.textures['entry'][205].height, right_x - left_x - (self.textures['entry'][205].width), bottom_y - top_y - (self.textures['entry'][205].height))
|
||||
ray.draw_texture_pro(texture, src, dest, ray.Vector2(0, 0), 0, ray.WHITE)
|
||||
ray.draw_texture_pro(texture, src, dest, ray.Vector2(0, 0), 0, color)
|
||||
|
||||
ray.draw_texture(self.textures['entry'][226], 384, 144, ray.WHITE)
|
||||
ray.draw_texture(self.textures['entry'][226], 384, 144, color)
|
||||
|
||||
cursor_x = 261
|
||||
cursor_texture = self.textures['entry'][230]
|
||||
@@ -179,7 +198,7 @@ class EntryScreen:
|
||||
flip = -1
|
||||
else:
|
||||
texture = self.textures['entry'][232]
|
||||
ray.draw_texture(texture, 261, 400, ray.WHITE)
|
||||
ray.draw_texture(texture, 261, 400, color)
|
||||
|
||||
if self.side == 1:
|
||||
texture = self.textures['entry'][76]
|
||||
@@ -187,19 +206,19 @@ class EntryScreen:
|
||||
cursor_x = 512
|
||||
else:
|
||||
texture = self.textures['entry'][228]
|
||||
ray.draw_texture(texture, 512, 400, ray.WHITE)
|
||||
ray.draw_texture(self.textures['entry'][201], 512, 408, ray.WHITE)
|
||||
ray.draw_texture(texture, 512, 400, color)
|
||||
ray.draw_texture(self.textures['entry'][201], 512, 408, color)
|
||||
|
||||
if self.side == 2:
|
||||
texture = self.textures['entry'][233]
|
||||
cursor_x = 762
|
||||
else:
|
||||
texture = self.textures['entry'][227]
|
||||
ray.draw_texture(texture, 762, 400, ray.WHITE)
|
||||
ray.draw_texture(texture, 762, 400, color)
|
||||
|
||||
src = ray.Rectangle(0, 0, cursor_texture.width * flip, cursor_texture.height)
|
||||
dest = ray.Rectangle(cursor_x, 400, cursor_texture.width, cursor_texture.height)
|
||||
ray.draw_texture_pro(cursor_texture, src, dest, ray.Vector2(0, 0), 0, ray.WHITE)
|
||||
ray.draw_texture_pro(cursor_texture, src, dest, ray.Vector2(0, 0), 0, color)
|
||||
|
||||
def draw_player_drum(self):
|
||||
move_x = 0
|
||||
@@ -230,8 +249,9 @@ class EntryScreen:
|
||||
color = ray.fade(ray.WHITE, self.cloud_fade.attribute)
|
||||
draw_scaled_texture(self.textures['entry'][texture_index], x + move_x - int(160 * (scale-1)), 720 + move_y - 200 - int(160 * (scale-1)), scale, color)
|
||||
|
||||
def draw_mode_select(self):
|
||||
def draw_mode_select(self, fade):
|
||||
self.draw_player_drum()
|
||||
color = ray.fade(ray.WHITE, fade)
|
||||
if self.cloud_fade is not None and self.cloud_fade.is_finished:
|
||||
box_width = self.textures['entry'][262].width
|
||||
spacing = 80
|
||||
@@ -248,31 +268,39 @@ class EntryScreen:
|
||||
else:
|
||||
push_offset = push_distance
|
||||
final_x = x_pos + push_offset
|
||||
ray.draw_texture(self.textures['entry'][262], final_x, y, ray.WHITE)
|
||||
ray.draw_texture(self.textures['entry'][262], final_x, y, color)
|
||||
if i == self.selected_box:
|
||||
ray.draw_texture(self.textures['entry'][302], final_x, y, ray.WHITE)
|
||||
ray.draw_texture(self.textures['entry'][302], final_x, y, color)
|
||||
texture = self.textures['entry'][304]
|
||||
src = ray.Rectangle(0, 0, texture.width, texture.height)
|
||||
dest = ray.Rectangle(final_x + self.textures['entry'][302].width, y, 100 - self.textures['entry'][302].width, texture.height)
|
||||
ray.draw_texture_pro(texture, src, dest, ray.Vector2(0, 0), 0, ray.WHITE)
|
||||
ray.draw_texture(self.textures['entry'][303], final_x+100, y, ray.WHITE)
|
||||
ray.draw_texture_pro(texture, src, dest, ray.Vector2(0, 0), 0, color)
|
||||
ray.draw_texture(self.textures['entry'][303], final_x+100, y, color)
|
||||
|
||||
box_title = self.box_titles[i][1]
|
||||
src = ray.Rectangle(0, 0, box_title.texture.width, box_title.texture.height)
|
||||
dest = ray.Rectangle(final_x + 12, y + 20, box_title.texture.width, box_title.texture.height)
|
||||
box_title.draw(src, dest, ray.Vector2(0, 0), 0, ray.WHITE)
|
||||
box_title.draw(src, dest, ray.Vector2(0, 0), 0, color)
|
||||
else:
|
||||
box_title = self.box_titles[i][0]
|
||||
src = ray.Rectangle(0, 0, box_title.texture.width, box_title.texture.height)
|
||||
dest = ray.Rectangle(final_x + 9, y + 20, box_title.texture.width, box_title.texture.height)
|
||||
box_title.draw(src, dest, ray.Vector2(0, 0), 0, ray.WHITE)
|
||||
box_title.draw(src, dest, ray.Vector2(0, 0), 0, color)
|
||||
|
||||
def draw(self):
|
||||
self.draw_background()
|
||||
if self.state == State.SELECT_SIDE:
|
||||
self.draw_side_select()
|
||||
self.draw_side_select(self.side_select_fade.attribute)
|
||||
elif self.state == State.SELECT_MODE:
|
||||
self.draw_mode_select()
|
||||
if self.fade_out is not None:
|
||||
self.draw_mode_select(self.fade_out.attribute)
|
||||
else:
|
||||
self.draw_mode_select(1.0)
|
||||
self.draw_footer()
|
||||
|
||||
ray.draw_texture(self.textures['entry'][320], 0, 0, ray.WHITE)
|
||||
|
||||
if self.fade_out is not None and self.fade_out.is_finished:
|
||||
src = ray.Rectangle(0, 0, self.texture_black.width, self.texture_black.height)
|
||||
dest = ray.Rectangle(0, 0, self.width, self.height)
|
||||
ray.draw_texture_pro(self.texture_black, src, dest, ray.Vector2(0, 0), 0, ray.WHITE)
|
||||
|
||||
Reference in New Issue
Block a user