Sha256: 9e4a4c28420431846349612634b04f99981fdbf5bff9a6b3218fc86c0e0855fe
Contents?: true
Size: 1.24 KB
Versions: 4
Compression:
Stored size: 1.24 KB
Contents
module FeedBo module Transformable attr_accessor :direction def initialize super @direction = 2 end 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 def turn_left_frame(speed=1) @direction -= 0.25 * speed @direction += 8 if @direction < 0 rotate(-11.25 * speed) end def turn_right_frame(speed=1) @direction += 0.25 * speed @direction -= 8 if @direction >= 8 rotate(11.25 * speed) end protected 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 end end
Version data entries
4 entries across 4 versions & 1 rubygems
Version | Path |
---|---|
feed_bo-0.0.4 | lib/feed_bo/transformable.rb |
feed_bo-0.0.3 | lib/feed_bo/transformable.rb |
feed_bo-0.0.2 | lib/feed_bo/transformable.rb |
feed_bo-0.0.1 | lib/feed_bo/transformable.rb |