ZLP1/scripts/entities/bullet.lua

100 lines
2.6 KiB
Lua
Raw Normal View History

2021-12-31 11:21:48 +00:00
Projectile = Entity:New(x,y)
2021-12-31 01:46:21 +00:00
2021-12-31 11:21:48 +00:00
function Projectile:New(x,y,angle,data)
2021-12-31 01:46:21 +00:00
local o = Entity:New(x,y,angle)
o.target = {}
o.hitbox = 2
o.draw_scale = 2
o.angle = angle
o.hits = data.hits
o.damage = data.damage
2021-12-31 11:21:48 +00:00
-- i guess damage is useless to the player but maybe there's stuff that has hp? like obstacles
2021-12-31 01:46:21 +00:00
o.animation = AnimationContainer:New(data.animation)
2021-12-31 11:21:48 +00:00
2021-12-31 01:46:21 +00:00
o.moveSpeed = data.moveSpeed
2021-12-31 11:21:48 +00:00
o.moveSpeedLimits = data.moveSpeedLimits or { min = 0, max = 100}
2021-12-31 01:46:21 +00:00
o.moveSpeedIncrease = data.moveSpeedIncrease or 0
o.moveHorizontalIncrease = data.moveHorizontalIncrease or 0
o.moveVerticalIncrease = data.moveVerticalIncrease or 0
2021-12-31 11:21:48 +00:00
o.maximumTurnRate = data.maximumTurnRate or 0
2021-12-31 01:46:21 +00:00
o.moveHorizontal = 0
o.moveVertical = 0
-- lists
2022-01-17 23:53:03 +00:00
o:AddList("Simulate")
2021-12-31 01:46:21 +00:00
local friendly = data.friendly or false
local hostile = data.hostile or false
if friendly == true then
2022-01-17 23:53:03 +00:00
o:AddList("FriendlyBullet")
2021-12-31 01:46:21 +00:00
end
if hostile == true then
2022-01-17 23:53:03 +00:00
o:AddList("HostileBullet")
o.grazeTimer = 0
o.Grazed = false
2021-12-31 01:46:21 +00:00
end
setmetatable(o, self)
self.__index = self
return o
end
2021-12-31 11:21:48 +00:00
function Projectile:Step()
2021-12-31 01:46:21 +00:00
self.moveSpeed = self.moveSpeed + self.moveSpeedIncrease
2021-12-31 11:21:48 +00:00
self.moveSpeed = math.max(self.moveSpeedLimits.min,self.moveSpeed)
self.moveSpeed = math.min(self.moveSpeedLimits.max,self.moveSpeed)
2021-12-31 01:46:21 +00:00
self.moveHorizontal = self.moveHorizontal + self.moveHorizontalIncrease
self.moveVertical = self.moveVertical + self.moveVerticalIncrease
local move_x = (self.moveSpeed) * math.cos(self.angle) + self.moveHorizontal
local move_y = (self.moveSpeed) * math.sin(self.angle) + self.moveVertical
2021-12-31 11:21:48 +00:00
self:AngleTowards(
You.pos.x,
You.pos.y
)
2022-01-17 23:53:03 +00:00
-- bends towards the player? owo
2021-12-31 11:21:48 +00:00
self.pos.x = self.pos.x + move_x + self.maximumTurnRate * math.cos(self.angle)
self.pos.y = self.pos.y + move_y + self.maximumTurnRate * math.sin(self.angle)
2021-12-31 01:46:21 +00:00
self:AngleTowards(
self.pos.x + move_x,
self.pos.y + move_y
)
2021-12-31 11:21:48 +00:00
2022-01-17 23:53:03 +00:00
-- if out of s screen, kill.
if self.pos.x < 0 or self.pos.x > windowWidth
or self.pos.y < 0 or self.pos.y > windowHeight then
self:RemoveList("Simulate")
self:RemoveList("EnemyBullet")
self:RemoveList("FriendlyBullet")
2021-12-31 01:46:21 +00:00
end
end
2021-12-31 11:21:48 +00:00
function Projectile:Draw()
2021-12-31 01:46:21 +00:00
self.animation:Animate()
self.animation:Draw(
self.pos.x,
self.pos.y,
self.angle+math.rad(90),
self.draw_scale,
self.draw_scale
)
2022-01-17 23:53:03 +00:00
love.graphics.line(self.pos.x, self.pos.y, self.pos.x + 50*self.vel.x, self.pos.y + 50*self.vel.y)
2021-12-31 01:46:21 +00:00
--[[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