Module: Lotu::SteeringSystem::UserMethods
- Defined in:
- lib/lotu/systems/steering_system.rb
Class Method Summary collapse
Instance Method Summary collapse
- #activate(behavior) ⇒ Object
- #distance_to_target ⇒ Object
- #draw_debug ⇒ Object
- #facing_target? ⇒ Boolean
- #setup_steering ⇒ Object
-
#to_s ⇒ Object
to_s utility methods.
Class Method Details
.extended(instance) ⇒ Object
179 180 181 |
# File 'lib/lotu/systems/steering_system.rb', line 179 def self.extended(instance) instance.setup_steering end |
Instance Method Details
#activate(behavior) ⇒ Object
211 212 213 |
# File 'lib/lotu/systems/steering_system.rb', line 211 def activate(behavior) @systems[SteeringSystem].activate(behavior) end |
#distance_to_target ⇒ Object
215 216 217 |
# File 'lib/lotu/systems/steering_system.rb', line 215 def distance_to_target (@target - @pos).length end |
#draw_debug ⇒ Object
223 224 225 226 227 228 |
# File 'lib/lotu/systems/steering_system.rb', line 223 def draw_debug super $lotu.draw_line(0, 0, @colors[:position], @pos.x, @pos.y, @colors[:position]) $lotu.draw_line(@pos.x, @pos.y, @colors[:heading], (@pos + @heading*50).x, (@pos+@heading*50).y, @colors[:heading]) $lotu.draw_line(@pos.x, @pos.y, @colors[:target], @target.x, @target.y, @colors[:target]) if @target end |
#facing_target? ⇒ Boolean
219 220 221 |
# File 'lib/lotu/systems/steering_system.rb', line 219 def facing_target? @heading.facing_to?(@target - @pos) end |
#setup_steering ⇒ Object
183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 |
# File 'lib/lotu/systems/steering_system.rb', line 183 def setup_steering # Create accessors for the user class << self attr_accessor :mass, :pos, :heading, :vel, :accel, :max_speed, :max_turn_rate, :max_force, :wander_radius, :wander_distance, :wander_target, :target, :evader, :pursuer, :pursuers end # TODO: move these inside the SteeringSystem? # and just delegate with accessors? # Some defaults @pos = Vector2d.new(@x, @y) offset_x = Gosu.offset_x(@angle, 1) offset_y = Gosu.offset_y(@angle, 1) @heading = Vector2d.new(offset_x, offset_y) @vel = Vector2d.new @accel = Vector2d.new @wander_target = Vector2d.new @pursuers = [] @colors = { :position => 0xff666666, :heading => 0xffff0000, :target => rand_color } end |
#to_s ⇒ Object
to_s utility methods
231 232 233 234 235 236 237 238 239 240 |
# File 'lib/lotu/systems/steering_system.rb', line 231 def to_s ["@angle(#{format('%.2f', @angle)}°)", "@pos(#{@pos})", "@heading(#{@heading})", "@vel |#{format('%.2f', @vel.length)}| (#{@vel})", "@accel |#{format('%.2f', @accel.length)}| (#{@accel})", "facing_target? #{facing_target? if @target}", "angle_to(@target) #{format('%.2f', @heading.angle_to(@target - @pos)) if @target}", "@seek_target(#{@target})"] end |