fix: multi-directionnal weapons

This commit is contained in:
Kazhnuz Klappsthul 2021-11-27 13:11:05 +01:00
parent e676439431
commit 516ed301bd
1 changed files with 13 additions and 6 deletions

View File

@ -1,13 +1,13 @@
local Parent = require "game.modules.subgames.world.actors.parent" local Parent = require "game.modules.subgames.world.actors.parent"
local WeaponShot = Parent:extend() local WeaponShot = Parent:extend()
function WeaponShot:new(world, x, y, z, direction, data, creator) function WeaponShot:new(world, x, y, z, angle, data, creator)
WeaponShot.super.new(self, world, "shot", x, y, z, 16, 8, 16, false) WeaponShot.super.new(self, world, "shot", x, y, z, 16, 8, 16, false)
self:setSprite("ringweapon", 0, 0) self:setSprite("ringweapon", 0, 0)
self.direction = direction self.angle = -angle
self.data = data self.data = data
self.zsp = self.data.zspeed self.zsp = self.data.zspeed
self.xsp = (self.data.xspeed * direction) self.xsp, self.ysp = utils.math.lengthdir(self.data.xspeed, angle)
self.xfrc, self.yfrc = 0, 0 self.xfrc, self.yfrc = 0, 0
if (self.zsp ~= 0) then if (self.zsp ~= 0) then
self:setGravity(480*2) self:setGravity(480*2)
@ -16,7 +16,13 @@ function WeaponShot:new(world, x, y, z, direction, data, creator)
end end
function WeaponShot:updateStart(dt) function WeaponShot:updateStart(dt)
if (self.xsp == 0) then if (self.xsp == 0 and self.ysp == 0) then
self:destroy()
end
end
function WeaponShot:collisionResponse(collision)
if collision.other.isSolid then
self:destroy() self:destroy()
end end
end end
@ -25,9 +31,10 @@ function WeaponShot:draw()
love.graphics.setColor(self.data.color[1], self.data.color[2], self.data.color[3], 1) love.graphics.setColor(self.data.color[1], self.data.color[2], self.data.color[3], 1)
WeaponShot.super.draw(self) WeaponShot.super.draw(self)
love.graphics.setColor(self.data.color[1], self.data.color[2], self.data.color[3], 0.6) love.graphics.setColor(self.data.color[1], self.data.color[2], self.data.color[3], 0.6)
local x, y = self.x + self.y/2 + 8, self.y - self.z - 3 --local x, y = self.x + self.y/2 + 8, self.y - self.z - 3
local x, y = self:computeDrawingPosition()
local angle = utils.math.pointDirection(0, 0, self.xsp, self.zsp * -1) local angle = utils.math.pointDirection(0, 0, self.xsp, self.zsp * -1)
self.scene.assets.sprites["ringtoss"]:draw(x, y, angle) self.scene.assets.sprites["ringtoss"]:draw(x + 8, y + 8, self.angle)
love.graphics.setColor(1, 1, 1, 1) love.graphics.setColor(1, 1, 1, 1)
end end