Skip to content

Instantly share code, notes, and snippets.

@benstafford
Created November 21, 2012 00:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save benstafford/4122319 to your computer and use it in GitHub Desktop.
Save benstafford/4122319 to your computer and use it in GitHub Desktop.
Deathbot
require 'rrobots'
class Deathbot
include Robot
def tick events
@turn_speed = 2 if @turn_speed.nil?
@time_turned = 0 if @time_turned.nil?
if (!events['robot_scanned'].empty?)
accelerate -1
turn @turn_speed *= -1
fire 1
end
if against_wall?
change_direction
@time_turned = time
else
accelerate 1
turn @turn_speed
turn_gun @turn_speed * 1.1
end
#slow down if recently got hit, otherwise speed up
if @last_hit && time - @last_hit < 20
accelerate(-1)
else
accelerate 1
end
end
def against_wall?
if x <= size or x >= battlefield_width-size or
y <= size or y >= battlefield_width-size
return true
end
return false
end
def change_direction
if x <= size
if heading > 270
turn 10
else
turn -10
end
end
if x >= battlefield_width-size
if heading > 90
turn 10
else
turn -10
end
end
if y <= size
if heading > 180
turn 10
else
turn -10
end
end
if y >= battlefield_height-size
if heading > 0 and heading < 90
turn 10
else
turn -10
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment