public void MoveActor(DynamicActor actor, Vector2 newPos, float newRot) { if (actor.CollisionClass == CollisionClass.IsolatedNoPersist) { actor.Position = newPos; actor.Rotation = newRot; throw new Exception("you really shouldn't be doing this"); return; } moveActor_overlaps(actor, newPos, newRot); }
/// <summary> /// move an actor, updating ActorOverlaps for all affected tiles /// </summary> /// <param name="actor"></param> /// <param name="newPos"></param> void moveActor_overlaps(DynamicActor actor, Vector2 newPos, float newRot) { var initUV = actor.GetPosUV(); var initProximity = actor.GetProximityOverlaps(); actor.Position = newPos; actor.Rotation = newRot; var finalUV = actor.GetPosUV(); var finalProximity = actor.GetProximityOverlaps(); //main events if (initUV != finalUV) { var initTile = TileGrid[initUV]; var finalTile = TileGrid[finalUV]; initTile.OnMainExit(actor, finalTile); finalTile.OnMainEnter(actor, initTile); } //overlap events //note: could be optimized foreach (Tile ftile in finalProximity) { if (!initProximity.Contains(ftile)) { lock (ftile.ProximityActors) { ftile.ProximityActors.Add(actor); ftile.OnProximityEnter(actor); } } } foreach (Tile itile in initProximity) { if (!finalProximity.Contains(itile)) { lock (itile.ProximityActors) { itile.ProximityActors.Remove(actor); itile.OnProximityExit(actor); } } } }