65 lines
1.6 KiB
Lua
65 lines
1.6 KiB
Lua
--cursor.lua
|
|
Cursor = {}
|
|
Cursor.__index = Cursor
|
|
local Cleaver = require("src/cleaver")
|
|
|
|
function Cursor:new()
|
|
local instance = setmetatable({}, Cursor)
|
|
instance.state = "idle"
|
|
instance.states = {"idle", "cleaver"}
|
|
instance.cleaver = Cleaver:new()
|
|
instance.idleCursor = love.graphics.newImage("assets/images/ui/cursor.png")
|
|
return instance
|
|
end
|
|
|
|
|
|
function Cursor:update(dt)
|
|
self.x, self.y = love.mouse.getPosition()
|
|
local isAboveMeatFactory = false
|
|
|
|
-- Check if cursor is above any meat factory
|
|
for _, meatFactory in ipairs(instances.meat_factories) do
|
|
if meatFactory:isHovering(self.x, self.y) then
|
|
isAboveMeatFactory = true
|
|
break
|
|
end
|
|
end
|
|
|
|
-- Update the cleaver state or cursor state accordingly
|
|
if isAboveMeatFactory then
|
|
self.state = "cleaver"
|
|
else
|
|
self.state = "idle"
|
|
end
|
|
|
|
-- You can also update the cleaver's state or position here if needed
|
|
self.cleaver:update(dt) -- Assuming Cleaver has an update function
|
|
end
|
|
|
|
function Cursor:draw()
|
|
if self.state == "cleaver" then
|
|
self.cleaver:draw(self.x, self.y)
|
|
elseif self.state == "idle" then
|
|
love.graphics.draw(self.idleCursor, self.x - self.idleCursor:getWidth() / 2, self.y - self.idleCursor:getHeight() / 2)
|
|
end
|
|
end
|
|
|
|
|
|
function Cursor:mousepressed(button)
|
|
if self.state == "cleaver" then
|
|
self.cleaver:mousepressed(button)
|
|
end
|
|
end
|
|
|
|
function Cursor:mousereleased(button)
|
|
if self.state == "cleaver" then
|
|
self.cleaver:mousereleased(button)
|
|
end
|
|
end
|
|
|
|
|
|
return Cursor
|
|
|
|
|
|
|
|
|