私はLöveに新しいです。 私はGridlocked Playerチュートリアルを見てきました。私は他の人に基づいてそのようなことをしたかったのです。それはあなたがそれらに触れるようにタイルを描画する目に見えない迷路です。Love2dグリッドロックされたプレーヤーの問題
local points = 0
width = love.graphics.getWidth()
height = love.graphics.getHeight()
function love.load()
picture = love.graphics.newImage("candy.png")
back = love.graphics.newImage("sky.jpg")
cloud = love.graphics.newImage("cloud.png")
love.mouse.setVisible(false)
song = love.audio.newSource('elevator.mp3')
song:setLooping(true)
song:play()
song:setVolume(0.1)
anime = love.graphics.newImage("anime.png")
music = love.audio.newSource("tick.mp3")
music:setVolume(0.3)
font = love.graphics.newFont("Kendal.ttf", 18)
font1 = love.graphics.newFont("Kendal.ttf", 40)
font2 = love.graphics.newFont("Kendal.ttf", 60)
player = {
grid_x = 256,
grid_y = 256,
act_x = 300,
act_y = 300,
speed = 20
}
map = {
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },
{ 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 },
{ 1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1 },
{ 1, 0, 1, 1, 0, 0, 0, 0, 1, 0, 0, 1, 0, 1 },
{ 1, 1, 1, 1, 0, 0, 0, 0, 1, 0, 0, 1, 0, 1 },
{ 1, 1, 0, 1, 0, 1, 1, 1, 1, 0, 0, 0, 0, 1 },
{ 1, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1 },
{ 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1 },
{ 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1 },
{ 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1 },
{ 1, 0, 0, 1, 0, 0, 0, 0, 1, 1, 1, 1, 0, 1 },
{ 1, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1 },
{ 1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1 },
{ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 }
}
-- Cria um array do mesmo tamanho do array de map
seen_tiles = {}
for yindex,column in ipairs(map) do
seen_tiles[yindex] = {}
for xindex,tile in ipairs(column) do
seen_tiles[yindex][xindex] = 0
end
end
end
function love.update(dt)
function testMap (x, y)
if map[(player.grid_y/32) + y][(player.grid_x/32) + x] == 1 then
-- Marca um bloco como visto assim que setá-lo para 1
seen_tiles[(player.grid_y/32) + y][(player.grid_x/32) + x] = 1
return false
end
return true
end
player.act_y = player.act_y - ((player.act_y - player.grid_y) * player.speed * dt)
player.act_x = player.act_x - ((player.act_x - player.grid_x) * player.speed * dt)
end
function love.draw()
love.graphics.draw(back, 0, 0)
love.graphics.setColor(3, 3, 3)
love.graphics.rectangle("fill", 580, 0, width, height)
love.graphics.setColor(255, 255, 255)
love.graphics.rectangle("fill", player.act_x, player.act_y, 32, 32)
love.graphics.draw(cloud, 591, 150, 0, 0.2111111)
love.graphics.setFont(font1)
love.graphics.print("Ghost Maze", 600, 200)
love.graphics.setFont(font)
love.graphics.print("Minimum movements: 12", 600, 280)
love.graphics.print("Your movements:" .. points, 600, 300)
love.graphics.draw(picture, love.mouse.getX() , love.mouse.getY())
love.graphics.draw(anime, 530, 360)
-- Desenha os blocos se eles forem marcados como vistos
for y=1, #seen_tiles do
for x=1, #seen_tiles[y] do
if seen_tiles[y][x] == 1 then
love.graphics.setColor(120, 0, 200)
love.graphics.rectangle("fill", x * 32, y * 32, 32, 32)
love.graphics.setColor(255,255,255)
end
end
end
end
function love.keypressed (key)
if key == "escape" then
love.event.quit()
end
if key == "up" then
if testMap (0, -1) then
player.grid_y = player.grid_y - 32
points = points + 1
love.audio.play(music)
end
elseif key == "down" then
if testMap (0, 1) then
player.grid_y = player.grid_y + 32
points = points + 1
love.audio.play(music)
end
elseif key == "left" then
if testMap (-1, 0) then
player.grid_x = player.grid_x - 32
points = points + 1
love.audio.play(music)
end
elseif key == "right" then
if testMap (1, 0) then
player.grid_x = player.grid_x + 32
points = points + 1
love.audio.play(music)
end
end
end
私の闘争は、文字(小箱)は「マップ」去るや否や、このエラーが発生したということです:Error。
私は迷路から出てきたときにレベルが完了したことを意味するいくつかの画面を表示したいが、この問題を解決する方法はほとんど分からない。
問題のコードを貼り付けて正しくフォーマットしてください。 – sudo
あなたの質問にテキストとしてコードを貼り付け、ハイライトしてCtrl + Kを押すと、コードをコピーしてIDEに貼り付けることができ、問題の特定に役立ちます。 – WhatsThePoint
を含める必要があるコードを知るには、[最小限で完全で検証可能な例の作成方法](https://stackoverflow.com/help/mcve)をお読みください。 – Dayanne