From ede6bb6d912a23033bf77d59afc4fd0c34b01f46 Mon Sep 17 00:00:00 2001 From: mshj Date: Thu, 7 Aug 2025 22:27:48 -0400 Subject: [PATCH] get rid of meat table --- main.lua | 14 +++++--------- src/cursor.lua | 12 ++++++------ src/meat.lua | 25 ++++++++++++++++++++++--- src/meat_factory.lua | 29 +++++++++++++++++------------ src/meat_tables.lua | 26 -------------------------- 5 files changed, 50 insertions(+), 56 deletions(-) delete mode 100644 src/meat_tables.lua diff --git a/main.lua b/main.lua index c694b49..59a41b4 100644 --- a/main.lua +++ b/main.lua @@ -1,6 +1,5 @@ -- imports local MeatFactory = require("src/meat_factory") -local MeatTable = require("src/meat_tables") local Cursor = require("src/cursor") -- main.lua @@ -25,16 +24,13 @@ function love.load() -- Load basic cursor cursor = Cursor:new() - -- Load MeatTable - meatTable = MeatTable:new() - -- Create a MeatFactory instance - meatFactory = MeatFactory:new(5, {"chicken", "cow", "pig"}, meatTable) + meatFactory = MeatFactory:new(5, {"chicken", "cow", "pig"}) instances = {} instances.meats = {} - instances.meat_tables = {} - table.insert(instances.meat_tables, meatTable) + instances.meat_factories = {} + table.insert(instances.meat_factories, meatFactory) end @@ -55,11 +51,11 @@ function love.draw() end -- Draw butcher table - meatTable:draw() + meatFactory:draw() -- Draw meat for _, meat in ipairs(instances.meats) do - love.graphics.draw(meat.currentImage, meat.x, meat.y) + meat:draw() end diff --git a/src/cursor.lua b/src/cursor.lua index 1549c5e..88bf089 100644 --- a/src/cursor.lua +++ b/src/cursor.lua @@ -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" diff --git a/src/meat.lua b/src/meat.lua index 3fa12c7..beae489 100644 --- a/src/meat.lua +++ b/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 \ No newline at end of file diff --git a/src/meat_factory.lua b/src/meat_factory.lua index d67c817..4d30e99 100644 --- a/src/meat_factory.lua +++ b/src/meat_factory.lua @@ -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 \ No newline at end of file diff --git a/src/meat_tables.lua b/src/meat_tables.lua deleted file mode 100644 index b17153f..0000000 --- a/src/meat_tables.lua +++ /dev/null @@ -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 \ No newline at end of file