class Tank

class Tank

Attributes

direction[RW]

Public Class Methods

new(x, y, direction) click to toggle source
Calls superclass method GameObject::new
# File lib/entities/tank.rb, line 8
def initialize(x, y, direction)
  super(x, y, 2, 2, true)
  @direction = direction
  @missile = nil
  @shoot_timer = 0
  @level = 0
  @speed = 1
end

Public Instance Methods

can_shoot?() click to toggle source
# File lib/entities/tank.rb, line 43
def can_shoot?
  @missile.nil? && @shoot_timer == 0
end
canoonX() click to toggle source
# File lib/entities/tank.rb, line 47
def canoonX
  return @x + 14 if @direction == :right
  return @x - 12 if @direction == :left
  return @x + 3 if @direction == :up || @direction == :down
end
canoonY() click to toggle source
# File lib/entities/tank.rb, line 53
def canoonY
  return @y + 14 if @direction == :down
  return @y - 12 if @direction == :up
  @y
end
check_missile() click to toggle source
# File lib/entities/tank.rb, line 59
def check_missile
  return if @missile.nil?
  if @missile.done?
    @missile = nil
    @shoot_timer = 20 - @level * 3
  end
end
move() click to toggle source
# File lib/entities/tank.rb, line 17
def move
  @x -= 0.5 * @speed if @direction == :left
  @x += 0.5 * @speed if @direction == :right
  @y += 0.5 * @speed if @direction == :down
  @y -= 0.5 * @speed if @direction == :up
  @x = 0 if @x < 0
  @y = 0 if @y < 0
  @x = 240 if @x > 240
  @y = 208 if @y > 208
  @collider.update(@x, @y)
end
return_back() click to toggle source
# File lib/entities/tank.rb, line 29
def return_back
  @x += 0.5 * @speed if @direction == :left
  @x -= 0.5 * @speed if @direction == :right
  @y -= 0.5 * @speed if @direction == :down
  @y += 0.5 * @speed if @direction == :up
  @collider.update(@x, @y)
end
shoot() click to toggle source
# File lib/entities/tank.rb, line 37
def shoot
  @missile = Bullet.new(self, true) if can_shoot? && @level == 4
  @missile = Bullet.new(self) if can_shoot?
  @missile
end
update() click to toggle source
# File lib/entities/tank.rb, line 67
def update
  @shoot_timer -= 1 if @shoot_timer > 0
end