Here's a simple example of a filter working, The player can move through the orange block, but not the blue one.
Code: Select all
function love.load()
bump = require "bump"
world = bump.newWorld()
player = {
type = "player",
x = love.graphics.getWidth() / 2 - 16,
y = love.graphics.getHeight() / 2 - 16,
size = 32
}
solidWall = {
type = "solidWall",
x = 32,
y = 128,
width = 32,
height = 32
}
notSolidWall = {
type = "notSolidWall",
x = love.graphics.getWidth() - 64,
y = 128,
width = 32,
height = 32
}
world:add(player, player.x, player.y, player.size, player.size)
world:add(solidWall, solidWall.x, solidWall.y, solidWall.height, solidWall.width)
world:add(notSolidWall, notSolidWall.x, notSolidWall.y, notSolidWall.height, notSolidWall.width)
end
function playerFilter(item, other)
if other.type == "solidWall" then
return "slide"
elseif other.type == "notSolidWall" then
return "cross"
end
end
function love.update(dt)
local goalX, goalY = player.x, player.y
if love.keyboard.isDown("d") then
goalX = player.x + 200 * dt
elseif love.keyboard.isDown("a") then
goalX = player.x - 200 * dt
end
if love.keyboard.isDown("s") then
goalY = player.y + 200 * dt
elseif love.keyboard.isDown("w") then
goalY = player.y - 200 * dt
end
local actualX, actualY, cols = world:move(player, goalX, goalY, playerFilter)
player.x = actualX
player.y = actualY
end
function love.draw()
love.graphics.setColor(255, 255, 255)
love.graphics.rectangle("fill", player.x, player.y, player.size, player.size)
love.graphics.setColor(0, 125, 255)
love.graphics.rectangle("fill", solidWall.x, solidWall.y, solidWall.width, solidWall.height)
love.graphics.setColor(255, 125, 0)
love.graphics.rectangle("fill", notSolidWall.x, notSolidWall.y, notSolidWall.width, notSolidWall.height)
end
function love.keypressed(key)
if key == "escape" then love.event.push("quit") end
end
I'm pretty sure the problem is your filter is checking for a value that doesn't exist, so it always returns nil. Perhaps you can read over my code and figure things out.