added base score animation

This commit is contained in:
Yonokid
2024-09-01 16:03:20 -04:00
parent 511ae64ccc
commit 9dad5356ee
2 changed files with 139 additions and 106 deletions

223
game.py
View File

@@ -147,6 +147,10 @@ class GameScreen:
ray.load_texture(folder_path + 'action_fusen_1p_img00008.png'), ray.load_texture(folder_path + 'action_fusen_1p_img00008.png'),
ray.load_texture(folder_path + 'action_fusen_1p_img00009.png'), ray.load_texture(folder_path + 'action_fusen_1p_img00009.png'),
ray.load_texture(folder_path + 'action_fusen_1p_img00010.png')] ray.load_texture(folder_path + '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(ray.load_texture(folder_path + filename))
def load_sounds(self): def load_sounds(self):
self.sound_don = ray.load_sound('Sounds\\inst_00_don.wav') self.sound_don = ray.load_sound('Sounds\\inst_00_don.wav')
@@ -231,6 +235,7 @@ class Player:
self.balloon_list = [] self.balloon_list = []
self.combo_list = [] self.combo_list = []
self.score_list = [] self.score_list = []
self.base_score_list = []
def calculate_base_score(self): def calculate_base_score(self):
total_notes = 0 total_notes = 0
@@ -356,6 +361,7 @@ class Player:
self.draw_arc_list.append(NoteArc(note_type, game_screen.current_ms, self.player_number)) self.draw_arc_list.append(NoteArc(note_type, game_screen.current_ms, self.player_number))
self.curr_drumroll_count += 1 self.curr_drumroll_count += 1
self.score += 100 self.score += 100
self.base_score_list.append(ScoreCounterAnimation(game_screen.current_ms, 100))
color = 255 - (self.curr_drumroll_count*10) color = 255 - (self.curr_drumroll_count*10)
if color < 0: if color < 0:
self.current_notes_draw[0]['color'] = 0 self.current_notes_draw[0]['color'] = 0
@@ -369,6 +375,7 @@ class Player:
self.balloon_list.append(BalloonAnimation(game_screen.current_ms, current_note['balloon'])) self.balloon_list.append(BalloonAnimation(game_screen.current_ms, current_note['balloon']))
self.curr_balloon_count += 1 self.curr_balloon_count += 1
self.score += 100 self.score += 100
self.base_score_list.append(ScoreCounterAnimation(game_screen.current_ms, 100))
self.current_notes_draw[0]['popped'] = False self.current_notes_draw[0]['popped'] = False
if self.curr_balloon_count == current_note['balloon']: if self.curr_balloon_count == current_note['balloon']:
self.is_balloon = False self.is_balloon = False
@@ -399,12 +406,14 @@ class Player:
self.draw_effect_list.append(LaneHitEffect(game_screen.current_ms, 'GOOD')) self.draw_effect_list.append(LaneHitEffect(game_screen.current_ms, 'GOOD'))
self.good_count += 1 self.good_count += 1
self.score += self.base_score self.score += self.base_score
self.base_score_list.append(ScoreCounterAnimation(game_screen.current_ms, self.base_score))
self.note_correct(game_screen, current_note) self.note_correct(game_screen, current_note)
elif (note_ms - self.timing_ok) + self.judge_offset <= game_screen.current_ms <= (note_ms + self.timing_ok) + self.judge_offset: elif (note_ms - self.timing_ok) + self.judge_offset <= game_screen.current_ms <= (note_ms + self.timing_ok) + self.judge_offset:
self.draw_judge_list.append(Judgement(game_screen.current_ms, 'OK', big)) self.draw_judge_list.append(Judgement(game_screen.current_ms, 'OK', big))
self.ok_count += 1 self.ok_count += 1
self.score += 10 * math.floor(self.base_score / 2 / 10) self.score += 10 * math.floor(self.base_score / 2 / 10)
self.base_score_list.append(ScoreCounterAnimation(game_screen.current_ms, 10 * math.floor(self.base_score / 2 / 10)))
self.note_correct(game_screen, current_note) self.note_correct(game_screen, current_note)
elif (note_ms - self.timing_bad) + self.judge_offset <= game_screen.current_ms <= (note_ms + self.timing_bad) + self.judge_offset: elif (note_ms - self.timing_bad) + self.judge_offset <= game_screen.current_ms <= (note_ms + self.timing_bad) + self.judge_offset:
@@ -448,22 +457,22 @@ class Player:
self.score_list[0].update(game_screen.current_ms, self.score) self.score_list[0].update(game_screen.current_ms, self.score)
def key_manager(self, game_screen): def key_manager(self, game_screen):
if ray.is_key_pressed(ray.KeyboardKey.KEY_F): if ray.is_key_pressed(ray.KeyboardKey.KEY_F) or ray.is_key_pressed(ray.KeyboardKey.KEY_D):
self.draw_effect_list.append(LaneHitEffect(game_screen.current_ms, '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')) self.draw_drum_hit_list.append(DrumHitEffect(game_screen.current_ms, 'DON', 'L'))
ray.play_sound(game_screen.sound_don) ray.play_sound(game_screen.sound_don)
self.check_note(game_screen, '1') self.check_note(game_screen, '1')
if ray.is_key_pressed(ray.KeyboardKey.KEY_J): if ray.is_key_pressed(ray.KeyboardKey.KEY_J) or ray.is_key_pressed(ray.KeyboardKey.KEY_K):
self.draw_effect_list.append(LaneHitEffect(game_screen.current_ms, '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')) self.draw_drum_hit_list.append(DrumHitEffect(game_screen.current_ms, 'DON', 'R'))
ray.play_sound(game_screen.sound_don) ray.play_sound(game_screen.sound_don)
self.check_note(game_screen, '1') self.check_note(game_screen, '1')
if ray.is_key_pressed(ray.KeyboardKey.KEY_E): if ray.is_key_pressed(ray.KeyboardKey.KEY_E) or ray.is_key_pressed(ray.KeyboardKey.KEY_R):
self.draw_effect_list.append(LaneHitEffect(game_screen.current_ms, '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')) self.draw_drum_hit_list.append(DrumHitEffect(game_screen.current_ms, 'KAT', 'L'))
ray.play_sound(game_screen.sound_kat) ray.play_sound(game_screen.sound_kat)
self.check_note(game_screen, '2') self.check_note(game_screen, '2')
if ray.is_key_pressed(ray.KeyboardKey.KEY_I): if ray.is_key_pressed(ray.KeyboardKey.KEY_I) or ray.is_key_pressed(ray.KeyboardKey.KEY_U):
self.draw_effect_list.append(LaneHitEffect(game_screen.current_ms, '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')) self.draw_drum_hit_list.append(DrumHitEffect(game_screen.current_ms, 'KAT', 'R'))
ray.play_sound(game_screen.sound_kat) ray.play_sound(game_screen.sound_kat)
@@ -479,6 +488,7 @@ class Player:
self.animation_manager(game_screen, self.draw_effect_list) self.animation_manager(game_screen, self.draw_effect_list)
self.animation_manager(game_screen, self.draw_drum_hit_list) 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.draw_arc_list)
self.animation_manager(game_screen, self.base_score_list)
self.score_manager(game_screen) self.score_manager(game_screen)
self.key_manager(game_screen) self.key_manager(game_screen)
@@ -503,13 +513,9 @@ class Player:
drumroll_length = 47 drumroll_length = 47
if tail['note'] == '8': if tail['note'] == '8':
drumroll_end_position = self.get_position(game_screen, tail['load_ms'], tail['ppf']) drumroll_end_position = self.get_position(game_screen, tail['load_ms'], tail['ppf'])
distance = ((drumroll_end_position - drumroll_start_position) / drumroll_length) - 1 length = (drumroll_end_position - drumroll_start_position - 50)
if distance > 0: self.draw_note(game_screen, drumroll_body, (drumroll_start_position+64), color, drumroll_length=length)
for i in range(int(distance)): self.draw_note(game_screen, drumroll_tail, drumroll_end_position, color, drumroll_length=None)
self.draw_note(game_screen, drumroll_body, (drumroll_start_position + 64) + (i*drumroll_length), color)
self.draw_note(game_screen, drumroll_body, drumroll_end_position - drumroll_length, color)
self.draw_note(game_screen, drumroll_tail, drumroll_end_position, color)
drumroll_end_position = 0
def draw_balloon(self, game_screen, note, position, index): def draw_balloon(self, game_screen, note, position, index):
end_time = self.current_notes_draw[index+1] end_time = self.current_notes_draw[index+1]
@@ -524,7 +530,7 @@ class Player:
position = 349 position = 349
self.draw_note(game_screen, '7', position, 255) self.draw_note(game_screen, '7', position, 255)
def draw_note(self, game_screen, note, position, color): def draw_note(self, game_screen, note, position, color, drumroll_length=None):
note_padding = 64 note_padding = 64
if note == 'barline': if note == 'barline':
y = 184 y = 184
@@ -545,7 +551,12 @@ class Player:
else: else:
offset = 0 offset = 0
balloon = False balloon = False
ray.draw_texture(game_screen.note_type_dict[note][current_eighth % 2], position-offset, 192, ray.Color(255, draw_color, draw_color, 255)) source_rect = ray.Rectangle(0,0,game_screen.note_type_dict[note][0].width,game_screen.note_type_dict[note][0].height)
if drumroll_length == None:
dest_rect = ray.Rectangle(position-offset, 192, game_screen.note_type_dict[note][0].width,game_screen.note_type_dict[note][0].height)
else:
dest_rect = ray.Rectangle(position-offset, 192, drumroll_length,game_screen.note_type_dict['1'][0].height)
ray.draw_texture_pro(game_screen.note_type_dict[note][current_eighth % 2], source_rect, dest_rect, ray.Vector2(0,0), 0, ray.Color(255, draw_color, draw_color, 255))
if balloon: if balloon:
ray.draw_texture(game_screen.note_type_dict['balloon_tail'][current_eighth % 2], position-offset+128, 192, ray.Color(255, draw_color, draw_color, 255)) ray.draw_texture(game_screen.note_type_dict['balloon_tail'][current_eighth % 2], position-offset+128, 192, ray.Color(255, draw_color, draw_color, 255))
@@ -589,6 +600,7 @@ class Player:
self.draw_animation_list(game_screen, self.draw_arc_list) 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.balloon_list)
self.draw_animation_list(game_screen, self.score_list) self.draw_animation_list(game_screen, self.score_list)
self.draw_animation_list(game_screen, self.base_score_list)
class Judgement: class Judgement:
def __init__(self, current_ms, type, big): def __init__(self, current_ms, type, big):
@@ -743,34 +755,18 @@ class DrumrollCounter:
self.is_finished = False self.is_finished = False
self.total_duration = 1349 self.total_duration = 1349
self.drumroll_count = 0 self.drumroll_count = 0
self.counter_stretch = 0
self.start_stretch = None
self.is_stretching = False
self.fade_animation = Animation(current_ms, 166, 'fade') self.fade_animation = Animation(current_ms, 166, 'fade')
self.fade_animation.params['delay'] = self.total_duration - 166 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, count, elapsed_time):
self.total_duration = elapsed_time + 1349 self.total_duration = elapsed_time + 1349
if self.drumroll_count != count: if self.drumroll_count != count:
self.drumroll_count = count self.drumroll_count = count
self.start_stretch = current_ms self.stretch_animation = Animation(current_ms, 50, 'text_stretch')
self.is_stretching = True
def update_stretch(self, current_ms):
if not self.is_stretching:
return
elapsed_time = current_ms - self.start_stretch
if elapsed_time <= 50:
self.counter_stretch = 2 + 5 * (elapsed_time // 25)
elif elapsed_time <= 50 + 116:
frame_time = (elapsed_time - 50) // 16.57
self.counter_stretch = 2 + 10 - (2 * (frame_time + 1))
else:
self.counter_stretch = 0
self.is_stretching = False
def update(self, game_screen, current_ms, drumroll_count): def update(self, game_screen, current_ms, drumroll_count):
self.update_stretch(current_ms) self.stretch_animation.update(current_ms)
self.fade_animation.update(current_ms) self.fade_animation.update(current_ms)
elapsed_time = current_ms - self.create_ms elapsed_time = current_ms - self.create_ms
@@ -787,7 +783,7 @@ class DrumrollCounter:
start_x = 344 - (total_width // 2) 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) 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)): for i in range(len(counter)):
dest_rect = ray.Rectangle(start_x + (i * 52), 50 - self.counter_stretch, game_screen.texture_drumroll_number[0].width, game_screen.texture_drumroll_number[0].height + self.counter_stretch) 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.texture_balloon_number[int(counter[i])], source_rect, dest_rect, ray.Vector2(0,0), 0, color)
class BalloonAnimation: class BalloonAnimation:
@@ -795,50 +791,32 @@ class BalloonAnimation:
self.create_ms = current_ms self.create_ms = current_ms
self.is_finished = False self.is_finished = False
self.total_duration = 83.33 self.total_duration = 83.33
self.fade = 1 self.color = ray.fade(ray.WHITE, 1.0)
self.color = ray.fade(ray.WHITE, self.fade)
self.balloon_count = 0 self.balloon_count = 0
self.balloon_total = balloon_total self.balloon_total = balloon_total
self.is_popped = False self.is_popped = False
self.counter_stretch = 0 self.fade_animation = Animation(current_ms, 166, 'fade')
self.start_stretch = None self.stretch_animation = Animation(current_ms, 0, 'text_stretch')
self.is_stretching = False
def update_count(self, current_ms, balloon_count): def update_count(self, current_ms, balloon_count):
if self.balloon_count != balloon_count: if self.balloon_count != balloon_count:
self.balloon_count = balloon_count self.balloon_count = balloon_count
self.start_stretch = current_ms self.stretch_animation = Animation(current_ms, 50, 'text_stretch')
self.is_stretching = True
def update_stretch(self, current_ms):
if not self.is_stretching:
return
elapsed_time = current_ms - self.start_stretch
if elapsed_time <= 50:
self.counter_stretch = 2 + 5 * (elapsed_time // 25)
elif elapsed_time <= 50 + 116:
frame_time = (elapsed_time - 50) // 16.57
self.counter_stretch = 2 + 10 - (2 * (frame_time + 1))
else:
self.counter_stretch = 0
self.is_stretching = False
def update(self, game_screen, current_ms, balloon_count, is_popped): def update(self, game_screen, current_ms, balloon_count, is_popped):
self.update_count(current_ms, balloon_count) self.update_count(current_ms, balloon_count)
self.update_stretch(current_ms) self.stretch_animation.update(current_ms)
self.is_popped = is_popped self.is_popped = is_popped
elapsed_time = current_ms - self.create_ms elapsed_time = current_ms - self.create_ms
fade_start_time = self.total_duration - 166
if self.is_popped: if self.is_popped:
if elapsed_time >= fade_start_time: self.fade_animation.update(current_ms)
fade_progress = (elapsed_time - fade_start_time) / 166 self.color = ray.fade(ray.WHITE, self.fade_animation.attribute)
self.fade = 1 - fade_progress
self.color = ray.fade(ray.WHITE, self.fade)
if elapsed_time > self.total_duration:
self.is_finished = True
else: else:
self.total_duration = elapsed_time + 166 self.total_duration = elapsed_time + 166
self.fade_animation.params['delay'] = self.total_duration - 166
if self.fade_animation.is_finished:
self.is_finished = True
def draw(self, game_screen): def draw(self, game_screen):
if self.is_popped: if self.is_popped:
@@ -855,15 +833,13 @@ class BalloonAnimation:
start_x = x - (total_width // 2) 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.texture_balloon_number[0].width, game_screen.texture_balloon_number[0].height)
for i in range(len(counter)): for i in range(len(counter)):
dest_rect = ray.Rectangle(start_x + (i * margin), y - self.counter_stretch, game_screen.texture_balloon_number[0].width, game_screen.texture_balloon_number[0].height + self.counter_stretch) 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) ray.draw_texture_pro(game_screen.texture_balloon_number[int(counter[i])], source_rect, dest_rect, ray.Vector2(0,0), 0, self.color)
class Combo: class Combo:
def __init__(self, combo, current_ms): def __init__(self, combo, current_ms):
self.combo = combo self.combo = combo
self.counter_stretch = 0 self.stretch_animation = Animation(current_ms, 0, 'text_stretch')
self.start_stretch = None
self.is_stretching = False
self.color = [ray.fade(ray.WHITE, 1), ray.fade(ray.WHITE, 1), ray.fade(ray.WHITE, 1)] self.color = [ray.fade(ray.WHITE, 1), ray.fade(ray.WHITE, 1), ray.fade(ray.WHITE, 1)]
self.glimmer_dict = {0: 0, 1: 0, 2: 0} self.glimmer_dict = {0: 0, 1: 0, 2: 0}
self.total_time = 250 self.total_time = 250
@@ -877,25 +853,11 @@ class Combo:
def update_count(self, current_ms, combo): def update_count(self, current_ms, combo):
if self.combo != combo: if self.combo != combo:
self.combo = combo self.combo = combo
self.start_stretch = current_ms self.stretch_animation = Animation(current_ms, 50, 'text_stretch')
self.is_stretching = True
def update_stretch(self, current_ms):
if not self.is_stretching:
return
elapsed_time = current_ms - self.start_stretch
if elapsed_time <= 50:
self.counter_stretch = 2 + (5 * (elapsed_time // 25))
elif elapsed_time <= 50 + 100:
frame_time = (elapsed_time - 50) // 16.57
self.counter_stretch = 2 + (10 - (2 * (frame_time + 1)))
else:
self.counter_stretch = 0
self.is_stretching = False
def update(self, game_screen, current_ms, combo): def update(self, game_screen, current_ms, combo):
self.update_count(current_ms, combo) self.update_count(current_ms, combo)
self.update_stretch(current_ms) self.stretch_animation.update(current_ms)
for i in range(3): for i in range(3):
elapsed_time = current_ms - self.start_times[i] elapsed_time = current_ms - self.start_times[i]
@@ -929,7 +891,7 @@ class Combo:
start_x = x - (total_width // 2) start_x = x - (total_width // 2)
source_rect = ray.Rectangle(0, 0, game_screen.texture_combo_numbers[0].width, game_screen.texture_combo_numbers[0].height) source_rect = ray.Rectangle(0, 0, game_screen.texture_combo_numbers[0].width, game_screen.texture_combo_numbers[0].height)
for i in range(len(counter)): for i in range(len(counter)):
dest_rect = ray.Rectangle(start_x + (i * margin), y - self.counter_stretch, game_screen.texture_combo_numbers[0].width, game_screen.texture_combo_numbers[0].height + self.counter_stretch) dest_rect = ray.Rectangle(start_x + (i * margin), y - self.stretch_animation.attribute, game_screen.texture_combo_numbers[0].width, game_screen.texture_combo_numbers[0].height + self.stretch_animation.attribute)
ray.draw_texture_pro(game_screen.texture_combo_numbers[int(counter[i]) + (text_color*10)], source_rect, dest_rect, ray.Vector2(0,0), 0, ray.WHITE) ray.draw_texture_pro(game_screen.texture_combo_numbers[int(counter[i]) + (text_color*10)], source_rect, dest_rect, ray.Vector2(0,0), 0, ray.WHITE)
glimmer_positions = [(225, 210), (200, 230), (250, 230)] glimmer_positions = [(225, 210), (200, 230), (250, 230)]
if self.combo >= 100: if self.combo >= 100:
@@ -941,32 +903,16 @@ class ScoreCounter:
def __init__(self, score, current_ms): def __init__(self, score, current_ms):
self.score = score self.score = score
self.create_ms = current_ms self.create_ms = current_ms
self.counter_stretch = 0 self.stretch_animation = Animation(current_ms, 0, 'text_stretch')
self.start_stretch = None
self.is_stretching = False
def update_count(self, current_ms, score): def update_count(self, current_ms, score):
if self.score != score: if self.score != score:
self.score = score self.score = score
self.start_stretch = current_ms self.stretch_animation = Animation(current_ms, 50, 'text_stretch')
self.is_stretching = True
def update_stretch(self, current_ms):
if not self.is_stretching:
return
elapsed_time = current_ms - self.start_stretch
if elapsed_time <= 50:
self.counter_stretch = 2 + (5 * (elapsed_time // 25))
elif elapsed_time <= 50 + 100:
frame_time = (elapsed_time - 50) // 16.57
self.counter_stretch = 2 + (10 - (2 * (frame_time + 1)))
else:
self.counter_stretch = 0
self.is_stretching = False
def update(self, current_ms, score): def update(self, current_ms, score):
self.update_count(current_ms, score) self.update_count(current_ms, score)
self.update_stretch(current_ms) self.stretch_animation.update(current_ms)
def draw(self, game_screen): def draw(self, game_screen):
counter = str(self.score) counter = str(self.score)
@@ -976,9 +922,78 @@ class ScoreCounter:
start_x = x - total_width start_x = x - total_width
source_rect = ray.Rectangle(0, 0, game_screen.texture_score_numbers[0].width, game_screen.texture_score_numbers[0].height) source_rect = ray.Rectangle(0, 0, game_screen.texture_score_numbers[0].width, game_screen.texture_score_numbers[0].height)
for i in range(len(counter)): for i in range(len(counter)):
dest_rect = ray.Rectangle(start_x + (i * margin), y - self.counter_stretch, game_screen.texture_score_numbers[0].width, game_screen.texture_score_numbers[0].height + self.counter_stretch) dest_rect = ray.Rectangle(start_x + (i * margin), y - self.stretch_animation.attribute, game_screen.texture_score_numbers[0].width, game_screen.texture_score_numbers[0].height + self.stretch_animation.attribute)
ray.draw_texture_pro(game_screen.texture_score_numbers[int(counter[i])], source_rect, dest_rect, ray.Vector2(0,0), 0, ray.WHITE) 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: class ScoreCounterAnimation:
def __init__(self, current_ms): def __init__(self, current_ms, counter):
pass self.counter = int(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
self.move_animation_1 = Animation(current_ms, 80, 'move')
self.move_animation_1.params['total_distance'] = -20
self.move_animation_1.params['start_position'] = 175
self.fade_animation_2 = Animation(current_ms, 80, 'fade')
self.fade_animation_2.params['delay'] = 366.74
self.move_animation_2 = Animation(current_ms, 66, 'move')
self.move_animation_2.params['total_distance'] = 5
self.move_animation_2.params['start_position'] = 145
self.move_animation_2.params['delay'] = 80
self.move_animation_3 = Animation(current_ms, 66, 'move')
self.move_animation_3.params['delay'] = 279.36
self.move_animation_3.params['total_distance'] = -2
self.move_animation_3.params['start_position'] = 146
self.move_animation_4 = Animation(current_ms, 80, 'move')
self.move_animation_4.params['delay'] = 366.74
self.move_animation_4.params['total_distance'] = 10
self.move_animation_4.params['start_position'] = 148
self.color = ray.fade(ray.Color(254, 102, 0, 255), 1.0)
self.is_finished = False
self.y_pos_list = []
def update(self, current_ms):
self.fade_animation_1.update(current_ms)
self.move_animation_1.update(current_ms)
self.move_animation_2.update(current_ms)
self.move_animation_3.update(current_ms)
self.move_animation_4.update(current_ms)
self.fade_animation_2.update(current_ms)
if self.fade_animation_1.is_finished:
self.color = ray.fade(ray.Color(254, 102, 0, 255), self.fade_animation_2.attribute)
else:
self.color = ray.fade(ray.Color(254, 102, 0, 255), self.fade_animation_1.attribute)
if self.fade_animation_2.is_finished:
self.is_finished = True
self.y_pos_list = []
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):
if self.move_animation_1.is_finished:
x = self.move_animation_2.attribute
else:
x = self.move_animation_1.attribute
if x == 0:
return
counter = str(self.counter)
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)
for i in range(len(counter)):
if self.move_animation_3.is_finished:
y = self.y_pos_list[i]
elif self.move_animation_2.is_finished:
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)

View File

@@ -254,11 +254,15 @@ class Animation:
self.move(current_ms, self.move(current_ms,
self.duration, self.duration,
self.params['total_distance'], self.params['total_distance'],
self.params['start_position']) self.params['start_position'],
delay=self.params.get('delay', 0.0))
elif self.type == 'texture_change': elif self.type == 'texture_change':
self.texture_change(current_ms, self.texture_change(current_ms,
self.duration, self.duration,
self.params['textures']) self.params['textures'])
elif self.type == 'text_stretch':
self.text_stretch(current_ms,
self.duration)
def fade(self, current_ms, duration, initial_opacity, final_opacity, delay, ease_in, ease_out): def fade(self, current_ms, duration, initial_opacity, final_opacity, delay, ease_in, ease_out):
def ease_out_progress(progress, ease): def ease_out_progress(progress, ease):
@@ -298,8 +302,12 @@ class Animation:
current_opacity = initial_opacity + (final_opacity - initial_opacity) * progress current_opacity = initial_opacity + (final_opacity - initial_opacity) * progress
self.attribute = current_opacity self.attribute = current_opacity
def move(self, current_ms, duration, total_distance, start_position): def move(self, current_ms, duration, total_distance, start_position, delay):
elapsed_time = current_ms - self.start_ms elapsed_time = current_ms - self.start_ms
if elapsed_time < delay:
self.attribute = start_position
elapsed_time -= delay
if elapsed_time <= duration: if elapsed_time <= duration:
progress = elapsed_time / duration progress = elapsed_time / duration
self.attribute = start_position + (total_distance * progress) self.attribute = start_position + (total_distance * progress)
@@ -315,3 +323,13 @@ class Animation:
self.attribute = index self.attribute = index
else: else:
self.is_finished = True self.is_finished = True
def text_stretch(self, current_ms, duration):
elapsed_time = current_ms - self.start_ms
if elapsed_time <= duration:
self.attribute = 2 + 5 * (elapsed_time // 25)
elif elapsed_time <= duration + 116:
frame_time = (elapsed_time - duration) // 16.57
self.attribute = 2 + 10 - (2 * (frame_time + 1))
else:
self.attribute = 0
self.is_finished = True