meat tables + factory creation
This commit is contained in:
parent
e52e10c0c8
commit
eb1a82d1f3
12 changed files with 161 additions and 16 deletions
37
cleaver.lua
37
cleaver.lua
|
|
@ -44,8 +44,12 @@ function Cleaver:update(dt)
|
|||
end
|
||||
|
||||
function Cleaver:draw()
|
||||
local x, y = love.mouse.getPosition()
|
||||
love.graphics.draw(self.currentImage, x - self.currentImage:getWidth() / 2, y - self.currentImage:getHeight() / 2)
|
||||
local x, y = love.mouse.getPosition()
|
||||
for _, meatTable in ipairs(instances.meat_tables) do
|
||||
if meatTable:isHovering(x,y) then
|
||||
love.graphics.draw(self.currentImage, x - self.currentImage:getWidth() / 2, y - self.currentImage:getHeight() / 2)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function Cleaver:mousepressed(button)
|
||||
|
|
@ -58,18 +62,27 @@ function Cleaver:mousepressed(button)
|
|||
end
|
||||
|
||||
function Cleaver:mousereleased(button)
|
||||
if button == 1 then -- Left mouse button
|
||||
if self.state == "charged" then
|
||||
self.state = "chop"
|
||||
self.currentImage = self.images.chop
|
||||
self.timer = 0
|
||||
self.scorePending = true
|
||||
elseif self.state == "windup" then
|
||||
self.state = "idle"
|
||||
self.currentImage = self.images.idle
|
||||
self.timer = 0
|
||||
if button == 1 then -- Left mouse button
|
||||
if self.state == "charged" then
|
||||
self.state = "chop"
|
||||
self.currentImage = self.images.chop
|
||||
self.timer = 0
|
||||
self.scorePending = true
|
||||
-- Check if the cleaver is hovering over a meat instance
|
||||
local x, y = love.mouse.getPosition()
|
||||
for i, meat in ipairs(instances.meats) do
|
||||
if x >= meat.x and x <= meat.x + meat.currentImage:getWidth() and y >= meat.y and y <= meat.y + meat.currentImage:getHeight() then
|
||||
-- Remove the meat instance from the table
|
||||
table.remove(instances.meats, i)
|
||||
break
|
||||
end
|
||||
end
|
||||
elseif self.state == "windup" then
|
||||
self.state = "idle"
|
||||
self.currentImage = self.images.idle
|
||||
self.timer = 0
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function Cleaver:getScore()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue