【发布时间】:2014-04-04 01:28:50
【问题描述】:
我在瓷砖碰撞方法中遇到问题。出于某种原因,玩家可以通过一些不应通过的图块。另外,我不完全确定为什么,但是当它卡住时,它可以通过物体向左移动,但只能向左移动。我在下面发布了一些代码,如果有人能指出我正确的方向,那就太好了。 (如果有人能找到一个快速的解决方案,那就更好了!)我的玩家移动方法和瓷砖碰撞方法都在更新方法中调用。
地图和瓷砖碰撞
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
【问题讨论】:
-
欢迎来到 StackOverflow。为问题分配标签时请小心谨慎,并在 this 网站上查看其含义的描述。例如,由于这是一个面向专业程序员和其他程序员的网站,因此 RPG 标签指的是主要由专业程序员使用的 RPG 语言,而不是游戏玩家的松散术语。
标签: lua collision-detection tile love2d