Class: Chingu::GameObjectList
- Inherits:
-
Object
- Object
- Chingu::GameObjectList
- Extended by:
- Forwardable
- Defined in:
- lib/chingu/game_object_list.rb
Overview
Manages a list of game objects An instance of GameObjectList is automaticly created as “game_objects” if using Chingu::Window
Instance Attribute Summary collapse
-
#unpaused_game_objects ⇒ Object
readonly
Returns the value of attribute unpaused_game_objects.
-
#visible_game_objects ⇒ Object
readonly
Returns the value of attribute visible_game_objects.
Instance Method Summary collapse
- #add_game_object(object) ⇒ Object
- #destroy_all ⇒ Object (also: #clear, #remove_all)
- #destroy_if ⇒ Object
- #draw ⇒ Object
- #draw_relative(x = 0, y = 0, zorder = 0, angle = 0, center_x = 0, center_y = 0, factor_x = 0, factor_y = 0) ⇒ Object
- #each ⇒ Object
- #each_with_index ⇒ Object
- #force_draw ⇒ Object
- #force_update ⇒ Object
-
#hide! ⇒ Object
(also: #hide)
Disable automatic calling of draw and draw_trait each game loop for all game objects.
- #hide_game_object(object) ⇒ Object
-
#initialize(options = {}) ⇒ GameObjectList
constructor
A new instance of GameObjectList.
- #map ⇒ Object
- #of_class(klass) ⇒ Object
-
#pause! ⇒ Object
(also: #pause)
Disable automatic calling of update() and update_trait() each game loop for all game objects.
- #pause_game_object(object) ⇒ Object
- #remove_game_object(object) ⇒ Object
- #select ⇒ Object
-
#show! ⇒ Object
(also: #show)
Enable automatic calling of draw and draw_trait each game loop for all game objects.
- #show_game_object(object) ⇒ Object
- #to_s ⇒ Object
-
#unpause! ⇒ Object
(also: #unpause)
Enable automatic calling of update() and update_trait() each game loop for all game objects.
- #unpause_game_object(object) ⇒ Object
- #update ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ GameObjectList
Returns a new instance of GameObjectList.
34 35 36 37 38 |
# File 'lib/chingu/game_object_list.rb', line 34 def initialize( = {}) @game_objects = [:game_objects] || [] @visible_game_objects = [] @unpaused_game_objects = [] end |
Instance Attribute Details
#unpaused_game_objects ⇒ Object (readonly)
Returns the value of attribute unpaused_game_objects
32 33 34 |
# File 'lib/chingu/game_object_list.rb', line 32 def unpaused_game_objects @unpaused_game_objects end |
#visible_game_objects ⇒ Object (readonly)
Returns the value of attribute visible_game_objects
32 33 34 |
# File 'lib/chingu/game_object_list.rb', line 32 def visible_game_objects @visible_game_objects end |
Instance Method Details
#add_game_object(object) ⇒ Object
72 73 74 75 76 |
# File 'lib/chingu/game_object_list.rb', line 72 def add_game_object(object) @game_objects.push(object) @visible_game_objects.push(object) if object.respond_to?(:visible) && object.visible @unpaused_game_objects.push(object) if object.respond_to?(:paused) && !object.paused end |
#destroy_all ⇒ Object Also known as: clear, remove_all
53 54 55 |
# File 'lib/chingu/game_object_list.rb', line 53 def destroy_all @game_objects.each { |game_object| game_object.destroy } end |
#destroy_if ⇒ Object
84 85 86 |
# File 'lib/chingu/game_object_list.rb', line 84 def destroy_if @game_objects.select { |object| object.destroy if yield(object) } end |
#draw ⇒ Object
95 96 97 |
# File 'lib/chingu/game_object_list.rb', line 95 def draw @visible_game_objects.each { |go| go.draw_trait; go.draw; } end |
#draw_relative(x = 0, y = 0, zorder = 0, angle = 0, center_x = 0, center_y = 0, factor_x = 0, factor_y = 0) ⇒ Object
102 103 104 105 106 107 |
# File 'lib/chingu/game_object_list.rb', line 102 def draw_relative(x=0, y=0, zorder=0, angle=0, center_x=0, center_y=0, factor_x=0, factor_y=0) @visible_game_objects.each do |object| object.draw_trait object.draw_relative(x, y, zorder, angle, center_x, center_y, factor_x, factor_y) end end |
#each ⇒ Object
110 111 112 |
# File 'lib/chingu/game_object_list.rb', line 110 def each @game_objects.dup.each { |object| yield object } end |
#each_with_index ⇒ Object
114 115 116 |
# File 'lib/chingu/game_object_list.rb', line 114 def each_with_index @game_objects.dup.each_with_index { |object, index| yield object, index } end |
#force_draw ⇒ Object
98 99 100 |
# File 'lib/chingu/game_object_list.rb', line 98 def force_draw @game_objects.each { |go| go.draw_trait; go.draw } end |
#force_update ⇒ Object
91 92 93 |
# File 'lib/chingu/game_object_list.rb', line 91 def force_update @game_objects.each { |go| go.update_trait; go.update; } end |
#hide! ⇒ Object Also known as: hide
Disable automatic calling of draw and draw_trait each game loop for all game objects
145 146 147 |
# File 'lib/chingu/game_object_list.rb', line 145 def hide! @game_objects.each { |object| object.hide! } end |
#hide_game_object(object) ⇒ Object
62 63 64 |
# File 'lib/chingu/game_object_list.rb', line 62 def hide_game_object(object) @visible_game_objects.delete(object) end |
#map ⇒ Object
122 123 124 |
# File 'lib/chingu/game_object_list.rb', line 122 def map @game_objects.map { |object| yield object } end |
#of_class(klass) ⇒ Object
49 50 51 |
# File 'lib/chingu/game_object_list.rb', line 49 def of_class(klass) @game_objects.select { |game_object| game_object.is_a? klass } end |
#pause! ⇒ Object Also known as: pause
Disable automatic calling of update() and update_trait() each game loop for all game objects
129 130 131 |
# File 'lib/chingu/game_object_list.rb', line 129 def pause! @game_objects.each { |object| object.pause! } end |
#pause_game_object(object) ⇒ Object
65 66 67 |
# File 'lib/chingu/game_object_list.rb', line 65 def pause_game_object(object) @unpaused_game_objects.delete(object) end |
#remove_game_object(object) ⇒ Object
78 79 80 81 82 |
# File 'lib/chingu/game_object_list.rb', line 78 def remove_game_object(object) @game_objects.delete(object) @visible_game_objects.delete(object) @unpaused_game_objects.delete(object) end |
#select ⇒ Object
118 119 120 |
# File 'lib/chingu/game_object_list.rb', line 118 def select @game_objects.dup.select { |object| yield object } end |
#show! ⇒ Object Also known as: show
Enable automatic calling of draw and draw_trait each game loop for all game objects
153 154 155 |
# File 'lib/chingu/game_object_list.rb', line 153 def show! @game_objects.each { |object| object.show! } end |
#show_game_object(object) ⇒ Object
59 60 61 |
# File 'lib/chingu/game_object_list.rb', line 59 def show_game_object(object) @visible_game_objects.push(object) end |
#to_s ⇒ Object
45 46 47 |
# File 'lib/chingu/game_object_list.rb', line 45 def to_s "#{@game_objects.size} game objects." end |
#unpause! ⇒ Object Also known as: unpause
Enable automatic calling of update() and update_trait() each game loop for all game objects
137 138 139 |
# File 'lib/chingu/game_object_list.rb', line 137 def unpause! @game_objects.each { |object| object.unpause! } end |
#unpause_game_object(object) ⇒ Object
68 69 70 |
# File 'lib/chingu/game_object_list.rb', line 68 def unpause_game_object(object) @unpaused_game_objects.push(object) end |
#update ⇒ Object
88 89 90 |
# File 'lib/chingu/game_object_list.rb', line 88 def update @unpaused_game_objects.each { |go| go.update_trait; go.update; } end |