Class: Gembots::Robot
- Inherits:
-
Object
- Object
- Gembots::Robot
- Defined in:
- lib/gembots/bot.rb
Instance Attribute Summary collapse
-
#actions ⇒ Object
readonly
Returns the value of attribute actions.
-
#angle ⇒ Object
readonly
Returns the value of attribute angle.
-
#x ⇒ Object
readonly
Returns the value of attribute x.
-
#y ⇒ Object
readonly
Returns the value of attribute y.
Instance Method Summary collapse
- #draw ⇒ Object
- #fire ⇒ Object
-
#initialize(window) ⇒ Robot
constructor
A new instance of Robot.
- #move(dist = 10) ⇒ Object
- #turn(angle = 10) ⇒ Object
- #update ⇒ Object
- #warp(x, y) ⇒ Object
Constructor Details
#initialize(window) ⇒ Robot
Returns a new instance of Robot.
6 7 8 9 10 11 12 |
# File 'lib/gembots/bot.rb', line 6 def initialize window @actions = [] @window = window @images = Gosu::Image::load_tiles(window, "media/tank.png", 32, 32, false) @image = Gosu::Image.new window, "media/cannon.png", false @x = @y = @angle = @cur_image = 0.0 end |
Instance Attribute Details
#actions ⇒ Object (readonly)
Returns the value of attribute actions.
4 5 6 |
# File 'lib/gembots/bot.rb', line 4 def actions @actions end |
#angle ⇒ Object (readonly)
Returns the value of attribute angle.
4 5 6 |
# File 'lib/gembots/bot.rb', line 4 def angle @angle end |
#x ⇒ Object (readonly)
Returns the value of attribute x.
4 5 6 |
# File 'lib/gembots/bot.rb', line 4 def x @x end |
#y ⇒ Object (readonly)
Returns the value of attribute y.
4 5 6 |
# File 'lib/gembots/bot.rb', line 4 def y @y end |
Instance Method Details
#draw ⇒ Object
59 60 61 62 |
# File 'lib/gembots/bot.rb', line 59 def draw @images[@cur_image].draw_rot @x, @y, 1, @angle - 90 % 360 @image.draw_rot @x, @y, 1, @angle - 90 % 360 end |
#fire ⇒ Object
64 65 66 |
# File 'lib/gembots/bot.rb', line 64 def fire @actions << [:fire] end |
#move(dist = 10) ⇒ Object
22 23 24 |
# File 'lib/gembots/bot.rb', line 22 def move dist=10 @actions << [:move, dist] end |
#turn(angle = 10) ⇒ Object
18 19 20 |
# File 'lib/gembots/bot.rb', line 18 def turn angle=10 @actions << [:turn, angle] end |
#update ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/gembots/bot.rb', line 26 def update return if @actions.empty? case @actions[0][0] when :move then # I probably should implement dist = @actions[0][1]; dist %= 0.5 or something # but right now I'm tired, and worried I will screw up the math if I try that... dist = @actions[0][1] <= 0.9 ? @actions[0][1] : 1.0 @x += Gosu::offset_x @angle, dist @y += Gosu::offset_y @angle, dist @x %= 640 @y %= 480 @cur_image += 0.1 @cur_image %= 7.0 @actions[0][1] -= 0.5 @actions.shift if @actions[0][1] == 0.0 when :turn then deg = @actions[0][1] <= 9 ? @actions[0][1] : 10 @angle += deg @angle %= 360 @actions[0][1] -= deg @actions.shift if @actions[0][1] == 0 when :fire @window.spawn_proj self @actions.shift end end |
#warp(x, y) ⇒ Object
14 15 16 |
# File 'lib/gembots/bot.rb', line 14 def warp x, y @x, @y = x, y end |