class Gubby::GameEngine
Attributes
entities[R]
systems[RW]
Public Class Methods
new(*systems)
click to toggle source
# File lib/gubby/game_engine.rb, line 8 def initialize(*systems) @systems = [] @entities = [] systems.each do |s| @systems.push(s) end end
Public Instance Methods
[](*selectors)
click to toggle source
# File lib/gubby/game_engine.rb, line 52 def [](*selectors) found = [] selectors.each do |s| found.concat(@entities.select{|e| e.name == s}) if s.is_a?(String) found.concat(@entities.select{|e| e.is_a?(s)}) if s.is_a?(Module) end return found end
add_entity(e)
click to toggle source
# File lib/gubby/game_engine.rb, line 28 def add_entity(e) @entities.push(e) unless @entities.include?(e) e.engine = self @systems.each do |s| s.refresh_entity(e) end end
refresh_entity(e)
click to toggle source
# File lib/gubby/game_engine.rb, line 36 def refresh_entity(e) @systems.each do |s| s.refresh_entity(e) end end
remove_entity(e)
click to toggle source
# File lib/gubby/game_engine.rb, line 42 def remove_entity(e) @entities.delete(e) @systems.each do |s| if s.entities.include?(e) then s.entities.delete(e) end end e.engine = nil end
run(command, *args)
click to toggle source
# File lib/gubby/game_engine.rb, line 20 def run(command, *args) @systems.select{ |s| s.respond_to?(command) }.each do |s| s.send(command.to_s, *args) end end