Fixed outer tile flag generation

The flags were not properly set for tiles where y equaled 0 or x equaled 0 due to the way the code checked surrounding elements. It now has special logic for those outer tiles.