I don't get any error but when I try to execute code in my classes update and draw events it doesn't do anything
Code: Select all
local inspect = require("inspect")
local Class = require("class")
local Manager = Class:derive()
Manager.data =
{
instances = {},
graphics = {},
sounds = {},
music = {}
}
-- Local functions
function Manager:collision()
local collision = false
local index = nil --I want to implement this but don't know how
local value = nil
local state = nil
for i1, v1 in ipairs(self.data.instances) do
for i2, v2 in ipairs(self.data.instances) do
-- Checks if parallel, touching, intersecting in that order
if ((v1.x == v2.x or v1.x + v1.width == v2.x + v2.width) or
(v1.y == v2.y or v1.y + v1.Height == v2.y + v2.Height)) then
collision = true
index = i1
value = v1
state = 0
elseif ((v1.x == v2.x or v1.x + v1.width == v2.x + v2.width) and
(v1.y == v2.y or v1.y + v1.Height == v2.y + v2.Height)) then
collision = true
index = i1
value = v1
state = 1
elseif ((v1.x > v2.x and v1.x + v1.width <= v2.x + v2.width) and
(v1.y > v2.y and v1.y + v1.Height <= v2.y + v2.Height)) then
collision = true
index = i1
value = v1
state = 2
end
end
end
return index, value, state
end
-- Public functions
function Manager:load()
for _, v in ipairs(self.data.instances) do
--v:load(self.data.instances) --NOT WORKING
end
end
function Manager:update(dt)
for _, v in ipairs(self.data.instances) do
local icol, vcol, scol = self:collision()
if (vcol ~= nil) then v.collision(icol, vcol, scol) end --Collision
v:update(dt) --NOT WORKING
end
end
function Manager:draw()
for _, v in ipairs(self.data.instances) do
love.graphics.print(v.bulletSpeed, 0, 0) --NOT WORKING
v:draw() --NOT WORKING
end
end
return Manager
the table is not empty is contains class data so idk
Code: Select all
local Class = {}
Class.__index = Class
-- Default implementation
function Class:new() end
-- Create a new class type from our base class
function Class:derive(type)
local cls = {}
cls["__call"] = Class.__call
cls.type = type
cls.__index = cls
cls.base = self
setmetatable(cls, self)
return cls
end
-- Call a new Class
function Class:__call(...)
local inst = setmetatable({}, self)
inst:new(...)
return inst
end
-- Get type
function Class:get_type()
return self.type
end
-- Events
function Class:load() end
function Class:update() end
function Class:draw() end
function Class:collision() end
return Class