Hi! This is my first time developing a game and I’m doing a tile puzzle based on 15 puzzle game tutorial from Defold.
My game is different because the original code is for a puzzle 100% width and height on the display and as you can see my board is only 300x300 and display values are 412x848. In the original code, on the input function the x and y value is width and height / 75. I think it doesn’t work because I didn’t define the position of my board but I don’t know how.
How can I set the position of my board in this case?
function on_input(self, action_id, action)
if action_id == hash("press") and action.pressed and not self.done then
print(action.x, action.y)
--Fuera el tablero:
if action.x < 57 + 1 or action.x > 357 - 1 or action.y < 148 + 1 or action.y > 448 + 1 then
print("click outside")
return
--Dentro del tablero
elseif action.x >= 57 or action.x <= 357 or action.y >= 148 or action.y > 448 then
print("click inside")
end
if M.pausedGame == true then
M.mov = M.mov + 0
msg.post("/gui#exitPanel", "update_mov")
elseif M.pausedGame == false then
M.mov = M.mov + 1
msg.post("/gui#exitPanel", "update_mov")
else
M.mov = M.mov + 1
msg.post("/gui#exitPanel", "update_mov")
end
local x = math.ceil(action.x / 75)
local y = math.ceil(action.y / 75)
local ex, ey = find(self.board, 0)
if math.abs(x - ex) + math.abs(y - ey) == 1 then
print("moving tile")
self.board = swap(self.board, (4-ey)*4+ex, (4-y)*4+x)
draw(self.board)
M.mov = M.mov + 1
msg.post("/gui#exitPanel", "update_mov")
end
ex, ey = find(self.board,0)
if inversions(self.board) == 0 and ex == 4 then
self.done = true
msg.post("#done", "enable")
dtimer.stop(node_timer_1)
end
end
end