Tank = {}

class("Tank").extends(Graphics.sprite)

function Tank:init(x, y, ground)
    local target = Targets[CurrentMission.targetIndex]
    self.tankImage = Graphics.image.new(target.sprite)
    self.tankImageD = Graphics.image.new(target.spriteD)
    Tank.super.init(self)

    -- Collision properties
    self:setZIndex(ZIndex.enemy)
    self:setTag(2)
    self:setCollideRect(4, 56, 147, 65)
    self:setGroups(CollideGroups.enemy)
    self:setCollidesWithGroups(
        {
            CollideGroups.player
        })

    -- Main properties
    Tank.ground = ground

    self:fadein()

    self:moveTo(x, y)
end

function Tank:fadein()
    self:setImage(self.tankImage)
end

function Tank:fadeout()
    self:setImage(self.tankImageD)
end

function Tank:update()
    if self.x <= 330 then
        Tank.ground:setMoveSpeed(0)
        return
    end

    self:moveTo(self.x - Tank.ground.moveSpeed, self.y)
end
