When you insert objects into the bump world, you can use just about anything: a string, number, or table. If you use a table to define the bump world objects, you can define them along the lines of:
Code: Select all
local projectileProperties = {
isSolid = false,
isDamaging = true,
damage = {
amount = 2,
pushback = 2
}
}
--insert the object into the bump world
Now, we just need to define a filter with which to detect a player, or other collidable object:
Code: Select all
local projectileFilter = function(item, other)
if other.isPlayer then return 'touch'
elseif other.isWall then return 'bounce'
-- other possible cases
end
end
Now, when you update the projectile in the bump world, loop through the collisions:
Code: Select all
local actualX, actualY, collisions, numberOfCollisions = world:move(projectileInstance, targetX, targetY, projectileFilter)
for i = 1, numberOfCollisions do
-- the 'other' in collisions table entries returns the object that you use for adding objects into the bump world
if collisions[i].other.isPlayer then
-- deal damage to the player here
end
-- handle other collisions (eq. walls)
end
Because bump allows you to set up your objects in any number of ways you can pick whatever approach you wish. For instance, you could just store the player object itself in the bump world, or just a string id and use a lookup table in the collision resolution phase, or whatever you're comfortable with.