61 lines
1.4 KiB
Lua
61 lines
1.4 KiB
Lua
Tank = {}
|
|
|
|
class("Tank").extends(Graphics.sprite)
|
|
|
|
function Tank:init(x, y, player, ground)
|
|
self.tankImage = Graphics.image.new("assets/sprites/tank")
|
|
self.tankImageD = Graphics.image.new("assets/sprites/tankD")
|
|
Tank.super.init(self)
|
|
|
|
local width, height = self.tankImage:getSize()
|
|
|
|
self.faded_image = Graphics.image.new(width, height, Graphics.kColorClear)
|
|
|
|
Graphics.pushContext(self.faded_image)
|
|
self.tankImageD:drawBlurred(0, 0, 2, 2, Graphics.image.kDitherTypeFloydSteinberg)
|
|
Graphics.popContext()
|
|
|
|
-- 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.moveSpeed = 2
|
|
Tank.player = player
|
|
Tank.ground = ground
|
|
|
|
self:fadein()
|
|
|
|
self:moveTo(x, y)
|
|
end
|
|
|
|
function Tank:fadein()
|
|
self:setImage(self.tankImage)
|
|
end
|
|
|
|
function Tank:fadeout()
|
|
self:setImage(self.faded_image)
|
|
end
|
|
|
|
function Tank:update()
|
|
if self.x <= 330 then
|
|
Tank.ground:setMoveSpeed(0)
|
|
return
|
|
end
|
|
|
|
-- Speedup when player is moving right
|
|
if Tank.player.isMovingRight() == false then
|
|
Tank.moveSpeed = 0.2
|
|
else
|
|
Tank.moveSpeed = 1
|
|
end
|
|
|
|
self:moveTo(self.x - Tank.moveSpeed, self.y)
|
|
end
|