タイルの衝突方法で問題が発生しています。何らかの理由で、プレーヤーが通過できないタイルを通過できる場合があります。また、理由はよくわかりませんが、スタックすると、オブジェクトを左に移動できますが、左にしか移動できません。以下にいくつかのコードを投稿しました。誰かが私を正しい方向に向けることができれば幸いです。(または、誰かが簡単な解決策を見つけることができればさらに良いことです!) 私のプレーヤー移動メソッドとタイル衝突メソッドは、両方とも更新メソッドで呼び出されます。
マップとタイルの衝突
map = { {1,1,1,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3},
{1,1,1,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3},
{1,1,1,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3},
{1,1,1,1,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3},
{1,1,1,1,1,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3},
{1,1,1,1,1,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3},
{2,1,1,1,1,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3},
{2,2,1,1,1,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3},
{2,2,1,1,1,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3},
{2,2,1,1,1,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3},
{2,2,1,1,1,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3},
{2,2,1,1,1,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3},
{2,2,1,1,1,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3},
{2,2,1,1,1,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3},
{2,2,1,1,1,3,3,1,1,1,1,1,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3},
{2,2,1,1,1,3,3,1,1,1,1,1,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3},
{2,2,1,1,1,3,3,1,1,1,1,1,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3},
{1,1,1,1,1,1,1,1,1,1,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3},
{1,1,1,1,1,1,1,1,1,1,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3},
{1,1,1,1,1,1,1,1,1,1,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3},
}
function testTile(x,y)
if map[y][x + 1] == 1 then
canRight = true
end
if map[y][x + 1] ~= 1 then
canRight = false
end
if map[y][x - 1] == 1 then
canLeft = true
end
if map[y][x - 1] ~= 1 then
canRight = false
end
if map[y + 1][x] == 1 then
canDown = true
end
if map[y + 1][x] ~= 1 then
canDown = false
end
if map[y - 1][x] == 1 then
canUp = true
end
if map[y - 1][x] ~= 1 then
canUp = false
end
end
function movePlayer(dt)
if love.keyboard.isDown("right") and canRight then
playerX = playerX + 1 * dt
end
if love.keyboard.isDown("left") and canLeft then
playerX = playerX - 1 * dt
end
if love.keyboard.isDown("down") and canDown then
playerY = playerY + 1 * dt
end
if love.keyboard.isDown("up") and canUp then
playerY = playerY - 1 * dt
end
end