Class: Gubby::GameEntity

Inherits:
Object show all
Defined in:
lib/gubby/game_entity.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#componentsObject (readonly)

Returns the value of attribute components.



8
9
10
# File 'lib/gubby/game_entity.rb', line 8

def components
  @components
end

#engineObject

Returns the value of attribute engine.



5
6
7
# File 'lib/gubby/game_entity.rb', line 5

def engine
  @engine
end

#entity_nameObject

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

#destroyObject



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