Class: Chingu::GameStates::Popup

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

Overview

Premade game state for chingu - A simple way if pausing the game + displaying a text. Usage:

push_game_state(Chingu::GameStates::Popup.new(:text => "bla bla bla"))

TODO: Use Gosu's new flush() instead of mucking around with ZORDER + 1000…

Instance Attribute Summary

Attributes inherited from Chingu::GameState

#game_objects, #game_state_manager, #options, #previous_game_state

Attributes included from Helpers::InputDispatcher

#input_clients

Attributes included from Helpers::GameObject

#game_objects

Instance Method Summary collapse

Methods inherited from Chingu::GameState

#button_down, #close, #close_game, #draw_trait, #filename, #setup, #setup_trait, #to_s, #to_sym, trait, #trait_options, traits, #update, #update_trait

Methods included from Helpers::ClassInheritableAccessor

included

Methods included from Helpers::InputClient

#add_inputs, #holding?, #holding_all?, #holding_any?, #input, #input=, #on_input

Methods included from Helpers::InputDispatcher

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

Methods included from Helpers::GameObject

#game_objects_of_class, #load_game_objects, #save_game_objects

Methods included from Helpers::GFX

#draw_arc, #draw_circle, #draw_rect, #fill, #fill_arc, #fill_circle, #fill_gradient, #fill_rect

Constructor Details

#initialize(options = {}) ⇒ Popup

Returns a new instance of Popup



34
35
36
37
38
39
40
# File 'lib/chingu/game_states/popup.rb', line 34

def initialize(options = {})
  super
  @white = Color.new(255,255,255,255)
  @color = Gosu::Color.new(200,0,0,0)
  @string = options[:text] || "Press ESC to return."
  @text = Text.new(@string, :x => 20, :y => 10, :align => :left, :zorder => Chingu::DEBUG_ZORDER + 1001, :factor => 1)
end

Instance Method Details

#button_up(id) ⇒ Object



42
43
44
# File 'lib/chingu/game_states/popup.rb', line 42

def button_up(id)
  pop_game_state(:setup => false) if id == Gosu::KbEscape   # Return the previous game state, dont call setup()
end

#drawObject



46
47
48
49
50
51
52
53
# File 'lib/chingu/game_states/popup.rb', line 46

def draw
  previous_game_state.draw          # Draw prev game state
  $window.draw_quad(  0,0,@color,
                      $window.width,0,@color,
                      $window.width,$window.height,@color,
                      0,$window.height,@color, Chingu::DEBUG_ZORDER + 1000)                            
  @text.draw
end