95 lines
2.4 KiB
Lua
95 lines
2.4 KiB
Lua
|
Shooter = Entity:New(x,y)
|
||
|
|
||
|
function Shooter:New(x,y)
|
||
|
local o = Entity:New(x,y)
|
||
|
|
||
|
o.moveSpeed = 0
|
||
|
o.hitbox = 10
|
||
|
o.sprite = love.graphics.newImage("assets/shooter.png")
|
||
|
o.sprite_cannon = love.graphics.newImage("assets/shooter_cannon.png")
|
||
|
o.draw_scale = 3
|
||
|
o.angle = 0
|
||
|
o.max_health = 2000
|
||
|
o.health = o.max_health
|
||
|
o.show_health = true
|
||
|
o.shotTimer = 1
|
||
|
-- lists
|
||
|
|
||
|
setmetatable(o, self)
|
||
|
self.__index = self
|
||
|
|
||
|
o:AddList(List.Simulate)
|
||
|
o:AddList(List.Enemy)
|
||
|
o:ChangePattern(AttackPattern.DrowningBarrage)
|
||
|
|
||
|
return o
|
||
|
end
|
||
|
|
||
|
function Shooter:ChangePattern(pattern)
|
||
|
self.patternTimer = 0
|
||
|
self.patternTime = 10000
|
||
|
self.pattern_t = 0
|
||
|
self.pattern_v1 = nil
|
||
|
self.pattern_v2 = nil
|
||
|
self.pattern_v3 = nil
|
||
|
self.patternActive = pattern
|
||
|
self.nextPattern = nil
|
||
|
end
|
||
|
|
||
|
function Shooter:Step()
|
||
|
if self.shotTimer > 0 then self.shotTimer = self.shotTimer - current_dt end
|
||
|
if self.shotTimer < 0 then self.shotTimer = 0 end
|
||
|
|
||
|
--self:AngleTowards(target_x,target_y)
|
||
|
if self.shotTimer <= 0 then
|
||
|
self.pattern_t = self.pattern_t + 1 or 0
|
||
|
self.patternActive(self,self.pattern_t,self.pattern_v1,self.pattern_v2,self.pattern_v3)
|
||
|
end
|
||
|
|
||
|
self.patternTimer = self.patternTimer + current_dt
|
||
|
if self.patternTimer >= self.patternTime then
|
||
|
self:ChangePattern(self.nextPattern)
|
||
|
end
|
||
|
|
||
|
self.pos.x = self.pos.x + self.vel.x
|
||
|
self.pos.y = self.pos.y + self.vel.y
|
||
|
end
|
||
|
|
||
|
function Shooter:Draw()
|
||
|
love.graphics.draw(
|
||
|
self.sprite,
|
||
|
self.pos.x,
|
||
|
self.pos.y,
|
||
|
0, --self.angle-math.rad(90),
|
||
|
self.draw_scale,
|
||
|
self.draw_scale,
|
||
|
self.sprite:getPixelWidth()/2,
|
||
|
self.sprite:getPixelHeight()/2
|
||
|
)
|
||
|
local bullet_variables = ""
|
||
|
if self.pattern_v1 ~= nil then
|
||
|
bullet_variables = bullet_variables .. " a: " .. self.pattern_v1 .. ", " or ""
|
||
|
end
|
||
|
if self.pattern_v2 ~= nil then
|
||
|
bullet_variables = bullet_variables .. " b: " .. self.pattern_v2 .. ", " or ""
|
||
|
end
|
||
|
if self.pattern_v3 ~= nil then
|
||
|
bullet_variables = bullet_variables .. " c: " .. self.pattern_v3 or ""
|
||
|
end
|
||
|
if self.patternTimer ~= nil then
|
||
|
bullet_variables = bullet_variables .. " TIME: " .. self.patternTimer or ""
|
||
|
end
|
||
|
|
||
|
love.graphics.print(self.pattern_t .. bullet_variables,self.pos.x,self.pos.y-40)
|
||
|
love.graphics.draw(
|
||
|
self.sprite_cannon,
|
||
|
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
|