class Tank

Constants

SHOOT_DELAY

Attributes

direction[RW]
fire_rate_modifier[RW]
graphics[RW]
gun_angle[RW]
health[RW]
input[RW]
physics[RW]
sounds[RW]
speed_modifier[RW]
throttle_down[RW]

Public Class Methods

new(object_pool, input) click to toggle source
Calls superclass method GameObject::new
# File lib/entities/tank.rb, line 7
def initialize(object_pool, input)
  x, y = object_pool.map.spawn_point
  super(object_pool, x, y)
  @input = input
  @input.control(self)
  @physics = TankPhysics.new(self, object_pool)
  @sounds = TankSounds.new(self, object_pool)
  @health = TankHealth.new(self, object_pool)
  @graphics = TankGraphics.new(self)
  @direction = rand(0..7) * 45
  @gun_angle = rand(0..360)
  reset_modifiers
end

Public Instance Methods

box() click to toggle source
# File lib/entities/tank.rb, line 21
def box
  @physics.box
end
can_shoot?() click to toggle source
# File lib/entities/tank.rb, line 50
def can_shoot?
  Gosu.milliseconds - (@last_shot || 0) >
    (SHOOT_DELAY / @fire_rate_modifier)
end
on_collision(object) click to toggle source
# File lib/entities/tank.rb, line 25
def on_collision(object)
  return unless object
  # Avoid recursion
  if object.class == Tank
    # Inform AI about hit
    object.input.on_collision(object)
  else
    # Call only on non-tanks to avoid recursion
    object.on_collision(self)
  end
  # Bullets should not slow Tanks down
  if object.class != Bullet
    @sounds.collide if @physics.speed > 1
  end
end
reset_modifiers() click to toggle source
# File lib/entities/tank.rb, line 55
def reset_modifiers
  @fire_rate_modifier = 1
  @speed_modifier = 1
end
shoot(target_x, target_y) click to toggle source
# File lib/entities/tank.rb, line 41
def shoot(target_x, target_y)
  if can_shoot?
    @last_shot = Gosu.milliseconds
    Bullet.new(object_pool, @x, @y, target_x, target_y).fire(
      self, 1500)
    input.stats.add_shot
  end
end
to_s() click to toggle source
# File lib/entities/tank.rb, line 60
def to_s
  "Tank [#{@health.health}@#{@x}:#{@y}@#{@physics.speed.round(2)}px/tick]#{@input.stats}"
end