Class: Gubby::GameEntity
Instance Attribute Summary collapse
-
#components ⇒ Object
readonly
Returns the value of attribute components.
-
#engine ⇒ Object
Returns the value of attribute engine.
-
#entity_name ⇒ Object
Returns the value of attribute entity_name.
Instance Method Summary collapse
- #add_component(*components) ⇒ Object
- #destroy ⇒ Object
-
#initialize(name = nil, *components) ⇒ GameEntity
constructor
A new instance of GameEntity.
- #remove_component(*components) ⇒ Object
Constructor Details
#initialize(name = nil, *components) ⇒ GameEntity
Returns a new instance of GameEntity.
10 11 12 13 14 15 16 |
# File 'lib/gubby/game_entity.rb', line 10 def initialize(name = nil, *components) @components = [] @entity_name = name unless name.nil? add_component(*components) end |
Instance Attribute Details
#components ⇒ Object (readonly)
Returns the value of attribute components.
8 9 10 |
# File 'lib/gubby/game_entity.rb', line 8 def components @components end |
#engine ⇒ Object
Returns the value of attribute engine.
5 6 7 |
# File 'lib/gubby/game_entity.rb', line 5 def engine @engine end |
#entity_name ⇒ Object
Returns the value of attribute entity_name.
5 6 7 |
# File 'lib/gubby/game_entity.rb', line 5 def entity_name @entity_name end |
Instance Method Details
#add_component(*components) ⇒ Object
18 19 20 21 22 23 24 25 26 27 |
# File 'lib/gubby/game_entity.rb', line 18 def add_component(*components) components.each do |c| extend(c) @components.push(c) end @engine.refresh_entity(self) unless @engine.nil? end |
#destroy ⇒ Object
40 41 42 |
# File 'lib/gubby/game_entity.rb', line 40 def destroy() @engine.remove_entity(self) end |
#remove_component(*components) ⇒ Object
29 30 31 32 33 34 35 36 37 38 |
# File 'lib/gubby/game_entity.rb', line 29 def remove_component(*components) components.each do |c| unextend(c) @components.delete(c) end @engine.refresh_entity(self) unless @engine.nil? end |