Class: CyberarmEngine::IntroState
- Defined in:
- lib/cyberarm_engine/builtin/intro_state.rb
Instance Attribute Summary
Attributes inherited from GameState
#game_objects, #global_pause, #options
Instance Method Summary collapse
- #button_down(_id) ⇒ Object
- #draw ⇒ Object
- #generate_proxy(title, caption, color_hint) ⇒ Object
- #setup ⇒ Object
- #update ⇒ Object
Methods inherited from GameState
#add_game_object, #button_up, #destroy, #draw_bounding_box, #initialize, #post_setup
Methods included from Common
#current_state, #darken, #draw_rect, #fill, #get_asset, #get_image, #get_sample, #get_song, #lighten, #opacity, #pop_state, #previous_state, #push_state, #shift_state, #show_cursor, #show_cursor=, #window
Constructor Details
This class inherits a constructor from CyberarmEngine::GameState
Instance Method Details
#button_down(_id) ⇒ Object
103 104 105 |
# File 'lib/cyberarm_engine/builtin/intro_state.rb', line 103 def (_id) @continue_after = 0 end |
#draw ⇒ Object
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 |
# File 'lib/cyberarm_engine/builtin/intro_state.rb', line 39 def draw Gosu.draw_rect(0, 0, window.width, window.height, 0xff_222222) scale = (@display_width - @padding * 2).to_f / @cyberarm_engine_logo.width * @animators.last.transition @cyberarm_engine_logo.draw_rot( window.width / 2, (window.height) / 2 - @cyberarm_engine_logo.height / 2 - @padding * 2, 2, 0, 0.5, 0.5, scale, scale ) Gosu.draw_rect( window.width / 2 - (@display_width / 2 + @padding), window.height / 2 - @spacer_height / 2, @display_width + @padding, @spacer_height * @animators[0].transition, Gosu::Color::WHITE ) @title.x = window.width / 2 - @title.width / 2 @title.y = (window.height / 2 + (@spacer_height / 2) + @padding) * @animators[1].transition @title.text = "Powered By" Gosu.clip_to(0, window.height / 2 + (@spacer_height / 2), window.width, @title.height) do @title.draw end y = @title.y + @title.height * 2 Gosu.clip_to(0, y, window.width, @gosu_logo.height) do Gosu.translate(@opengl_logo.nil? ? @ruby_logo.width / 2 : 0, 0) do @gosu_logo.draw( window.width.to_f / 2 - @ruby_logo.width / 2 - (@ruby_logo.width - @padding), y * @animators[2].transition, 2 ) @ruby_logo.draw( window.width.to_f / 2 - @ruby_logo.width / 2, y * @animators[3].transition, 2 ) @opengl_logo&.draw( window.width.to_f / 2 - @ruby_logo.width / 2 + (@ruby_logo.width - @padding), y * @animators[4].transition, 2 ) end end end |
#generate_proxy(title, caption, color_hint) ⇒ Object
107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 |
# File 'lib/cyberarm_engine/builtin/intro_state.rb', line 107 def generate_proxy(title, caption, color_hint) @title.text = title @caption.text = caption width = @spacer_width + 2 * @padding height = @title_size + @caption_size + @spacer_height + 2 * @padding + @spacer_height Gosu.record(width.ceil, height.ceil) do @title.x = (width - @padding * 2) / 2 - @title.width / 2 @title.y = @padding @title.draw Gosu.draw_rect(0, @padding + @title_size + @padding, @spacer_width, @spacer_height, Gosu::Color::WHITE) Gosu.draw_rect(1, @padding + @title_size + @padding + 1, @spacer_width - 2, @spacer_height - 2, color_hint) @caption.x = (width - @padding * 2) / 2 - @caption.width / 2 @caption.y = @padding + @title_size + @padding + @spacer_height + @padding @caption.draw end end |
#setup ⇒ Object
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/cyberarm_engine/builtin/intro_state.rb', line 3 def setup @display_width = 800 @display_height = 600 @title_size = 56 @caption_size = 24 @title = CyberarmEngine::Text.new("", size: @title_size, shadow_color: 0xaa_222222) @caption = CyberarmEngine::Text.new("", size: @caption_size, shadow_color: 0xaa_222222) @spacer_width = 256 @spacer_height = 6 @padding = 6 @cyberarm_engine_logo = get_image "#{CYBERARM_ENGINE_ROOT_PATH}/assets/textures/logo.png" @gosu_logo = generate_proxy("Gosu", "Game Library", 0xff_111111) @ruby_logo = generate_proxy("Ruby", "Programming Language", 0xff_880000) @opengl_logo = generate_proxy("OpenGL", "Graphics API", 0xff_5586a4) if defined?(OpenGL) base_time = Gosu.milliseconds @animators = [ Animator.new(start_time: base_time += 1000, duration: 100, from: 0.0, to: 1.0, tween: :ease_in_out), Animator.new(start_time: base_time += -500, duration: 1_000, from: 0.0, to: 1.0, tween: :ease_in_out), Animator.new(start_time: base_time += 500, duration: 1_000, from: 0.0, to: 1.0, tween: :ease_in_out), Animator.new(start_time: base_time += 500, duration: 1_000, from: 0.0, to: 1.0, tween: :ease_in_out), Animator.new(start_time: base_time + 500, duration: 1_000, from: 0.0, to: 1.0, tween: :ease_in_out), Animator.new(start_time: Gosu.milliseconds + 250, duration: 500, from: 0.0, to: 1.0, tween: :ease_in_out) # CyberarmEngine LOGO ] @born_time = Gosu.milliseconds @continue_after = 5_000 end |
#update ⇒ Object
94 95 96 97 98 99 100 101 |
# File 'lib/cyberarm_engine/builtin/intro_state.rb', line 94 def update @animators.each(&:update) return unless Gosu.milliseconds - @born_time >= @continue_after pop_state push_state(@options[:forward], @options[:forward_options] || {}) if @options[:forward] end |