47 lines
938 B
Lua
47 lines
938 B
Lua
local Entity = require "scenes.levels.entities.parent"
|
|
|
|
local Bullet = Entity:extend()
|
|
|
|
function Bullet:new(world, x, y, w, h, speed, dir)
|
|
Bullet.super.new(self, world, "bullet", x - (w / 2), y - (h / 2), w, h)
|
|
self.life = 0;
|
|
self:setMotionDirection(dir, speed)
|
|
end
|
|
|
|
function Bullet:setFilter()
|
|
self.filter = function(item, other)
|
|
if (other.type=="wall") then
|
|
return 'touch'
|
|
else
|
|
return 'cross'
|
|
end
|
|
end
|
|
end
|
|
|
|
function Bullet:update(dt)
|
|
self:setFilter()
|
|
|
|
local cols, cols_len
|
|
self.x, self.y, cols, cols_len = self:move(dt)
|
|
|
|
for j=1,cols_len do
|
|
local other = cols[j].other
|
|
if other.type=="wall" and (self.life == 1) then
|
|
self:destroy()
|
|
end
|
|
end
|
|
|
|
self.life = 1
|
|
|
|
local isInsideView = self:isInsideView()
|
|
if (isInsideView == false) or (self.xsp == 0) then
|
|
self:destroy()
|
|
end
|
|
end
|
|
|
|
function Bullet:draw(dt)
|
|
currentLevel:drawHitbox(self, 0,128,0)
|
|
end
|
|
|
|
return Bullet
|