module FeedBo::Transformable

Attributes

direction[RW]

Public Class Methods

new() click to toggle source
Calls superclass method
# File lib/feed_bo/transformable.rb, line 6
def initialize
  super
  @direction = 2
end

Public Instance Methods

move_frame() click to toggle source
# File lib/feed_bo/transformable.rb, line 11
def move_frame
  x_movement = case @direction
    when 0,4 then 0
    when 1,2,3 then 1
    when 5,6,7 then -1
  end
  y_movement = case @direction
    when 2,6 then 0
    when 3,4,5 then 1
    when 7,0,1 then -1
  end
  unless @level.position_blocked? @position[0]+0.25*x_movement, @position[1]+0.25*y_movement
    @position[0] += 0.25 * x_movement
    @position[1] += 0.25 * y_movement
  end
end
turn_left_frame(speed=1) click to toggle source
# File lib/feed_bo/transformable.rb, line 28
def turn_left_frame(speed=1)
  @direction -= 0.25 * speed
  @direction += 8 if @direction < 0
  rotate(-11.25 * speed)
end
turn_right_frame(speed=1) click to toggle source
# File lib/feed_bo/transformable.rb, line 34
def turn_right_frame(speed=1)
  @direction += 0.25 * speed
  @direction -= 8 if @direction >= 8
  rotate(11.25 * speed)
end

Protected Instance Methods

rotate(degrees) click to toggle source
# File lib/feed_bo/transformable.rb, line 42
def rotate(degrees)
  radians = degrees * Math::PI / 180
  s = Level::FIELD_SIZE / 2
  @points.map! { |p| [p[0]-s, p[1]-s] }
  @points.map! do |p|
    [ Math.cos(radians) * p[0] - Math.sin(radians) * p[1],
      Math.sin(radians) * p[0] + Math.cos(radians) * p[1] ]
  end
  @points.map! { |p| [p[0]+s, p[1]+s] }
end