Module: Chingu::Helpers::GameObject
Overview
Convenience-methods for classes that hold game objects Mixed into Chingu::Window and Chingu::GameState
Instance Method Summary collapse
- #add_game_object(object) ⇒ Object
- #game_objects ⇒ Object
-
#game_objects_of_class(klass) ⇒ Object
Fetch game objects of a certain type/class.
-
#load_game_objects(options = {}) ⇒ Object
Creates game objects from a Chingu-spezed game objects file (created with game state ‘Edit’).
- #remove_game_object(object) ⇒ Object
Instance Method Details
#add_game_object(object) ⇒ Object
31 32 33 34 |
# File 'lib/chingu/helpers/game_object.rb', line 31 def add_game_object(object) # puts "#{self.to_s} add_game_object(#{object.to_s})" @game_objects.add_game_object(object) end |
#game_objects ⇒ Object
40 41 42 |
# File 'lib/chingu/helpers/game_object.rb', line 40 def game_objects @game_objects end |
#game_objects_of_class(klass) ⇒ Object
Fetch game objects of a certain type/class
47 48 49 |
# File 'lib/chingu/helpers/game_object.rb', line 47 def game_objects_of_class(klass) @game_objects.select { |game_object| game_object.is_a? klass } end |
#load_game_objects(options = {}) ⇒ Object
Creates game objects from a Chingu-spezed game objects file (created with game state ‘Edit’)
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/chingu/helpers/game_object.rb', line 54 def load_game_objects( = {}) filename = [:file] || "#{self.class.to_s.downcase}.yml" require 'yaml' if File.exists?(filename) game_objects = YAML.load_file(filename) game_objects.each do |game_object| game_object.each_pair do |klassname, attributes| begin klass = Kernel::const_get(klassname) unless klass.class == "GameObject" puts "Creating #{klassname.to_s}: #{attributes.to_s}" klass.create(attributes) end rescue puts "Couldn't create class '#{klassname}'" end end end end end |
#remove_game_object(object) ⇒ Object
36 37 38 |
# File 'lib/chingu/helpers/game_object.rb', line 36 def remove_game_object(object) @game_objects.remove_game_object(object) end |