So the last hours i tried to find a way and came up with a pretty loosy and messy solution i’m not so happy with yet. Maybe i find a more mathematical solution because this version works for now in this environment but when i think of moving the meant-to-be map later i’m kind of scared. Additionally it aint so accurate like i would like to wish, maybe you have a thought on this or two you want to share? Would love to hear it.
private function stuckCheck():void
{
var nw:Point = new Point(x - 16, y - 16);
var n:Point = new Point(x, y - 16);
var no:Point = new Point(x +16, y - 16);
var w:Point = new Point(x - 16, y);
var o:Point = new Point(x + 16, y);
var sw:Point = new Point(x - 16, y + 16);
var s:Point = new Point(x, y + 16);
var so:Point = new Point(x + 16, y + 16);
var nw2:Point = new Point(x - 32, y - 32); //
var nnw:Point = new Point(x - 16, y - 32); //
var nww:Point = new Point(x - 32, y - 16); //
var n2:Point = new Point(x, y - 32); //
var nno:Point = new Point(x +16, y - 32); //
var no2:Point = new Point(x +32, y - 32); //
var noo:Point = new Point(x +32, y - 16); //
var w2:Point = new Point(x - 32, y); //
var o2:Point = new Point(x + 32, y); //
var sww:Point = new Point(x - 32, y + 16); //
var sw2:Point = new Point(x - 32, y + 32); //
var ssw:Point = new Point(x - 16, y + 32); //
var s2:Point = new Point(x, y + 32); //
var sso:Point = new Point(x + 16, y + 32); //
var so2:Point = new Point(x + 32, y + 32); //
var soo:Point = new Point(x + 32, y + 16); //
if (collideTypes(["solid", "schlucht"], x, y))
{
if ((world as Alabsa)._mapGrid.getTile(Math.round(w.x / 16), Math.round(w.y / 16)) == true) { trace("WEST"); x+6}
if ((world as Alabsa)._mapGrid.getTile(Math.round(w2.x / 16), Math.round(w2.y / 16)) == true) { trace("WEST2"); x += 6 }
if ((world as Alabsa)._mapGrid.getTile(Math.round(nw2.x / 16), Math.round(nw2.y / 16)) == true) { trace("NORDWEST2"); x += 6; y+=6 }
if ((world as Alabsa)._mapGrid.getTile(Math.round(nnw.x / 16), Math.round(nnw.y / 16)) == true) { trace("NORDNORDWEST"); y += 6; x+=6 }
if ((world as Alabsa)._mapGrid.getTile(Math.round(nww.x / 16), Math.round(nww.y / 16)) == true) { trace("NORDWESTWEST"); y += 6; x += 6 }
if ((world as Alabsa)._mapGrid.getTile(Math.round(n2.x / 16), Math.round(n2.y / 16)) == true) { trace("NORD2"); y += 6; }
if ((world as Alabsa)._mapGrid.getTile(Math.round(nno.x / 16), Math.round(nno.y / 16)) == true) { trace("NORDNORDOST"); y += 6; x -=6 }
if ((world as Alabsa)._mapGrid.getTile(Math.round(no2.x / 16), Math.round(no2.y / 16)) == true) { trace("NORDOST2"); y += 6; x -= 6 }
if ((world as Alabsa)._mapGrid.getTile(Math.round(noo.x / 16), Math.round(noo.y / 16)) == true) { trace("NORDOSTOST"); y += 6; x -= 6 }
if ((world as Alabsa)._mapGrid.getTile(Math.round(o2.x / 16), Math.round(o2.y / 16)) == true) { trace("OST2") ; x -= 6}
if ((world as Alabsa)._mapGrid.getTile(Math.round(sww.x / 16), Math.round(sww.y / 16)) == true) { trace("SUWESTWEST"); y -= 6; x += 6 }
if ((world as Alabsa)._mapGrid.getTile(Math.round(sw2.x / 16), Math.round(sw2.y / 16)) == true) { trace("SUDWEST2") ; y -= 6; x += 6}
if ((world as Alabsa)._mapGrid.getTile(Math.round(ssw.x / 16), Math.round(ssw.y / 16)) == true) { trace("SUDSUDWEST"); y -= 6; x += 6 }
if ((world as Alabsa)._mapGrid.getTile(Math.round(s2.x / 16), Math.round(s2.y / 16)) == true) { trace("SUD2") ; y -= 6; }
if ((world as Alabsa)._mapGrid.getTile(Math.round(soo.x / 16), Math.round(soo.y / 16)) == true) { trace("SUDSUDOST"); y -= 6; x -= 6 }
if ((world as Alabsa)._mapGrid.getTile(Math.round(so2.x / 16), Math.round(so2.y / 16)) == true) { trace("SUDOST2"); y -=6; x -= 6 }
if ((world as Alabsa)._mapGrid.getTile(Math.round(sso.x / 16), Math.round(sso.y / 16)) == true) { trace("SUDSUDOST") ; y -= 6; x -=6}
if ((world as Alabsa)._mapGrid.getTile(Math.round(s.x / 16), Math.round(s.y / 16)) == true) { trace("SUD") ; y -= 6}
if ((world as Alabsa)._mapGrid.getTile(Math.round(o.x / 16), Math.round(o.y / 16)) == true) { trace("OST") ; x -= 6}
if ((world as Alabsa)._mapGrid.getTile(Math.round(nw.x / 16), Math.round(nw.y / 16)) == true) { trace("NORDWEST"); y += 6; x += 6 }
if ((world as Alabsa)._mapGrid.getTile(Math.round(sw.x / 16), Math.round(sw.y / 16)) == true) { trace("SUDWEST"); y -= 6; x += 6 }
if ((world as Alabsa)._mapGrid.getTile(Math.round(no.x / 16), Math.round(no.y / 16)) == true) { trace("NORDOST"); y += 6; x -= 6 }
if ((world as Alabsa)._mapGrid.getTile(Math.round(so.x / 16), Math.round(so.y / 16)) == true) { trace("SUDOST"); y -= 6; x -= 6 }
if ((world as Alabsa)._mapGrid.getTile(Math.round(n.x / 16), Math.round(n.y / 16)) == true) { trace("NORD") ; y +=6}
stuckCheckBegin = false;
}
}
this looks messy too - sorry for that!
the points in the top are possible tides around the enemy entity after spawning (in the end is a stuckCheckBegin to keep it only for added entities) somehow it didnt work in the added function.
and the // after some points is for the second circle around the entity because i wasnt sure if this is maybe over the top but later it seemed to be necessary because sometimes i didnt find a tile in the first circle but got still stucked (but not with a second circle)