Class: Gubby::Systems::GameSystem

Inherits:
Object
  • Object
show all
Defined in:
lib/gubby/systems/game_system.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*args) ⇒ GameSystem

Returns a new instance of GameSystem.



10
11
12
13
14
15
# File 'lib/gubby/systems/game_system.rb', line 10

def initialize(*args)
	
	@entities = []
	@component_types = args
	
end

Instance Attribute Details

#entitiesObject (readonly)

Returns the value of attribute entities.



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

def entities
  @entities
end

Instance Method Details

#refresh_entity(e) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/gubby/systems/game_system.rb', line 17

def refresh_entity(e)
	
	#We need to make sure the entity is all the types it needs to be
	is_compatible = true
	
	@component_types.each do |c|
		is_compatible = is_compatible && e.is_a?(c)
	end
	
	if is_compatible && !@entities.include?(e) 
		@entities.push(e)
	end
	
	if not is_compatible && @entities.include?(e)
		@entities.delete(e)
	end
	
end