Class: Chingu::GameStates::FadeTo

Inherits:
Chingu::GameState show all
Defined in:
lib/chingu/game_states/fade_to.rb

Instance Attribute Summary

Attributes inherited from Chingu::GameState

#game_objects, #game_state_manager, #options

Attributes included from InputDispatcher

#input_clients

Instance Method Summary collapse

Methods inherited from Chingu::GameState

#button_down, #button_up, #close, #close_game, #to_s, #to_sym

Methods included from InputClient

#input, #input=

Methods included from InputDispatcher

#add_input_client, #dispatch_action, #dispatch_button_down, #dispatch_button_up, #dispatch_input_for, #remove_input_client

Methods included from Chingu::GameObjectHelpers

#add_game_object, #game_objects, #game_objects_of_class, #remove_game_object

Methods included from Chingu::GFXHelpers

#fill, #fill_gradient, #fill_rect

Methods included from Chingu::GameStateHelpers

#clear_game_states, #current_game_state, #pop_game_state, #previous_game_state, #push_game_state, #switch_game_state, #transitional_game_state

Constructor Details

#initialize(new_game_state, options = {}) ⇒ FadeTo

Returns a new instance of FadeTo.



36
37
38
39
# File 'lib/chingu/game_states/fade_to.rb', line 36

def initialize(new_game_state, options = {})
  @options = {:speed => 3}.merge(options)
  @new_game_state = new_game_state        
end

Instance Method Details

#drawObject



58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
# File 'lib/chingu/game_states/fade_to.rb', line 58

def draw
  # Stop endless loops
  if @drawn == false
    @drawn = true
    @game_state_manager.previous_game_state.draw  if @fading_in == false
    @new_game_state.draw                          if @fading_in == true

    $window.draw_quad( 0,0,@color,
                        $window.width,0,@color,
                        $window.width,$window.height,@color,
                        0,$window.height,@color,999)
                    
    if @fading_in == true && @alpha == 0
      @game_state_manager.switch_game_state(@new_game_state, :transitional => false)
    end
  end
end

#setupObject



41
42
43
44
45
46
# File 'lib/chingu/game_states/fade_to.rb', line 41

def setup
  @color = Gosu::Color.new(0,0,0,0)
  @alpha = 0.0
  @fading_in = false
  @new_game_state.update      # Make sure states game logic is run Once (for a correct draw())
end

#updateObject



48
49
50
51
52
53
54
55
56
# File 'lib/chingu/game_states/fade_to.rb', line 48

def update
  @alpha += (@fading_in ? -@options[:speed] : @options[:speed])
  if @alpha >= 255
    @fading_in = true
  else
    @color.alpha = @alpha.to_i
  end
  @drawn = false
end