Class: Chingu::GameObjectList
- Inherits:
-
Object
- Object
- Chingu::GameObjectList
- 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
- #empty? ⇒ Boolean
- #first ⇒ 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.
- #last ⇒ Object
- #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
- #size ⇒ 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.
31 32 33 34 35 36 37 38 39 |
# File 'lib/chingu/game_object_list.rb', line 31 def initialize( = {}) @game_objects = [:game_objects] || [] @visible_game_objects = [] @unpaused_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.
29 30 31 |
# File 'lib/chingu/game_object_list.rb', line 29 def unpaused_game_objects @unpaused_game_objects end |
#visible_game_objects ⇒ Object (readonly)
Returns the value of attribute visible_game_objects.
29 30 31 |
# File 'lib/chingu/game_object_list.rb', line 29 def visible_game_objects @visible_game_objects end |
Instance Method Details
#add_game_object(object) ⇒ Object
68 69 70 71 72 73 74 75 76 |
# File 'lib/chingu/game_object_list.rb', line 68 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 #@game_objects[object] = true #@visible_game_objects[object] = true if object.respond_to?(:visible) && object.visible #@unpaused_game_objects[object] = true if object.respond_to?(:paused) && !object.paused end |
#destroy_all ⇒ Object Also known as: clear, remove_all
49 50 51 |
# File 'lib/chingu/game_object_list.rb', line 49 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
103 104 105 |
# File 'lib/chingu/game_object_list.rb', line 103 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
110 111 112 113 114 115 |
# File 'lib/chingu/game_object_list.rb', line 110 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
118 119 120 |
# File 'lib/chingu/game_object_list.rb', line 118 def each @game_objects.dup.each { |object| yield object } end |
#each_with_index ⇒ Object
122 123 124 |
# File 'lib/chingu/game_object_list.rb', line 122 def each_with_index @game_objects.dup.each_with_index { |object, index| yield object, index } end |
#empty? ⇒ Boolean
92 93 94 |
# File 'lib/chingu/game_object_list.rb', line 92 def empty? @game_objects.empty? end |
#first ⇒ Object
134 135 136 |
# File 'lib/chingu/game_object_list.rb', line 134 def first @game_objects.first end |
#force_draw ⇒ Object
106 107 108 |
# File 'lib/chingu/game_object_list.rb', line 106 def force_draw @game_objects.each { |go| go.draw_trait; go.draw } end |
#force_update ⇒ Object
99 100 101 |
# File 'lib/chingu/game_object_list.rb', line 99 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
161 162 163 |
# File 'lib/chingu/game_object_list.rb', line 161 def hide! @game_objects.each { |object| object.hide! } end |
#hide_game_object(object) ⇒ Object
58 59 60 |
# File 'lib/chingu/game_object_list.rb', line 58 def hide_game_object(object) @visible_game_objects.delete(object) end |
#last ⇒ Object
138 139 140 |
# File 'lib/chingu/game_object_list.rb', line 138 def last @game_objects.last end |
#map ⇒ Object
130 131 132 |
# File 'lib/chingu/game_object_list.rb', line 130 def map @game_objects.map { |object| yield object } end |
#of_class(klass) ⇒ Object
45 46 47 |
# File 'lib/chingu/game_object_list.rb', line 45 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
145 146 147 |
# File 'lib/chingu/game_object_list.rb', line 145 def pause! @game_objects.each { |object| object.pause! } end |
#pause_game_object(object) ⇒ Object
61 62 63 |
# File 'lib/chingu/game_object_list.rb', line 61 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
126 127 128 |
# File 'lib/chingu/game_object_list.rb', line 126 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
169 170 171 |
# File 'lib/chingu/game_object_list.rb', line 169 def show! @game_objects.each { |object| object.show! } end |
#show_game_object(object) ⇒ Object
55 56 57 |
# File 'lib/chingu/game_object_list.rb', line 55 def show_game_object(object) @visible_game_objects.push(object) end |
#size ⇒ Object
88 89 90 |
# File 'lib/chingu/game_object_list.rb', line 88 def size @game_objects.size end |
#to_s ⇒ Object
41 42 43 |
# File 'lib/chingu/game_object_list.rb', line 41 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
153 154 155 |
# File 'lib/chingu/game_object_list.rb', line 153 def unpause! @game_objects.each { |object| object.unpause! } end |
#unpause_game_object(object) ⇒ Object
64 65 66 |
# File 'lib/chingu/game_object_list.rb', line 64 def unpause_game_object(object) @unpaused_game_objects.push(object) end |
#update ⇒ Object
96 97 98 |
# File 'lib/chingu/game_object_list.rb', line 96 def update @unpaused_game_objects.each { |go| go.update_trait; go.update; } end |