creating cursor class pt 1
This commit is contained in:
parent
409800a54f
commit
620caa0ec7
6 changed files with 83 additions and 26 deletions
65
src/cursor.lua
Normal file
65
src/cursor.lua
Normal file
|
|
@ -0,0 +1,65 @@
|
|||
--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 isAboveMeatTable = false
|
||||
|
||||
-- Check if cursor is above any meat table
|
||||
for _, meatTable in ipairs(instances.meat_tables) do
|
||||
if meatTable:isHovering(self.x, self.y) then
|
||||
isAboveMeatTable = true
|
||||
break
|
||||
end
|
||||
end
|
||||
|
||||
-- Update the cleaver state or cursor state accordingly
|
||||
if isAboveMeatTable 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
|
||||
|
||||
|
||||
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue