Hardon Collider - Identifying objects
Posted: Sat Jun 15, 2013 7:03 pm
Hey!
Are there any neat ways to wrap the different collision scenarios into maintanable and extendable code? In C++, for instance, I would probably add a virtual method to a class. How can I achieve this using HC?
Basically what I want to do is identify e.g. what enemy is colliding with e.g. the wall, the ground etc. and call e.g. the collision method for that corresponding enemy. I am not sure how to go about this.
Example:
Thanks!
Are there any neat ways to wrap the different collision scenarios into maintanable and extendable code? In C++, for instance, I would probably add a virtual method to a class. How can I achieve this using HC?
Basically what I want to do is identify e.g. what enemy is colliding with e.g. the wall, the ground etc. and call e.g. the collision method for that corresponding enemy. I am not sure how to go about this.
Example:
Code: Select all
local function _collision(dt, a, b, dx, dy)
if a.collision ~= nil then
a:collision(b, dx, dy)
end
if b.collision ~= nil then
b:collision(a, dx, dy)
end
end
Code: Select all
entity = {}
entity.__index = {}
...
function entity:collision(other, dx, dy)
print("Collision!")
end