From c5e0f33f21a1aef514304286e7df99a6ad10b109 Mon Sep 17 00:00:00 2001 From: Cyberarm Date: Sun, 25 Apr 2021 15:38:39 +0000 Subject: [PATCH] Addded some life to the Close state with some animations --- lib/states/game_states/close.rb | 60 ++++++++++++++++++++++----------- 1 file changed, 41 insertions(+), 19 deletions(-) diff --git a/lib/states/game_states/close.rb b/lib/states/game_states/close.rb index 4d68d34..80612ce 100644 --- a/lib/states/game_states/close.rb +++ b/lib/states/game_states/close.rb @@ -3,41 +3,63 @@ class IMICFPS class Close < GameState def setup - @slope = Menu::BAR_SLOPE - @logo = get_image("#{IMICFPS::GAME_ROOT_PATH}/static/logo.png") @start_time = Gosu.milliseconds - @time_to_live = 3_000 + @time_to_live = 3_750 + + timing = Gosu.milliseconds + @animators = [ + @arc_animator = CyberarmEngine::Animator.new( + start_time: timing += 0, + duration: 2_500, + from: 1.0, + to: 0.0, + tween: :ease_in_out + ), + @logo_animator = CyberarmEngine::Animator.new( + start_time: timing += 2_500, + duration: 500, + from: 1.0, + to: 0.0, + tween: :swing_from + ), + @fade_animator = CyberarmEngine::Animator.new( + start_time: timing += 500, + duration: 500, + from: 0.0, + to: 1.0, + tween: :ease_in_out + ), + ] window.needs_cursor = false end def draw - fraction_left = 1 - ((Gosu.milliseconds - @start_time) / (@time_to_live - 200).to_f) + menu_background(Menu::PRIMARY_COLOR, Menu::ACCENT_COLOR, Menu::BAR_COLOR_STEP, Menu::BAR_ALPHA, Menu::BAR_SIZE, Menu::BAR_SLOPE) - menu_background(Menu::PRIMARY_COLOR, Menu::ACCENT_COLOR, Menu::BAR_COLOR_STEP, Menu::BAR_ALPHA, Menu::BAR_SIZE, @slope.round) + Gosu.scale(@logo_animator.transition, @logo_animator.transition, window.width / 2, window.height / 2) do + Gosu.draw_circle( + window.width / 2, + window.height / 2, + @logo.width / 2, 128, Gosu::Color.new(0x11ffffff) + ) - Gosu.draw_circle( - window.width / 2, - window.height / 2, - @logo.width / 2, 128, Gosu::Color.new(0x11ffffff) - ) + Gosu.draw_arc( + window.width / 2, + window.height / 2, + @logo.width / 2, @arc_animator.transition, 128, 8, Gosu::Color.new(0x33ff8800) + ) - Gosu.draw_arc( - window.width / 2, - window.height / 2, - @logo.width / 2, fraction_left.clamp(0.0, 1.0), 128, 8, Gosu::Color.new(0x33ff8800) - ) + @logo.draw(window.width / 2 - @logo.width / 2, window.height / 2 - @logo.height / 2, 0) + end - @logo.draw(window.width / 2 - @logo.width / 2, window.height / 2 - @logo.height / 2, 0) - - fill(Gosu::Color.rgba(0, 0, 0, 255 * (1.1 - fraction_left))) + fill(Gosu::Color.rgba(0, 0, 0, 255 * @fade_animator.transition)) end def update window.close! if Gosu.milliseconds - @start_time >= @time_to_live - @slope -= 25 * window.dt end def button_up(id)