From 868e7ef8f78a438144c992a0e9274b6eba488747 Mon Sep 17 00:00:00 2001 From: Juan Date: Thu, 11 Sep 2025 23:41:26 -0400 Subject: [PATCH] initial upgrade tabled for mr meat (wip) --- assets/images/ui/butcher_upgrades.png | Bin 0 -> 3130 bytes main.lua | 33 +++++ src/cleaver.lua | 11 +- src/upgrade_table.lua | 183 ++++++++++++++++++++++++++ 4 files changed, 224 insertions(+), 3 deletions(-) create mode 100644 assets/images/ui/butcher_upgrades.png diff --git a/assets/images/ui/butcher_upgrades.png b/assets/images/ui/butcher_upgrades.png new file mode 100644 index 0000000000000000000000000000000000000000..cdc05f69d8da7bb51bb85e3c541940f0b9130f04 GIT binary patch literal 3130 zcmeAS@N?(olHy`uVBq!ia0y~yV0y#Az{JAA#=yYfWL_=Iz`(#*9OUlAuWk&D^>ZN`sab%vG9t{Unp#9_LpMVjiLaT?Gl! zrziQTzq9>axl7=$WzRwV`E_&j*b>ZU?{0r9f0A z^;sJvYa@O!F)%dTWwB;pXyGhlVBjb|C#WWIepUaR$mM5lmNk@a-oVV@Fe8DTp~2uF z9|J?;Ipafu>-OKx|8AeP*Y59+e^2i3x2uo6`g;DVy4vF3mAgNhGbFI;ykTGvDBJmk zm0`DSd`)@fYi|RFJ?Ua#^XmlTHh!7;)mi-8#T{GTTX*k${r~&k`}?k2e*L(6p856P zvcEoCeyjby*YEFSq4b-Kx4>pSyvgy!L(Xf9yz}{`mR%*{}b8+k0+hdFRZk zy9^(sxIsRMyz!6~*~e4V%XGIrxB6Z4;`O=Gu)lZC-~Re1S-14=bEALz?$_@uoF=Pq z;t+ps3^fkR>QhQrbyY69o&dL#F1PqKXZs;&B0r~0cgM5u%Pv6Gp>=8>M^nao$} zGTu9X{rKV>Uf#)=u>l+x#&14!q|Q~<*}I1MLRumyVz{jj%#1k4I0IrcA})nN(VzzM z#+ygKZvQQN+0DSv@crHMx6h8|&)5bw4CL0PV@L0TL!k-eaIkjE!;ny6VBkO);se%! zND2t$;FL3}5H+Wa2G3~fQ5elLpn_yHD~x7^(X0S&KaFOE(X4= bottomBarX and x <= bottomBarX + bottomBar:getWidth() and + y >= bottomBarY and y <= bottomBarY + bottomBar:getHeight() then + upgradeTable:toggle() + return + end + + -- If upgrade table is open, don't allow other interactions + if upgradeTable:isOpen() then + return + end + cursor:mousepressed(button) end function love.mousereleased(x, y, button) + -- If upgrade table is open, don't allow other interactions + if upgradeTable:isOpen() then + return + end + cursor:mousereleased(button) end diff --git a/src/cleaver.lua b/src/cleaver.lua index 22d1f95..2a019b6 100644 --- a/src/cleaver.lua +++ b/src/cleaver.lua @@ -9,6 +9,9 @@ function Cleaver:new() instance.score = 0 instance.images = {} instance.frame = 1 + -- Upgrade properties + instance.pointsPerChop = 1 + instance.windupSpeedBonus = 0 Cleaver.loadImages(instance) return instance end @@ -34,9 +37,11 @@ function Cleaver:loadImages() end function Cleaver:update(dt) + local windupSpeed = math.max(0.05, 0.1 - self.windupSpeedBonus) + if self.state == "windup" then self.timer = self.timer + dt - if self.timer >= 0.1 then + if self.timer >= windupSpeed then self.frame = self.frame + 1 if self.frame > #self.images.windup then self.state = "charged" @@ -100,7 +105,7 @@ function Cleaver:mousereleased(button) -- Remove the meat instance from the table meat.meatFactory.hasMeat = false table.remove(instances.meats, i) - self.score = self.score + 1 + self.score = self.score + self.pointsPerChop break end end @@ -117,4 +122,4 @@ function Cleaver:getScore() return self.score end -return Cleaver \ No newline at end of file +return Cleaver diff --git a/src/upgrade_table.lua b/src/upgrade_table.lua index e69de29..3ebdc54 100644 --- a/src/upgrade_table.lua +++ b/src/upgrade_table.lua @@ -0,0 +1,183 @@ +-- upgrade_table.lua +UpgradeTable = {} +UpgradeTable.__index = UpgradeTable + +function UpgradeTable:new() + local instance = setmetatable({}, UpgradeTable) + instance.isVisible = false + instance.image = love.graphics.newImage("assets/images/ui/butcher_upgrades.png") + instance.x = (love.graphics.getWidth() - instance.image:getWidth()) / 2 + instance.y = (love.graphics.getHeight() - instance.image:getHeight()) / 2 + + -- Define upgrades + instance.upgrades = { + { + name = "Sharp Blade", + description = "Increases points per chop by 1", + cost = 10, + level = 0, + maxLevel = 10, + effect = "pointsPerChop", + value = 1, + x = instance.x + 50, + y = instance.y + 80, + width = 120, + height = 40 + }, + { + name = "Quick Hands", + description = "Reduces windup time", + cost = 25, + level = 0, + maxLevel = 5, + effect = "windupSpeed", + value = 0.02, + x = instance.x + 50, + y = instance.y + 130, + width = 120, + height = 40 + }, + { + name = "Meat Magnet", + description = "Increases meat spawn rate", + cost = 50, + level = 0, + maxLevel = 8, + effect = "spawnRate", + value = 0.5, + x = instance.x + 50, + y = instance.y + 180, + width = 120, + height = 40 + } + } + + return instance +end + +function UpgradeTable:update(dt) + -- Update position in case window is resized + self.x = (love.graphics.getWidth() - self.image:getWidth()) / 2 + self.y = (love.graphics.getHeight() - self.image:getHeight()) / 2 + + -- Update upgrade button positions + for _, upgrade in ipairs(self.upgrades) do + upgrade.x = self.x + 50 + upgrade.y = self.y + 80 + (_ - 1) * 50 + end +end + +function UpgradeTable:draw() + if not self.isVisible then return end + + -- Draw upgrade table background + love.graphics.draw(self.image, self.x, self.y) + + -- Draw upgrades + local font = love.graphics.getFont() + for _, upgrade in ipairs(self.upgrades) do + -- Draw upgrade button background + if upgrade.level < upgrade.maxLevel then + love.graphics.setColor(0.2, 0.2, 0.2, 0.8) + else + love.graphics.setColor(0.1, 0.5, 0.1, 0.8) + end + love.graphics.rectangle("fill", upgrade.x, upgrade.y, upgrade.width, upgrade.height) + + -- Draw upgrade button border + love.graphics.setColor(1, 1, 1) + love.graphics.rectangle("line", upgrade.x, upgrade.y, upgrade.width, upgrade.height) + + -- Draw upgrade text + love.graphics.setColor(1, 1, 1) + local nameText = upgrade.name .. " (" .. upgrade.level .. "/" .. upgrade.maxLevel .. ")" + love.graphics.print(nameText, upgrade.x + 5, upgrade.y + 5, 0, 0.4, 0.4) + + local costText = "Cost: $" .. self:getUpgradeCost(upgrade) + if upgrade.level >= upgrade.maxLevel then + costText = "MAX LEVEL" + end + love.graphics.print(costText, upgrade.x + 5, upgrade.y + 20, 0, 0.3, 0.3) + end + + -- Draw close button + love.graphics.setColor(0.8, 0.2, 0.2) + love.graphics.rectangle("fill", self.x + self.image:getWidth() - 30, self.y + 10, 20, 20) + love.graphics.setColor(1, 1, 1) + love.graphics.rectangle("line", self.x + self.image:getWidth() - 30, self.y + 10, 20, 20) + love.graphics.print("X", self.x + self.image:getWidth() - 25, self.y + 12, 0, 0.5, 0.5) + + love.graphics.setColor(1, 1, 1) -- Reset color +end + +function UpgradeTable:getUpgradeCost(upgrade) + return math.floor(upgrade.cost * math.pow(1.5, upgrade.level)) +end + +function UpgradeTable:canAffordUpgrade(upgrade, playerMoney) + return playerMoney >= self:getUpgradeCost(upgrade) and upgrade.level < upgrade.maxLevel +end + +function UpgradeTable:purchaseUpgrade(upgrade, cleaver) + local cost = self:getUpgradeCost(upgrade) + if cleaver:getScore() >= cost and upgrade.level < upgrade.maxLevel then + cleaver.score = cleaver.score - cost + upgrade.level = upgrade.level + 1 + + -- Apply upgrade effect + if upgrade.effect == "pointsPerChop" then + cleaver.pointsPerChop = (cleaver.pointsPerChop or 1) + upgrade.value + elseif upgrade.effect == "windupSpeed" then + cleaver.windupSpeedBonus = (cleaver.windupSpeedBonus or 0) + upgrade.value + elseif upgrade.effect == "spawnRate" then + -- Apply to all meat factories + for _, factory in ipairs(instances.meat_factories) do + factory.spawnRate = math.max(0.5, factory.spawnRate - upgrade.value) + end + end + + return true + end + return false +end + +function UpgradeTable:toggle() + self.isVisible = not self.isVisible +end + +function UpgradeTable:isOpen() + return self.isVisible +end + +function UpgradeTable:mousepressed(x, y, button) + if not self.isVisible or button ~= 1 then return false end + + -- Check close button + local closeX = self.x + self.image:getWidth() - 30 + local closeY = self.y + 10 + if x >= closeX and x <= closeX + 20 and y >= closeY and y <= closeY + 20 then + self:toggle() + return true + end + + -- Check upgrade buttons + for _, upgrade in ipairs(self.upgrades) do + if x >= upgrade.x and x <= upgrade.x + upgrade.width and + y >= upgrade.y and y <= upgrade.y + upgrade.height then + if self:canAffordUpgrade(upgrade, cursor.cleaver:getScore()) then + self:purchaseUpgrade(upgrade, cursor.cleaver) + end + return true + end + end + + -- If clicked inside the upgrade table but not on any button, consume the click + if x >= self.x and x <= self.x + self.image:getWidth() and + y >= self.y and y <= self.y + self.image:getHeight() then + return true + end + + return false +end + +return UpgradeTable