Class: ShatteredModel::Base
- Inherits:
-
ShatteredPack::Base
- Object
- ShatteredPack::Base
- ShatteredModel::Base
- Defined in:
- lib/shattered_model/base.rb
Overview
Models encompass all of the game play logic and the game specific data.
Models are useful for unit tests and for making game rules. They are where all logic (AI/collisions/etc) go.
They can also specify keyboard input.
Instance Attribute Summary collapse
-
#view ⇒ Object
Returns the value of attribute view.
Attributes inherited from ShatteredPack::Base
Instance Method Summary collapse
-
#disabled? ⇒ Boolean
An object is disabled when it has been unloaded.
-
#fuzzy_logic=(file) ⇒ Object
:nodoc:.
- #inspect ⇒ Object
-
#method_missing(method, *args, &block) ⇒ Object
Delegates to View if view exists.
-
#unload! ⇒ Object
Unloading a controller will completely unload an object from the scene.
-
#update_fuzzy_logic ⇒ Object
:nodoc:.
-
#update_timer(time_elapsed) ⇒ Object
Propogates events to view as well.
Methods inherited from ShatteredPack::Base
#attr_accessor, #attr_reader, #attr_writer, new, #remove_dead_actors, #remove_from_scene, #remove_from_scene?, #state, #update_actors, #update_event, #when_unloaded
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *args, &block) ⇒ Object
Delegates to View if view exists
104 105 106 107 |
# File 'lib/shattered_model/base.rb', line 104 def method_missing(method, *args, &block) raise NoMethodError, "#{self.class} has no method defined '#{method}'" if self.view.nil? self.view.send(method, *args, &block) end |
Instance Attribute Details
#view ⇒ Object
Returns the value of attribute view.
18 19 20 |
# File 'lib/shattered_model/base.rb', line 18 def view @view end |
Instance Method Details
#disabled? ⇒ Boolean
An object is disabled when it has been unloaded.
91 92 93 |
# File 'lib/shattered_model/base.rb', line 91 def disabled? super end |
#fuzzy_logic=(file) ⇒ Object
:nodoc:
95 96 97 98 |
# File 'lib/shattered_model/base.rb', line 95 def fuzzy_logic=(file) #:nodoc: @fuzzy_logic = FuzzyLogic.new @fuzzy_logic.parse_fuzzy_file(File.dirname(__FILE__)+"/#{file}") end |
#inspect ⇒ Object
109 110 111 |
# File 'lib/shattered_model/base.rb', line 109 def inspect "#{self.class}:#{self.object_id}" end |
#unload! ⇒ Object
Unloading a controller will completely unload an object from the scene.
82 83 84 85 86 87 88 |
# File 'lib/shattered_model/base.rb', line 82 def unload! super @disabled = true @timer=:unloaded @view.send(:unload!) if @view self.view = nil end |
#update_fuzzy_logic ⇒ Object
:nodoc:
99 100 101 |
# File 'lib/shattered_model/base.rb', line 99 def update_fuzzy_logic #:nodoc: @fuzzy_logic.update(self) end |
#update_timer(time_elapsed) ⇒ Object
Propogates events to view as well.
72 73 74 75 76 77 78 79 |
# File 'lib/shattered_model/base.rb', line 72 def update_timer(time_elapsed)#:nodoc: return if @timer == :unloaded [self, view].each do |base| next if base.nil? base.time_elapsed = time_elapsed base.timer.update(time_elapsed) end end |