forked from h13ronim/rrobots
-
Notifications
You must be signed in to change notification settings - Fork 0
RobotZippy
Matthew Nielsen edited this page Aug 26, 2015
·
1 revision
class Zippy include Robot
def tick events @direction ||= :right
unless pointing_right?
turn_right
return
end
if @direction == :right
if distance_from_max > 8
accelerate(1)
else
stop
@direction = :left if stopped?
end
else
if distance_from_min > 8
accelerate(-1)
else
stop
@direction = :right if stopped?
end
end
turn_gun(-1)
unless events['robot_scanned'].empty?
say 'GOTCHA!'
fire 3
end
end
def stopped? speed == 0 end
def pointing_right? heading == 0 end
def turn_right new_heading = heading > 10 ? heading - 10 : heading turn(-new_heading) end
def distance_from_max (battlefield_width - size) - x end
def distance_from_min x - size end
end