Class: Lotu::Cursor

Inherits:
Actor
  • Object
show all
Defined in:
lib/lotu/cursor.rb

Instance Attribute Summary collapse

Attributes inherited from Actor

#parent, #x, #y

Instance Method Summary collapse

Methods inherited from Actor

#dt, #init_behavior

Methods included from Resourceful

#is_resourceful

Methods included from Drawable

#is_drawable

Methods included from Controllable

#is_controllable

Methods included from Eventful

#is_eventful

Constructor Details

#initializeCursor

Returns a new instance of Cursor.



7
8
9
10
11
# File 'lib/lotu/cursor.rb', line 7

def initialize
  super
  @click_x = @click_y = 0
  @arrow_speed = 1
end

Instance Attribute Details

#arrow_speedObject

Returns the value of attribute arrow_speed.



5
6
7
# File 'lib/lotu/cursor.rb', line 5

def arrow_speed
  @arrow_speed
end

#click_xObject (readonly)

Returns the value of attribute click_x.



4
5
6
# File 'lib/lotu/cursor.rb', line 4

def click_x
  @click_x
end

#click_yObject (readonly)

Returns the value of attribute click_y.



4
5
6
# File 'lib/lotu/cursor.rb', line 4

def click_y
  @click_y
end

Instance Method Details

#clickObject

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 click



22
23
24
25
26
# File 'lib/lotu/cursor.rb', line 22

def click
  @click_x = $window.mouse_x
  @click_y = $window.mouse_y
  fire(:click, @click_x, @click_y)
end

#downObject



32
33
34
# File 'lib/lotu/cursor.rb', line 32

def down
  $window.mouse_y += @arrow_speed
end

#last_clickObject



44
45
46
# File 'lib/lotu/cursor.rb', line 44

def last_click
  "#{@click_x}, #{@click_y}"
end

#leftObject



36
37
38
# File 'lib/lotu/cursor.rb', line 36

def left
  $window.mouse_x -= @arrow_speed
end

#rightObject



40
41
42
# File 'lib/lotu/cursor.rb', line 40

def right
  $window.mouse_x += @arrow_speed
end

#upObject



28
29
30
# File 'lib/lotu/cursor.rb', line 28

def up
  $window.mouse_y -= @arrow_speed
end

#updateObject



13
14
15
16
# File 'lib/lotu/cursor.rb', line 13

def update
  @x = $window.mouse_x
  @y = $window.mouse_y
end