meat tables + factory creation
This commit is contained in:
parent
e52e10c0c8
commit
eb1a82d1f3
12 changed files with 161 additions and 16 deletions
52
meat_factory.lua
Normal file
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
|
||||
Loading…
Add table
Add a link
Reference in a new issue