Skip to content

Instantly share code, notes, and snippets.

@mbuck-r7
Created May 5, 2014 23:30
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 mbuck-r7/cf651c446b9476b4e280 to your computer and use it in GitHub Desktop.
Save mbuck-r7/cf651c446b9476b4e280 to your computer and use it in GitHub Desktop.
# -*- encoding: utf-8 -*-
# Keyboard: Sample Bot
#
# Special bot controlled with the keyboard
#
# Controls:
# w drive forward
# s drive backwards
# a rotate left
# d rotate right
#
# ↑ fire powerful shot
# ↓ fire week shot
# ← rotate turret left
# → rotate turret right
class Keyboard < RTanque::Bot::Brain
include RTanque::Bot::BrainHelper
NAME = 'Keyboard'
def tick!
command.radar_heading = sensors.radar_heading + (RTanque::Heading::ONE_DEGREE * 30)
if sensors.button_down?(Gosu::KbLeft)
command.turret_heading = sensors.turret_heading - (RTanque::Heading::ONE_DEGREE * 10)
elsif sensors.button_down?(Gosu::KbRight)
command.turret_heading = sensors.turret_heading + (RTanque::Heading::ONE_DEGREE * 10)
end
if sensors.button_down?('a')
command.heading = sensors.heading - (RTanque::Heading::ONE_DEGREE * 10)
elsif sensors.button_down?('d')
command.heading = sensors.heading + (RTanque::Heading::ONE_DEGREE * 10)
end
if sensors.button_down?('w')
command.speed = 10
elsif sensors.button_down?('s')
command.speed = -10
else
command.speed = 0
end
if sensors.button_down?(Gosu::KbUp)
command.fire_power = 5
elsif sensors.button_down?(Gosu::KbDown)
command.fire_power = 1
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment