Class: CyberarmEngine::GameState

Inherits:
Object
  • Object
show all
Includes:
Common
Defined in:
lib/cyberarm_engine/game_state.rb

Direct Known Subclasses

GuiState, IntroState

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Common

#alt_down?, #control_down?, #current_state, #darken, #draw_rect, #fill, #find_element_by_tag, #get_asset, #get_image, #get_sample, #get_song, #lighten, #opacity, #pop_state, #previous_state, #push_state, #shift_down?, #shift_state, #show_cursor, #show_cursor=, #window

Constructor Details

#initialize(options = {}) ⇒ GameState

Returns a new instance of GameState.



8
9
10
11
12
13
14
15
# File 'lib/cyberarm_engine/game_state.rb', line 8

def initialize(options = {})
  @options = options
  @game_objects = []
  @global_pause = false
  window.text_input = nil unless options[:preserve_text_input]

  @down_keys = {}
end

Instance Attribute Details

#game_objectsObject (readonly)

Returns the value of attribute game_objects.



6
7
8
# File 'lib/cyberarm_engine/game_state.rb', line 6

def game_objects
  @game_objects
end

#global_pauseObject

Returns the value of attribute global_pause.



5
6
7
# File 'lib/cyberarm_engine/game_state.rb', line 5

def global_pause
  @global_pause
end

#optionsObject

Returns the value of attribute options.



5
6
7
# File 'lib/cyberarm_engine/game_state.rb', line 5

def options
  @options
end

Instance Method Details

#add_game_object(object) ⇒ Object



120
121
122
# File 'lib/cyberarm_engine/game_state.rb', line 120

def add_game_object(object)
  @game_objects << object
end

#button_down(id) ⇒ Object



56
57
58
59
60
61
62
# File 'lib/cyberarm_engine/game_state.rb', line 56

def button_down(id)
  @down_keys[id] = true

  @game_objects.each do |o|
    o.button_down(id)
  end
end

#button_up(id) ⇒ Object



64
65
66
67
68
69
70
# File 'lib/cyberarm_engine/game_state.rb', line 64

def button_up(id)
  @down_keys.delete(id)

  @game_objects.each do |o|
    o.button_up(id)
  end
end

#closeObject



72
73
74
# File 'lib/cyberarm_engine/game_state.rb', line 72

def close
  window.close!
end

#destroyObject



115
116
117
118
# File 'lib/cyberarm_engine/game_state.rb', line 115

def destroy
  @options.clear
  @game_objects.clear
end

#drawObject



25
26
27
# File 'lib/cyberarm_engine/game_state.rb', line 25

def draw
  @game_objects.each(&:draw)
end

#draw_bounding_box(box) ⇒ Object



76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
# File 'lib/cyberarm_engine/game_state.rb', line 76

def draw_bounding_box(box)
  x = box.x
  y = box.y
  max_x = box.max_x
  max_y = box.max_y

  color = Gosu::Color.rgba(255, 127, 64, 240)

  # pipe = 4
  # Gosu.draw_rect(x-width, y-height, x+(width*2), y+(height*2), color, Float::INFINITY)
  # puts "BB render: #{x}:#{y} w:#{x.abs+width} h:#{y.abs+height}"
  # Gosu.draw_rect(x, y, x.abs+width, y.abs+height, color, Float::INFINITY)

  # TOP LEFT to BOTTOM LEFT
  Gosu.draw_line(
    x, y, color,
    x, max_y, color,
    Float::INFINITY
  )
  # BOTTOM LEFT to BOTTOM RIGHT
  Gosu.draw_line(
    x, max_y, color,
    max_x, max_y, color,
    Float::INFINITY
  )
  # BOTTOM RIGHT to TOP RIGHT
  Gosu.draw_line(
    max_x, max_y, color,
    max_x, y, color,
    Float::INFINITY
  )
  # TOP RIGHT to TOP LEFT
  Gosu.draw_line(
    max_x, y, color,
    x, y, color,
    Float::INFINITY
  )
end

#drop(filename) ⇒ Object



41
42
# File 'lib/cyberarm_engine/game_state.rb', line 41

def drop(filename)
end

#gain_focusObject



50
51
# File 'lib/cyberarm_engine/game_state.rb', line 50

def gain_focus
end

#gamepad_connected(index) ⇒ Object



44
45
# File 'lib/cyberarm_engine/game_state.rb', line 44

def gamepad_connected(index)
end

#gamepad_disconnected(index) ⇒ Object



47
48
# File 'lib/cyberarm_engine/game_state.rb', line 47

def gamepad_disconnected(index)
end

#lose_focusObject



53
54
# File 'lib/cyberarm_engine/game_state.rb', line 53

def lose_focus
end

#needs_redraw?Boolean

Returns:

  • (Boolean)


33
34
35
# File 'lib/cyberarm_engine/game_state.rb', line 33

def needs_redraw?
  true
end

#needs_repaint?Boolean

Returns:

  • (Boolean)


37
38
39
# File 'lib/cyberarm_engine/game_state.rb', line 37

def needs_repaint?
  true
end

#post_setupObject

Called immediately after setup returns. GuiState uses this to set current_theme for ToolTip



22
23
# File 'lib/cyberarm_engine/game_state.rb', line 22

def post_setup
end

#setupObject



17
18
# File 'lib/cyberarm_engine/game_state.rb', line 17

def setup
end

#updateObject



29
30
31
# File 'lib/cyberarm_engine/game_state.rb', line 29

def update
  @game_objects.each(&:update)
end