Make this not dependent on the variable
Posted: Thu Feb 16, 2023 1:15 pm
Hello!
I'm trying to make a tower defense and I need to make my tower placement not dependent on this variable so that it can be placed infinite times, Here's the code of the tower class
I'm trying to make a tower defense and I need to make my tower placement not dependent on this variable so that it can be placed infinite times, Here's the code of the tower class
Thanks for your help!Sling = Class{}
function Sling:init()
self.image = love.graphics.newImage("Sling.png")
self.x = 964
self.y = 64
self.width = self.image:getWidth()
self.height = self.image:getHeight()
MXCONSTANT = 964
MYCONSTANT = 64
end
function Sling:collide()
if ((self.x >= mouseX + 10) or
(self.x + 64 <= mouseX) or
(self.y >= mouseY + 10) or
(self.y + 64 <= mouseY)) then
return false
else return true
end
end
function Sling:update(dt)
SliCol = Sling:collide()
if SliCol and pressed and screws >= 100 then
Tower = true
elseif Tower and pressed then
Tower = false
screws = screws - 100
end
if Tower == true then
MXCONSTANT = mouseX - 25
MYCONSTANT = mouseY - 25
end
end
function Sling:render()
love.graphics.draw(self.image, self.x, self.y)
love.graphics.printf(tostring(screws), Window_W / 2, 500, 100, "center")
if Tower then
love.graphics.draw(self.image, mouseX - 25, mouseY - 25)
elseif not Tower then
love.graphics.draw(self.image, MXCONSTANT, MYCONSTANT)
end
end