I stumbled across this problem in my game and maybe my solution will help someone else:
I want to change the player direction to match the wall they are standing on:
Having the wall tiles turn the player is error-prone, so I'm doing the work in the player
// analyze room layout
on enter do
x = 0
xStart = 0
xEnd = 0
while x<=24 do
tileName = name x,14
if tileName=="cornerLeft" then
xStart = x
elseif tileName=="cornerRight" then
xEnd = x
end
x++
end
end
// turn player
on update do
shrinkFactor = event.y
if xStart != xEnd then
if event.y<=10 then
// top area and middle area
if shrinkFactor>4 then
shrinkFactor = 4
end
emit "calculateShrinkage"
if event.x<xStartEffective then
swap "playerWest"
elseif event.x>xEndEffective then
swap "playerEast"
else
swap "player"
end
else
// bottom area
shrinkFactor -= 14
shrinkFactor *= -1
emit "calculateShrinkage"
if event.x<xStartEffective then
swap "playerWest"
elseif event.x>xEndEffective then
swap "playerEast"
else
swap "playerSouth"
end
end
end
end
on calculateShrinkage do
xStartEffective = xStart
xStartEffective += shrinkFactor
xEndEffective = xEnd
xEndEffective -= shrinkFactor
end
This works for different width rooms, because it measures the distance between the bottom corner tiles. From that the room layout is calculated and the player turned.