Class: Chingu::GameStates::Debug

Inherits:
Chingu::GameState show all
Includes:
Helpers::OptionsSetter
Defined in:
lib/chingu/game_states/debug.rb

Overview

Debug game state (F1 is default key to start/exit debug win, 'p' to pause game)

Usage:

Constant Summary

Z =

TODO - centralize!

999
DEFAULTS =
{
  :x_offset => 10,
  :y_offset => 10,
  :text_color => Gosu::Color.new(255,255,255,255),
  :fade_color => Gosu::Color.new(100,100,100,70),
  :paused => false
}

Instance Attribute Summary collapse

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, #button_up, #close, #close_game, #draw_trait, #filename, #setup, #setup_trait, #to_s, #to_sym, trait, #trait_options, traits, #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 = {}) ⇒ Debug

Returns a new instance of Debug



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

def initialize(options = {})
  super
  set_options(options, DEFAULTS)

  # it fails when setup in DEFAULTS as it needs existing $window
  @font ||= Gosu::Font[16]
  
  self.input = {:p => :pause, :f1 => :return_to_game, :esc => :return_to_game}
end

Instance Attribute Details

#fade_colorObject

Returns the value of attribute fade_color



34
35
36
# File 'lib/chingu/game_states/debug.rb', line 34

def fade_color
  @fade_color
end

#textObject

Returns the value of attribute text



34
35
36
# File 'lib/chingu/game_states/debug.rb', line 34

def text
  @text
end

#text_colorObject

Returns the value of attribute text_color



34
35
36
# File 'lib/chingu/game_states/debug.rb', line 34

def text_color
  @text_color
end

#x_offsetObject

Returns the value of attribute x_offset



34
35
36
# File 'lib/chingu/game_states/debug.rb', line 34

def x_offset
  @x_offset
end

#y_offsetObject

Returns the value of attribute y_offset



34
35
36
# File 'lib/chingu/game_states/debug.rb', line 34

def y_offset
  @y_offset
end

Instance Method Details

#drawObject



69
70
71
72
73
74
75
76
77
78
79
# File 'lib/chingu/game_states/debug.rb', line 69

def draw
  previous_state.draw unless previous_state.nil?

  $window.draw_quad(  0,0,@fade_color,
                      $window.width,0,@fade_color,
                      $window.width,$window.height,@fade_color,
                      0,$window.height,@fade_color,10)                       
  
  @font.draw("DEBUG CONSOLE", @x_offset, @y_offset, Z)       
  print_lines(@text || generate_info)
end

#pauseObject



61
62
63
# File 'lib/chingu/game_states/debug.rb', line 61

def pause
  @paused = !@paused
end

#return_to_gameObject



57
58
59
# File 'lib/chingu/game_states/debug.rb', line 57

def return_to_game
  game_state_manager.pop_game_state
end

#updateObject



65
66
67
# File 'lib/chingu/game_states/debug.rb', line 65

def update
  game_state_manager.previous_game_state.update unless @paused
end