meat tables + factory creation
BIN
assets/images/env/butcher_table.png
vendored
Normal file
|
After Width: | Height: | Size: 732 B |
BIN
assets/images/env/new_table.png
vendored
Normal file
|
After Width: | Height: | Size: 565 B |
BIN
assets/images/env/newer_table.png
vendored
Normal file
|
After Width: | Height: | Size: 665 B |
BIN
assets/images/tiles/tiles.png
Normal file
|
After Width: | Height: | Size: 1.3 KiB |
BIN
assets/images/tiles/tiles_bigger.png
Normal file
|
After Width: | Height: | Size: 1.8 KiB |
BIN
assets/images/tiles/tiles_bigger_new.png
Normal file
|
After Width: | Height: | Size: 1.5 KiB |
BIN
assets/images/ui/cursor.png
Normal file
|
After Width: | Height: | Size: 378 B |
13
cleaver.lua
|
|
@ -45,7 +45,11 @@ end
|
||||||
|
|
||||||
function Cleaver:draw()
|
function Cleaver:draw()
|
||||||
local x, y = love.mouse.getPosition()
|
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)
|
love.graphics.draw(self.currentImage, x - self.currentImage:getWidth() / 2, y - self.currentImage:getHeight() / 2)
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function Cleaver:mousepressed(button)
|
function Cleaver:mousepressed(button)
|
||||||
|
|
@ -64,6 +68,15 @@ function Cleaver:mousereleased(button)
|
||||||
self.currentImage = self.images.chop
|
self.currentImage = self.images.chop
|
||||||
self.timer = 0
|
self.timer = 0
|
||||||
self.scorePending = true
|
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
|
elseif self.state == "windup" then
|
||||||
self.state = "idle"
|
self.state = "idle"
|
||||||
self.currentImage = self.images.idle
|
self.currentImage = self.images.idle
|
||||||
|
|
|
||||||
37
main.lua
|
|
@ -1,5 +1,7 @@
|
||||||
-- imports
|
-- imports
|
||||||
local Cleaver = require("cleaver")
|
local Cleaver = require("cleaver")
|
||||||
|
local MeatFactory = require("meat_factory")
|
||||||
|
local MeatTable = require("meat_tables")
|
||||||
|
|
||||||
-- main.lua
|
-- main.lua
|
||||||
local font
|
local font
|
||||||
|
|
@ -7,6 +9,7 @@ local cleaver
|
||||||
local tileImage
|
local tileImage
|
||||||
local bottomBar
|
local bottomBar
|
||||||
local profitLossBar
|
local profitLossBar
|
||||||
|
local meatFactory
|
||||||
|
|
||||||
function love.load()
|
function love.load()
|
||||||
font = love.graphics.newFont("assets/fonts/Born2bSportyFS.otf", 32)
|
font = love.graphics.newFont("assets/fonts/Born2bSportyFS.otf", 32)
|
||||||
|
|
@ -17,27 +20,52 @@ function love.load()
|
||||||
cleaver:loadImages()
|
cleaver:loadImages()
|
||||||
|
|
||||||
-- Load tile image
|
-- 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
|
-- Load UI images for bottom bar and profit/loss bar
|
||||||
bottomBar = love.graphics.newImage("assets/images/ui/chopping-bottom-bar.png")
|
bottomBar = love.graphics.newImage("assets/images/ui/chopping-bottom-bar.png")
|
||||||
profitLossBar = love.graphics.newImage("assets/images/ui/chopping-profitloss-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
|
end
|
||||||
|
|
||||||
function love.update(dt)
|
function love.update(dt)
|
||||||
cleaver:update(dt)
|
cleaver:update(dt)
|
||||||
|
meatFactory:update(dt)
|
||||||
end
|
end
|
||||||
|
|
||||||
function love.draw()
|
function love.draw()
|
||||||
-- Draw tile background
|
-- Draw tile background
|
||||||
local tileWidth = tileImage:getWidth()
|
local tileWidth = tileImage:getWidth()
|
||||||
local tileHeight = tileImage:getHeight()
|
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 x = 0, love.graphics.getWidth(), tileWidth * scale do
|
||||||
for y = 0, love.graphics.getHeight(), tileHeight * scale do
|
for y = 0, love.graphics.getHeight(), tileHeight * scale do
|
||||||
love.graphics.draw(tileImage, x, y, 0, scale, scale)
|
love.graphics.draw(tileImage, x, y, 0, scale, scale)
|
||||||
end
|
end
|
||||||
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
|
-- Draw bottom bar and score
|
||||||
local bottomBarX = (love.graphics.getWidth() - bottomBar:getWidth()) / 2
|
local bottomBarX = (love.graphics.getWidth() - bottomBar:getWidth()) / 2
|
||||||
local bottomBarY = love.graphics.getHeight() - bottomBar:getHeight()
|
local bottomBarY = love.graphics.getHeight() - bottomBar:getHeight()
|
||||||
|
|
@ -56,8 +84,13 @@ function love.draw()
|
||||||
-- Draw profit/loss bar at top right
|
-- Draw profit/loss bar at top right
|
||||||
love.graphics.draw(profitLossBar, love.graphics.getWidth() - profitLossBar:getWidth() - 10, 10)
|
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
|
-- Draw cleaver
|
||||||
cleaver:draw()
|
cleaver:draw()
|
||||||
|
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
function love.mousepressed(x, y, button)
|
function love.mousepressed(x, y, button)
|
||||||
|
|
|
||||||
21
meat.lua
Normal file
|
|
@ -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
|
||||||
52
meat_factory.lua
Normal file
|
|
@ -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
|
||||||
26
meat_tables.lua
Normal file
|
|
@ -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
|
||||||