fpv/source/scripts/tankSprite.lua

52 lines
1.2 KiB
Lua
Raw Normal View History

2024-06-01 22:46:36 +03:00
Tank = {}
class("Tank").extends(Graphics.sprite)
2024-06-03 21:15:23 +03:00
function Tank:init(x, y, ground)
2024-06-01 22:46:36 +03:00
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)
2024-06-02 20:25:27 +03:00
Graphics.popContext()
2024-06-01 22:46:36 +03:00
-- Collision properties
2024-06-03 00:31:15 +03:00
self:setZIndex(ZIndex.enemy)
2024-06-01 22:46:36 +03:00
self:setTag(2)
self:setCollideRect(4, 56, 147, 65)
2024-06-03 00:31:15 +03:00
self:setGroups(CollideGroups.enemy)
self:setCollidesWithGroups(
{
CollideGroups.player
})
2024-06-01 22:46:36 +03:00
-- 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.faded_image)
end
function Tank:update()
if self.x <= 330 then
Tank.ground:setMoveSpeed(0)
return
end
2024-06-03 21:15:23 +03:00
self:moveTo(self.x - Tank.ground.moveSpeed, self.y)
2024-06-01 22:46:36 +03:00
end