Class: Lotu::Cursor
- Inherits:
-
Actor
- Object
- GameEntity
- Actor
- Lotu::Cursor
- Defined in:
- lib/lotu/cursor.rb
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, #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, #factor=, #parse_options, #rand_color, #set_gosu_image, #set_image
Methods included from Behavior
Methods included from Helpers::Util
#class_debug_info, #instance_debug_info, #parse_cli_options
Methods inherited from GameEntity
Constructor Details
#initialize(opts = {}) ⇒ Cursor
Returns a new instance of Cursor.
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/lotu/cursor.rb', line 9 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.
6 7 8 |
# File 'lib/lotu/cursor.rb', line 6 def clicked_x @clicked_x end |
#clicked_y ⇒ Object (readonly)
Returns the value of attribute clicked_y.
6 7 8 |
# File 'lib/lotu/cursor.rb', line 6 def clicked_y @clicked_y end |
#speed ⇒ Object
Returns the value of attribute speed.
7 8 9 |
# File 'lib/lotu/cursor.rb', line 7 def speed @speed end |
#use_mouse ⇒ Object
Returns the value of attribute use_mouse.
7 8 9 |
# File 'lib/lotu/cursor.rb', line 7 def use_mouse @use_mouse end |
Instance Method Details
#adjust_mouse ⇒ Object
43 44 45 46 |
# File 'lib/lotu/cursor.rb', line 43 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
37 38 39 40 41 |
# File 'lib/lotu/cursor.rb', line 37 def click @clicked_x = @x @clicked_y = @y fire(:click, @clicked_x, @clicked_y) end |
#down ⇒ Object
53 54 55 56 |
# File 'lib/lotu/cursor.rb', line 53 def down @y += @speed * dt adjust_mouse if use_mouse end |
#left ⇒ Object
58 59 60 61 |
# File 'lib/lotu/cursor.rb', line 58 def left @x -= @speed * dt adjust_mouse if use_mouse end |
#right ⇒ Object
63 64 65 66 |
# File 'lib/lotu/cursor.rb', line 63 def right @x += @speed * dt adjust_mouse if use_mouse end |
#to_s ⇒ Object
68 69 70 71 |
# File 'lib/lotu/cursor.rb', line 68 def to_s ["@pos(#{format('%.2f, %.2f', @x, @y)})", "@clicked(#{format('%.2f, %.2f', @clicked_x, @clicked_y)})"] end |
#up ⇒ Object
48 49 50 51 |
# File 'lib/lotu/cursor.rb', line 48 def up @y -= @speed * dt adjust_mouse if use_mouse end |
#update ⇒ Object
25 26 27 28 29 30 31 |
# File 'lib/lotu/cursor.rb', line 25 def update super if @use_mouse @x = $lotu.mouse_x @y = $lotu.mouse_y end end |