Class: Lotu::Cursor
Instance Attribute Summary collapse
-
#clicked_x ⇒ Object
readonly
Returns the value of attribute clicked_x.
-
#clicked_y ⇒ Object
readonly
Returns the value of attribute clicked_y.
-
#speed ⇒ Object
Returns the value of attribute speed.
-
#use_mouse ⇒ Object
Returns the value of attribute use_mouse.
Attributes inherited from Actor
#angle, #center_x, #center_y, #color, #factor_x, #factor_y, #height, #image, #mode, #parent, #systems, #width, #x, #y, #z
Instance Method Summary collapse
- #adjust_mouse ⇒ Object
-
#click ⇒ Object
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.
- #down ⇒ Object
-
#initialize(opts = {}) ⇒ Cursor
constructor
A new instance of Cursor.
- #left ⇒ Object
- #right ⇒ Object
- #to_s ⇒ Object
- #up ⇒ Object
- #update ⇒ Object
Methods inherited from Actor
#adjust_width_and_height, #calc_zoom, #die, #draw, #draw_box, #draw_debug, #dt, #parse_options, #rand_color, #set_gosu_image, #set_image
Methods included from Controllable
Methods included from SystemUser
Constructor Details
#initialize(opts = {}) ⇒ Cursor
Returns a new instance of Cursor.
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/lotu/cursor.rb', line 7 def initialize(opts={}) default_opts = { :use_mouse => true, :speed => 300, :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] end |
Instance Attribute Details
#clicked_x ⇒ Object (readonly)
Returns the value of attribute clicked_x.
4 5 6 |
# File 'lib/lotu/cursor.rb', line 4 def clicked_x @clicked_x end |
#clicked_y ⇒ Object (readonly)
Returns the value of attribute clicked_y.
4 5 6 |
# File 'lib/lotu/cursor.rb', line 4 def clicked_y @clicked_y end |
#speed ⇒ Object
Returns the value of attribute speed.
5 6 7 |
# File 'lib/lotu/cursor.rb', line 5 def speed @speed end |
#use_mouse ⇒ Object
Returns the value of attribute use_mouse.
5 6 7 |
# File 'lib/lotu/cursor.rb', line 5 def use_mouse @use_mouse end |
Instance Method Details
#adjust_mouse ⇒ Object
41 42 43 44 |
# File 'lib/lotu/cursor.rb', line 41 def adjust_mouse $lotu.mouse_y = @y $lotu.mouse_x = @x end |
#click ⇒ Object
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
35 36 37 38 39 |
# File 'lib/lotu/cursor.rb', line 35 def click @clicked_x = @x @clicked_y = @y fire(:click, @clicked_x, @clicked_y) end |
#down ⇒ Object
51 52 53 54 |
# File 'lib/lotu/cursor.rb', line 51 def down @y += @speed * dt adjust_mouse if use_mouse end |
#left ⇒ Object
56 57 58 59 |
# File 'lib/lotu/cursor.rb', line 56 def left @x -= @speed * dt adjust_mouse if use_mouse end |
#right ⇒ Object
61 62 63 64 |
# File 'lib/lotu/cursor.rb', line 61 def right @x += @speed * dt adjust_mouse if use_mouse end |
#to_s ⇒ Object
66 67 68 69 |
# File 'lib/lotu/cursor.rb', line 66 def to_s ["@pos(#{format('%.2f, %.2f', @x, @y)})", "@clicked(#{format('%.2f, %.2f', @clicked_x, @clicked_y)})"] end |
#up ⇒ Object
46 47 48 49 |
# File 'lib/lotu/cursor.rb', line 46 def up @y -= @speed * dt adjust_mouse if use_mouse end |
#update ⇒ Object
23 24 25 26 27 28 29 |
# File 'lib/lotu/cursor.rb', line 23 def update super if @use_mouse @x = $lotu.mouse_x @y = $lotu.mouse_y end end |