get rid of meat table
This commit is contained in:
parent
620caa0ec7
commit
ede6bb6d91
5 changed files with 50 additions and 56 deletions
|
|
@ -15,18 +15,18 @@ end
|
|||
|
||||
function Cursor:update(dt)
|
||||
self.x, self.y = love.mouse.getPosition()
|
||||
local isAboveMeatTable = false
|
||||
local isAboveMeatFactory = 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
|
||||
-- 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 isAboveMeatTable then
|
||||
if isAboveMeatFactory then
|
||||
self.state = "cleaver"
|
||||
else
|
||||
self.state = "idle"
|
||||
|
|
|
|||
25
src/meat.lua
25
src/meat.lua
|
|
@ -2,12 +2,16 @@
|
|||
Meat = {}
|
||||
Meat.__index = Meat
|
||||
|
||||
function Meat:new()
|
||||
function Meat:new(x , y, meatType)
|
||||
local instance = setmetatable({}, Meat)
|
||||
instance.meatType = ""
|
||||
instance.meatType = meatType
|
||||
instance.images = {}
|
||||
instance.currentImage = ""
|
||||
instance.scorePending = false
|
||||
instance.value = 1
|
||||
instance.x = x
|
||||
instance.y = y
|
||||
Meat.loadImages(instance)
|
||||
return instance
|
||||
end
|
||||
|
||||
|
|
@ -15,7 +19,22 @@ function Meat:loadImages()
|
|||
self.images.chicken = love.graphics.newImage("assets/images/meats/chicken.png")
|
||||
self.images.pig = love.graphics.newImage("assets/images/meats/pig.png")
|
||||
self.images.cow = love.graphics.newImage("assets/images/meats/cow.png")
|
||||
self.currentImage = self.images.chicken
|
||||
if self.meatType == "chicken" then
|
||||
self.currentImage = self.images.chicken
|
||||
end
|
||||
if self.meatType == "pig" then
|
||||
self.currentImage = self.images.pig
|
||||
end
|
||||
if self.meatType == "cow" then
|
||||
self.currentImage = self.images.cow
|
||||
end
|
||||
end
|
||||
|
||||
function Meat:draw()
|
||||
local tableImage = love.graphics.newImage("assets/images/env/newer_table.png")
|
||||
local x = self.x + (tableImage:getWidth() - self.currentImage:getWidth()) - 15
|
||||
local y = self.y + (tableImage:getHeight() - self.currentImage:getHeight()) - 30
|
||||
love.graphics.draw(self.currentImage, x, y)
|
||||
end
|
||||
|
||||
return Meat
|
||||
|
|
@ -4,12 +4,14 @@ MeatFactory.__index = MeatFactory
|
|||
local Meat = require("src/meat")
|
||||
|
||||
|
||||
function MeatFactory:new(spawnRate, meatTypes, meatTable)
|
||||
function MeatFactory:new(spawnRate, meatTypes)
|
||||
local instance = setmetatable({}, MeatFactory)
|
||||
instance.spawnRate = spawnRate
|
||||
instance.meatTypes = meatTypes
|
||||
instance.meatTable = meatTable
|
||||
instance.spawnTimer = 0
|
||||
instance.image = love.graphics.newImage("assets/images/env/newer_table.png")
|
||||
instance.x = (love.graphics.getWidth() - instance.image:getWidth()) / 2;
|
||||
instance.y = (love.graphics.getHeight() - instance.image:getHeight()) / 2;
|
||||
return instance
|
||||
end
|
||||
|
||||
|
|
@ -21,18 +23,17 @@ function MeatFactory:update(dt)
|
|||
end
|
||||
end
|
||||
|
||||
function MeatFactory:draw()
|
||||
local x = self.x
|
||||
local image = self.image
|
||||
local y = self.y
|
||||
love.graphics.draw(image, x, y);
|
||||
end
|
||||
|
||||
|
||||
function MeatFactory:spawnMeat()
|
||||
local meatType = self.meatTypes[math.random(#self.meatTypes)]
|
||||
local meat = Meat:new()
|
||||
meat:loadImages() -- Load images for the meat
|
||||
meat.meatType = meatType
|
||||
meat.currentImage = meat.images[meatType]
|
||||
meat.value = self:getMeatValue(meatType)
|
||||
-- Set the x and y coordinates to be within the bounds of the meat table
|
||||
local meatTableX = (love.graphics.getWidth() - self.meatTable.image:getWidth()) / 2
|
||||
local meatTableY = (love.graphics.getHeight() - self.meatTable.image:getHeight()) / 2
|
||||
meat.x = meatTableX + (self.meatTable.image:getWidth() - meat.currentImage:getWidth()) - 15
|
||||
meat.y = meatTableY + (self.meatTable.image:getHeight() - meat.currentImage:getHeight()) - 30
|
||||
local meat = Meat:new(self.x , self.y, meatType)
|
||||
table.insert(instances.meats, meat)
|
||||
|
||||
end
|
||||
|
|
@ -49,4 +50,8 @@ function MeatFactory:getMeatValue(meatType)
|
|||
end
|
||||
end
|
||||
|
||||
function MeatFactory:isHovering(x, y)
|
||||
return x >= self.x and x <= self.x + self.image:getWidth() and y >= self.y and y <= self.y + self.image:getHeight()
|
||||
end
|
||||
|
||||
return MeatFactory
|
||||
|
|
@ -1,26 +0,0 @@
|
|||
MeatTable = {}
|
||||
MeatTable.__index = MeatTable
|
||||
|
||||
function MeatTable:new()
|
||||
local instance = setmetatable({}, MeatTable)
|
||||
instance.image = love.graphics.newImage("assets/images/env/newer_table.png")
|
||||
instance.x = (love.graphics.getWidth() - instance.image:getWidth()) / 2;
|
||||
instance.y = (love.graphics.getHeight() - instance.image:getHeight()) / 2;
|
||||
return instance
|
||||
end
|
||||
|
||||
function MeatTable:draw()
|
||||
local x = self.x
|
||||
local image = self.image
|
||||
local y = self.y
|
||||
love.graphics.draw(image, x, y);
|
||||
end
|
||||
|
||||
function MeatTable:isHovering(x, y)
|
||||
return x >= self.x and x <= self.x + self.image:getWidth() and y >= self.y and y <= self.y + self.image:getHeight()
|
||||
end
|
||||
|
||||
|
||||
|
||||
|
||||
return MeatTable
|
||||
Loading…
Add table
Add a link
Reference in a new issue