Class: RubyGame::MovingObject
- Inherits:
-
StaticObject
- Object
- StaticObject
- RubyGame::MovingObject
- Defined in:
- lib/ruby_game/moving_object.rb
Instance Attribute Summary
Attributes inherited from StaticObject
Instance Method Summary collapse
- #init_limits(max_width, max_height, border_with, border_top_with) ⇒ Object
-
#initialize(x, y, image_name) ⇒ MovingObject
constructor
A new instance of MovingObject.
- #move_down(velocity = @velocity) ⇒ Object
- #move_left(velocity = @velocity) ⇒ Object
- #move_right(velocity = @velocity) ⇒ Object
- #move_up(velocity = @velocity) ⇒ Object
- #touch?(object) ⇒ Boolean
Methods inherited from StaticObject
Constructor Details
#initialize(x, y, image_name) ⇒ MovingObject
Returns a new instance of MovingObject.
3 4 5 6 |
# File 'lib/ruby_game/moving_object.rb', line 3 def initialize(x, y, image_name) super @velocity = 2 end |
Instance Method Details
#init_limits(max_width, max_height, border_with, border_top_with) ⇒ Object
8 9 10 11 |
# File 'lib/ruby_game/moving_object.rb', line 8 def init_limits(max_width, max_height, border_with, border_top_with) @max_width, @max_height = max_width, max_height @border_with, @border_top_with = border_with, border_top_with end |
#move_down(velocity = @velocity) ⇒ Object
29 30 31 |
# File 'lib/ruby_game/moving_object.rb', line 29 def move_down(velocity = @velocity) @y += velocity if @y < @max_height - @border_with - (@image.height/2) end |
#move_left(velocity = @velocity) ⇒ Object
17 18 19 |
# File 'lib/ruby_game/moving_object.rb', line 17 def move_left(velocity = @velocity) @x -= velocity if @x > @border_with + (@image.width/2) end |
#move_right(velocity = @velocity) ⇒ Object
21 22 23 |
# File 'lib/ruby_game/moving_object.rb', line 21 def move_right(velocity = @velocity) @x += velocity if @x < @max_width - @border_with - (@image.width/2) end |
#move_up(velocity = @velocity) ⇒ Object
25 26 27 |
# File 'lib/ruby_game/moving_object.rb', line 25 def move_up(velocity = @velocity) @y -= velocity if @y > @border_with + @border_top_with + (@image.height/2) end |
#touch?(object) ⇒ Boolean
13 14 15 |
# File 'lib/ruby_game/moving_object.rb', line 13 def touch?(object) Math.hypot(object.x - @x, object.y - @y) <= object.width/2 end |