class AdventureRL::Events::Mouse
Public Class Methods
new(*args)
click to toggle source
Calls superclass method
AdventureRL::Events::Event::new
# File lib/AdventureRL/Events/Mouse.rb, line 4 def initialize *args super @quadtree = Quadtree.new end
Public Instance Methods
add_object(object)
click to toggle source
Overwrite the add_object
method, so we can reset the object in the Quadtree
if necessary, via the object's move_by method.
Calls superclass method
AdventureRL::Events::Event#add_object
# File lib/AdventureRL/Events/Mouse.rb, line 12 def add_object object super [object].flatten.each do |obj| get_quadtree.add_object obj mouse_event = self obj.define_singleton_method :move_by do |*args| previous_position = get_position.dup super(*args) mouse_event.get_quadtree.reset_object self if (get_position != previous_position) end end end
get_quadtree()
click to toggle source
# File lib/AdventureRL/Events/Mouse.rb, line 43 def get_quadtree return @quadtree end
remove_object(object)
click to toggle source
Overwrite the remove_object
method, so we can also remove the object(s) from the Quadtree
.
Calls superclass method
AdventureRL::Events::Event#remove_object
# File lib/AdventureRL/Events/Mouse.rb, line 27 def remove_object object super [object].flatten.each do |obj| get_quadtree.remove_object obj end end
trigger(*args)
click to toggle source
Private Instance Methods
get_colliding_objects()
click to toggle source
# File lib/AdventureRL/Events/Mouse.rb, line 49 def get_colliding_objects return get_quadtree.get_colliding_objects_for get_mouse_point end
get_mouse_point()
click to toggle source
# File lib/AdventureRL/Events/Mouse.rb, line 53 def get_mouse_point window = Window.get_window return nil unless (window) return Point.new(window.mouse_x, window.mouse_y) end