get rid of meat table
This commit is contained in:
parent
620caa0ec7
commit
ede6bb6d91
5 changed files with 50 additions and 56 deletions
14
main.lua
14
main.lua
|
|
@ -1,6 +1,5 @@
|
||||||
-- imports
|
-- imports
|
||||||
local MeatFactory = require("src/meat_factory")
|
local MeatFactory = require("src/meat_factory")
|
||||||
local MeatTable = require("src/meat_tables")
|
|
||||||
local Cursor = require("src/cursor")
|
local Cursor = require("src/cursor")
|
||||||
|
|
||||||
-- main.lua
|
-- main.lua
|
||||||
|
|
@ -25,16 +24,13 @@ function love.load()
|
||||||
-- Load basic cursor
|
-- Load basic cursor
|
||||||
cursor = Cursor:new()
|
cursor = Cursor:new()
|
||||||
|
|
||||||
-- Load MeatTable
|
|
||||||
meatTable = MeatTable:new()
|
|
||||||
|
|
||||||
-- Create a MeatFactory instance
|
-- Create a MeatFactory instance
|
||||||
meatFactory = MeatFactory:new(5, {"chicken", "cow", "pig"}, meatTable)
|
meatFactory = MeatFactory:new(5, {"chicken", "cow", "pig"})
|
||||||
|
|
||||||
instances = {}
|
instances = {}
|
||||||
instances.meats = {}
|
instances.meats = {}
|
||||||
instances.meat_tables = {}
|
instances.meat_factories = {}
|
||||||
table.insert(instances.meat_tables, meatTable)
|
table.insert(instances.meat_factories, meatFactory)
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
@ -55,11 +51,11 @@ function love.draw()
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Draw butcher table
|
-- Draw butcher table
|
||||||
meatTable:draw()
|
meatFactory:draw()
|
||||||
|
|
||||||
-- Draw meat
|
-- Draw meat
|
||||||
for _, meat in ipairs(instances.meats) do
|
for _, meat in ipairs(instances.meats) do
|
||||||
love.graphics.draw(meat.currentImage, meat.x, meat.y)
|
meat:draw()
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -15,18 +15,18 @@ end
|
||||||
|
|
||||||
function Cursor:update(dt)
|
function Cursor:update(dt)
|
||||||
self.x, self.y = love.mouse.getPosition()
|
self.x, self.y = love.mouse.getPosition()
|
||||||
local isAboveMeatTable = false
|
local isAboveMeatFactory = false
|
||||||
|
|
||||||
-- Check if cursor is above any meat table
|
-- Check if cursor is above any meat factory
|
||||||
for _, meatTable in ipairs(instances.meat_tables) do
|
for _, meatFactory in ipairs(instances.meat_factories) do
|
||||||
if meatTable:isHovering(self.x, self.y) then
|
if meatFactory:isHovering(self.x, self.y) then
|
||||||
isAboveMeatTable = true
|
isAboveMeatFactory = true
|
||||||
break
|
break
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Update the cleaver state or cursor state accordingly
|
-- Update the cleaver state or cursor state accordingly
|
||||||
if isAboveMeatTable then
|
if isAboveMeatFactory then
|
||||||
self.state = "cleaver"
|
self.state = "cleaver"
|
||||||
else
|
else
|
||||||
self.state = "idle"
|
self.state = "idle"
|
||||||
|
|
|
||||||
23
src/meat.lua
23
src/meat.lua
|
|
@ -2,12 +2,16 @@
|
||||||
Meat = {}
|
Meat = {}
|
||||||
Meat.__index = Meat
|
Meat.__index = Meat
|
||||||
|
|
||||||
function Meat:new()
|
function Meat:new(x , y, meatType)
|
||||||
local instance = setmetatable({}, Meat)
|
local instance = setmetatable({}, Meat)
|
||||||
instance.meatType = ""
|
instance.meatType = meatType
|
||||||
instance.images = {}
|
instance.images = {}
|
||||||
|
instance.currentImage = ""
|
||||||
instance.scorePending = false
|
instance.scorePending = false
|
||||||
instance.value = 1
|
instance.value = 1
|
||||||
|
instance.x = x
|
||||||
|
instance.y = y
|
||||||
|
Meat.loadImages(instance)
|
||||||
return instance
|
return instance
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
@ -15,7 +19,22 @@ function Meat:loadImages()
|
||||||
self.images.chicken = love.graphics.newImage("assets/images/meats/chicken.png")
|
self.images.chicken = love.graphics.newImage("assets/images/meats/chicken.png")
|
||||||
self.images.pig = love.graphics.newImage("assets/images/meats/pig.png")
|
self.images.pig = love.graphics.newImage("assets/images/meats/pig.png")
|
||||||
self.images.cow = love.graphics.newImage("assets/images/meats/cow.png")
|
self.images.cow = love.graphics.newImage("assets/images/meats/cow.png")
|
||||||
|
if self.meatType == "chicken" then
|
||||||
self.currentImage = self.images.chicken
|
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
|
end
|
||||||
|
|
||||||
return Meat
|
return Meat
|
||||||
|
|
@ -4,12 +4,14 @@ MeatFactory.__index = MeatFactory
|
||||||
local Meat = require("src/meat")
|
local Meat = require("src/meat")
|
||||||
|
|
||||||
|
|
||||||
function MeatFactory:new(spawnRate, meatTypes, meatTable)
|
function MeatFactory:new(spawnRate, meatTypes)
|
||||||
local instance = setmetatable({}, MeatFactory)
|
local instance = setmetatable({}, MeatFactory)
|
||||||
instance.spawnRate = spawnRate
|
instance.spawnRate = spawnRate
|
||||||
instance.meatTypes = meatTypes
|
instance.meatTypes = meatTypes
|
||||||
instance.meatTable = meatTable
|
|
||||||
instance.spawnTimer = 0
|
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
|
return instance
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
@ -21,18 +23,17 @@ function MeatFactory:update(dt)
|
||||||
end
|
end
|
||||||
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()
|
function MeatFactory:spawnMeat()
|
||||||
local meatType = self.meatTypes[math.random(#self.meatTypes)]
|
local meatType = self.meatTypes[math.random(#self.meatTypes)]
|
||||||
local meat = Meat:new()
|
local meat = Meat:new(self.x , self.y, meatType)
|
||||||
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)
|
table.insert(instances.meats, meat)
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
@ -49,4 +50,8 @@ function MeatFactory:getMeatValue(meatType)
|
||||||
end
|
end
|
||||||
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
|
return MeatFactory
|
||||||
|
|
@ -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
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue