In my little game I'm going to have many things flying across the screen. I have implemented a crude collision detection system but it is poor. I have looked into using the Hardon Collider, but what I need to do is go through a list of many objects (not software objects, but more like entries). So I need to check to see if two entries have hit, and if so, which ones. I shall show you in simple code.
Code: Select all
enemies = {
enemy1 = {isHit = false, hp = 10},
enemy2 = {isHit = false, hp = 10},
enemy3 = {isHit = false, hp = 10}
}
-- This table would contain a ton of bullets.
bullets = {
bullet1 = { hasHit = false, target = "player"},
bullet2 = {hasBit = false, target = "enemy"},
bullet3 = {hasHit = false, target = "player"}
}
function on_colliding(object_one, object_two)
if hasHit(object_one, object_two) then
if object_one.target == "player" and object_two == enemy1 then
enemy1.isHit = true
end
end
end
Jeez, I don't even know where to begin with this.