Class: CyberarmEngine::GameState

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

Direct Known Subclasses

GuiState

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, #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



88
89
90
# File 'lib/cyberarm_engine/game_state.rb', line 88

def add_game_object(object)
  @game_objects << object
end

#button_down(id) ⇒ Object



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

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

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

#button_up(id) ⇒ Object



80
81
82
83
84
85
86
# File 'lib/cyberarm_engine/game_state.rb', line 80

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

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

#destroyObject



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

def destroy
  @options.clear
  @game_objects.clear
end

#drawObject



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

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

#draw_bounding_box(box) ⇒ Object



28
29
30
31
32
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
# File 'lib/cyberarm_engine/game_state.rb', line 28

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

#setupObject



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

def setup
end

#updateObject



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

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