View difference between Paste ID: WE2D4ds6 and Uqga4uR6
SHOW: | | - or go back to the newest paste.
1
local function move(map, startX, startY, dX, dY)
2
	local targetX, targetY = startX + dX, startY + dY
3
	if not map[targetX][targetY] then return startX, startY; end
4
	if map[targetX][targetY].isBox then
5
		local slideX, slideY = targetX + dX, targetY + dY
6
		if not (map[slideX] and map[slideX][slideY] and map[slideX][slideY].isWalkable) then return startX, startY; end
7-
		tileBlox[gameMap[targetX][targetY].id].x = gameMap[slideX][slideY].x
7+
		local empty, box = map[slideX][slideY], map[targetX][targetY]
8
		local sprite = tileBlox[box.id]
9
		sprite.x, sprite.y = empty.x, empty.y
10
		empty.id =  box.id
11
		empty.isBox = true
12
		empty.isWalkable = false
13
		box.id = 0
14
		box.isWalkable = true
15
		box.isBox = false
16
	end
17
end