ZLP1/scripts/entities/enemy/fang.lua

50 lines
1022 B
Lua

Fang = Entity:New(x,y)
function Fang:New(x,y)
local o = Entity:New(x,y)
o.moveSpeed = 3
o.hitbox = 10
o.sprite = love.graphics.newImage("assets/fangs.png")
o.draw_scale = 3
o.angle = 0
o.max_health = 3
o.health = o.max_health
-- lists
setmetatable(o, self)
self.__index = self
o:AddList("Simulate")
o:AddList("Enemy")
return o
end
function Fang:Step()
if self:CollisionWith(You) then
self.vel.x = 0
self.vel.y = 0
You.sprite = nil
else
self:MoveTowards(You.pos.x, You.pos.y, self.moveSpeed)
end
self.pos.x = self.pos.x + self.vel.x
self.pos.y = self.pos.y + self.vel.y
end
function Fang:Draw()
self:AngleTowards(You.pos.x, You.pos.y)
love.graphics.line(self.pos.x, self.pos.y, self.pos.x + 10*self.vel.x, self.pos.y + 10*self.vel.y)
love.graphics.draw(
self.sprite,
self.pos.x,
self.pos.y,
self.angle-math.rad(90),
self.draw_scale,
self.draw_scale,
self.sprite:getPixelWidth()/2,
self.sprite:getPixelHeight()/2
)
end