我是Löve的新手,對於任何錯誤我很抱歉,我可能已經說過了。 我見過Gridlocked Player教程,我想做一些基於他人的東西。這是一個看不見的迷宮,在你觸摸它們時畫出瓷磚。Love2d Gridlocked播放器問題
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中,並幫助識別問題。請閱讀[如何創建一個最小,完整,可驗證的示例](https://stackoverflow.com/help/mcve)知道你需要包含哪些代碼 – WhatsThePoint
感謝您的更正。 – Dayanne