mr_meat/main.lua
2025-08-26 17:53:17 -04:00

95 lines
2.9 KiB
Lua

-- imports
local MeatFactory = require("src/meat_factory")
local Cursor = require("src/cursor")
-- main.lua
local font
local tileImage
local bottomBar
local profitLossBar
local meatFactory
function love.load()
font = love.graphics.newFont("assets/fonts/Born2bSportyFS.otf", 32)
love.graphics.setFont(font)
love.mouse.setVisible(false) -- Hide the default cursor
-- Load tile image
tileImage = love.graphics.newImage("assets/images/tiles/tiles_bigger_new.png")
-- Load UI images for bottom bar and profit/loss bar
bottomBar = love.graphics.newImage("assets/images/ui/chopping-bottom-bar.png")
profitLossBar = love.graphics.newImage("assets/images/ui/chopping-profitloss-bar.png")
-- Load basic cursor
cursor = Cursor:new()
-- Create a MeatFactory instance
meatFactory = MeatFactory:new(5, {"chicken"})
instances = {}
instances.meats = {}
instances.meat_factories = {}
table.insert(instances.meat_factories, meatFactory)
end
function love.update(dt)
cursor:update(dt)
meatFactory:update(dt)
for _, meat in ipairs(instances.meats) do
meat:update(dt)
end
end
function love.draw()
-- Draw tile background
local tileWidth = tileImage:getWidth()
local tileHeight = tileImage:getHeight()
local scale = 1 -- Adjust this value to change the tile size
for x = 0, love.graphics.getWidth(), tileWidth * scale do
for y = 0, love.graphics.getHeight(), tileHeight * scale do
love.graphics.draw(tileImage, x, y, 0, scale, scale)
end
end
-- Draw butcher table
meatFactory:draw()
-- Draw meat
for _, meat in ipairs(instances.meats) do
meat:draw()
end
-- Draw bottom bar and score
local bottomBarX = (love.graphics.getWidth() - bottomBar:getWidth()) / 2
local bottomBarY = love.graphics.getHeight() - bottomBar:getHeight()
love.graphics.draw(bottomBar, bottomBarX, bottomBarY)
-- Draw score on bottom bar
local scoreText = "Net Worth: "
local scoreValue = "$" .. tostring(cursor.cleaver:getScore())
local scoreTextWidth = font:getWidth(scoreText)
local scoreValueWidth = font:getWidth(scoreValue)
love.graphics.setColor(0, 0, 0) -- Black
love.graphics.print(scoreText, bottomBarX + 20, bottomBarY + (bottomBar:getHeight() - font:getHeight()) / 2 + 15)
love.graphics.setColor(0, 0.5, 0)
love.graphics.print(scoreValue, bottomBarX + 20 + scoreTextWidth, bottomBarY + (bottomBar:getHeight() - font:getHeight()) / 2 + 15)
love.graphics.setColor(1, 1, 1) -- Reset to white
-- Draw profit/loss bar at top right
love.graphics.draw(profitLossBar, love.graphics.getWidth() - profitLossBar:getWidth() - 10, 10)
-- Draw cursor
cursor:draw()
end
function love.mousepressed(x, y, button)
cursor:mousepressed(button)
end
function love.mousereleased(x, y, button)
cursor:mousereleased(button)
end