class RubyMan::MovingObject

GridObject with the ability to move smoothly in 4 directions

Attributes

direction[RW]
phase[RW]
speed[RW]

Public Class Methods

new() click to toggle source
Calls superclass method RubyMan::GridObject::new
# File lib/ruby_man/GameObjects/moving_object.rb, line 9
def initialize
  super
  @direction = Direction.none
  @phase = 0
  @speed = 0
end

Public Instance Methods

change_direction(direction) click to toggle source
# File lib/ruby_man/GameObjects/moving_object.rb, line 33
def change_direction(direction)
  @direction = direction
  @image_angle = direction.to_angle
end
collision(_other) click to toggle source
# File lib/ruby_man/GameObjects/moving_object.rb, line 30
def collision(_other)
end
direction_free(direction) click to toggle source
# File lib/ruby_man/GameObjects/moving_object.rb, line 38
def direction_free(direction)
  @game.place_free(@grid_x + direction.rel_x, @grid_y + direction.rel_y)
end
grid_step() click to toggle source
# File lib/ruby_man/GameObjects/moving_object.rb, line 27
def grid_step
end
pixel_x() click to toggle source
# File lib/ruby_man/GameObjects/moving_object.rb, line 42
def pixel_x
  (@grid_x + @direction.rel_x * @phase) * 32
end
pixel_y() click to toggle source
# File lib/ruby_man/GameObjects/moving_object.rb, line 46
def pixel_y
  (@grid_y + @direction.rel_y * @phase) * 32
end
update(delta) click to toggle source
Calls superclass method RubyMan::GridObject#update
# File lib/ruby_man/GameObjects/moving_object.rb, line 16
def update(delta)
  super
  @phase += @speed * delta
  while @phase > 1
    @phase -= 1
    @grid_x += @direction.rel_x
    @grid_y += @direction.rel_y
    grid_step
  end
end