Sha256: 1ebe8f0ec8f583604b7ed92f5a61c3ed7b64a2275551bcba53a3157993b03217
Contents?: true
Size: 1.56 KB
Versions: 1
Compression:
Stored size: 1.56 KB
Contents
# Provides a mouse pointer usable through mouse or keyboard module Lotu class Cursor < Actor attr_reader :clicked_x, :clicked_y attr_accessor :speed, :use_mouse def initialize(opts={}) default_opts = { :use_mouse => true, :speed => 100, :x => $lotu.width/2, :y => $lotu.height/2 } opts = default_opts.merge!(opts) super $lotu.mouse_x = opts[:x] $lotu.mouse_y = opts[:y] @clicked_x = @clicked_y = 0 @speed = opts[:speed] @use_mouse = opts[:use_mouse] set_keys(opts[:keys]) unless opts[:keys].nil? end def update if @use_mouse @x = $lotu.mouse_x @y = $lotu.mouse_y end end # This is the method you want to call when a user press the # "click" key of your preference with something like: # set_keys Gosu::Button::MsLeft => :click # It'll yield the x, y coordinates of the clicked point def click @clicked_x = @x @clicked_y = @y fire(:click, @clicked_x, @clicked_y) end def adjust_mouse $lotu.mouse_y = @y $lotu.mouse_x = @x end def up @y -= @speed * dt adjust_mouse if use_mouse end def down @y += @speed * dt adjust_mouse if use_mouse end def left @x -= @speed * dt adjust_mouse if use_mouse end def right @x += @speed * dt adjust_mouse if use_mouse end def to_s ["@pos(#{format('%.2f, %.2f', @x, @y)})", "@clicked(#{format('%.2f, %.2f', @clicked_x, @clicked_y)})"] end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
lotu-0.1.11 | lib/lotu/cursor.rb |