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

#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

#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



93
94
95
# File 'lib/cyberarm_engine/game_state.rb', line 93

def add_game_object(object)
  @game_objects << object
end

#button_down(id) ⇒ Object



77
78
79
80
81
82
83
# File 'lib/cyberarm_engine/game_state.rb', line 77

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

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

#button_up(id) ⇒ Object



85
86
87
88
89
90
91
# File 'lib/cyberarm_engine/game_state.rb', line 85

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

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

#destroyObject



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

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



33
34
35
36
37
38
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
# File 'lib/cyberarm_engine/game_state.rb', line 33

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
  $window.draw_line(
    x, y, color,
    x, max_y, color,
    Float::INFINITY
  )
  # BOTTOM LEFT to BOTTOM RIGHT
  $window.draw_line(
    x, max_y, color,
    max_x, max_y, color,
    Float::INFINITY
  )
  # BOTTOM RIGHT to TOP RIGHT
  $window.draw_line(
    max_x, max_y, color,
    max_x, y, color,
    Float::INFINITY
  )
  # TOP RIGHT to TOP LEFT
  $window.draw_line(
    max_x, y, color,
    x, y, color,
    Float::INFINITY
  )
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