diff --git a/assets/images/env/butcher_table.png b/assets/images/env/butcher_table.png new file mode 100644 index 0000000..55ffe13 Binary files /dev/null and b/assets/images/env/butcher_table.png differ diff --git a/assets/images/env/new_table.png b/assets/images/env/new_table.png new file mode 100644 index 0000000..d650581 Binary files /dev/null and b/assets/images/env/new_table.png differ diff --git a/assets/images/env/newer_table.png b/assets/images/env/newer_table.png new file mode 100644 index 0000000..a43c15a Binary files /dev/null and b/assets/images/env/newer_table.png differ diff --git a/assets/images/tiles/tiles.png b/assets/images/tiles/tiles.png new file mode 100644 index 0000000..ada5c9e Binary files /dev/null and b/assets/images/tiles/tiles.png differ diff --git a/assets/images/tiles/tiles_bigger.png b/assets/images/tiles/tiles_bigger.png new file mode 100644 index 0000000..cd8ad2c Binary files /dev/null and b/assets/images/tiles/tiles_bigger.png differ diff --git a/assets/images/tiles/tiles_bigger_new.png b/assets/images/tiles/tiles_bigger_new.png new file mode 100644 index 0000000..fa76484 Binary files /dev/null and b/assets/images/tiles/tiles_bigger_new.png differ diff --git a/assets/images/ui/cursor.png b/assets/images/ui/cursor.png new file mode 100644 index 0000000..7c5aa99 Binary files /dev/null and b/assets/images/ui/cursor.png differ diff --git a/cleaver.lua b/cleaver.lua index cf812f3..0ca5333 100644 --- a/cleaver.lua +++ b/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() diff --git a/main.lua b/main.lua index ab945c0..f1cf0bd 100644 --- a/main.lua +++ b/main.lua @@ -1,5 +1,7 @@ -- imports local Cleaver = require("cleaver") +local MeatFactory = require("meat_factory") +local MeatTable = require("meat_tables") -- main.lua local font @@ -7,6 +9,7 @@ local cleaver local tileImage local bottomBar local profitLossBar +local meatFactory function love.load() font = love.graphics.newFont("assets/fonts/Born2bSportyFS.otf", 32) @@ -17,27 +20,52 @@ function love.load() cleaver:loadImages() -- Load tile image - tileImage = love.graphics.newImage("assets/images/tiles/chop-floor-tile.png") + 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 = love.graphics.newImage("assets/images/ui/cursor.png") + + -- Load MeatTable + meatTable = MeatTable:new() + + -- Create a MeatFactory instance + meatFactory = MeatFactory:new(5, {"chicken", "cow", "pig"}, meatTable) + + instances = {} + instances.meats = {} + instances.meat_tables = {} + table.insert(instances.meat_tables, meatTable) + end function love.update(dt) cleaver:update(dt) + meatFactory:update(dt) end function love.draw() -- Draw tile background local tileWidth = tileImage:getWidth() local tileHeight = tileImage:getHeight() - local scale = 4 -- Adjust this value to change the tile size + 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 + meatTable:draw() + + -- Draw meat + for _, meat in ipairs(instances.meats) do + love.graphics.draw(meat.currentImage, meat.x, meat.y) + end + + -- Draw bottom bar and score local bottomBarX = (love.graphics.getWidth() - bottomBar:getWidth()) / 2 local bottomBarY = love.graphics.getHeight() - bottomBar:getHeight() @@ -56,8 +84,13 @@ function love.draw() -- Draw profit/loss bar at top right love.graphics.draw(profitLossBar, love.graphics.getWidth() - profitLossBar:getWidth() - 10, 10) + local mouse_x, mouse_y = love.mouse.getPosition() + love.graphics.draw(cursor, mouse_x - cursor:getWidth() / 2, mouse_y - cursor:getHeight() / 2) + -- Draw cleaver cleaver:draw() + + end function love.mousepressed(x, y, button) @@ -66,4 +99,4 @@ end function love.mousereleased(x, y, button) cleaver:mousereleased(button) -end \ No newline at end of file +end diff --git a/meat.lua b/meat.lua new file mode 100644 index 0000000..3fa12c7 --- /dev/null +++ b/meat.lua @@ -0,0 +1,21 @@ +-- meat.lua +Meat = {} +Meat.__index = Meat + +function Meat:new() + local instance = setmetatable({}, Meat) + instance.meatType = "" + instance.images = {} + instance.scorePending = false + instance.value = 1 + return instance +end + +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 +end + +return Meat \ No newline at end of file diff --git a/meat_factory.lua b/meat_factory.lua new file mode 100644 index 0000000..7e90866 --- /dev/null +++ b/meat_factory.lua @@ -0,0 +1,52 @@ +-- meat-factory.lua +MeatFactory = {} +MeatFactory.__index = MeatFactory +local Meat = require("meat") + + +function MeatFactory:new(spawnRate, meatTypes, meatTable) + local instance = setmetatable({}, MeatFactory) + instance.spawnRate = spawnRate + instance.meatTypes = meatTypes + instance.meatTable = meatTable + instance.spawnTimer = 0 + return instance +end + +function MeatFactory:update(dt) + self.spawnTimer = self.spawnTimer + dt + if self.spawnTimer >= self.spawnRate then + self:spawnMeat() + self.spawnTimer = 0 + end +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 + table.insert(instances.meats, meat) + +end + +function MeatFactory:getMeatValue(meatType) + -- You can implement a logic to determine the value of the meat based on its type + -- For example: + if meatType == "chicken" then + return 10 + elseif meatType == "cow" then + return 20 + elseif meatType == "pig" then + return 15 + end +end + +return MeatFactory \ No newline at end of file diff --git a/meat_tables.lua b/meat_tables.lua new file mode 100644 index 0000000..b17153f --- /dev/null +++ b/meat_tables.lua @@ -0,0 +1,26 @@ +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