public static Pos GetDirPos(Pos start, Pos finish) { int x = 0; int y = 0; if (finish.x > start.x) x = 1; else if (finish.x < start.x) x = -1; if (finish.y > start.y) y = 1; else if (finish.y < start.y) y = -1; return new Pos(x, y); }
public static bool IsAdjacentTo(Pos one, Pos two, bool countDiag) { int diffX = one.x - two.x; int diffY = one.y - two.y; // Out of range if (Math.Abs(diffX) > 1) return false; // Out of range if (Math.Abs(diffY) > 1) return false; // Diagonal if (Math.Abs(diffX) == 1 && Math.Abs(diffY) == 1 && countDiag == false) return false; return true; }
public bool CanSeeTile(Pos tp, bool useCollisionInsteadOfSight, int radiusToUse) { return CanSeeTile(tp.x, tp.y, useCollisionInsteadOfSight, radiusToUse); }
public PathNode() { pos = Pos.Zero; parent = null; g = 0; h = 0; }
public static Pos ApplyDirPos(Pos coordPos, Pos dirPos) { return new Pos(coordPos.x + dirPos.x, coordPos.y + dirPos.y); }
public bool IsAdjacentTo(Pos other, bool countDiag) { return Pos.IsAdjacentTo(this, other, countDiag); }
public PathNode(Pos p, PathNode par, int curG, int calcH) { pos = p; parent = par; g = curG; h = calcH; }
public int Distance(Pos other) { return (int)Math.Sqrt(Math.Pow((other.x - x), 2) + Math.Pow((other.y - y), 2)); }
/// <summary> /// This version passes by reference to avoid copying the Pos every call--should help with GC and memory /// </summary> /// <param name="other"></param> /// <returns></returns> public bool CompareRef(ref Pos other) { if (x == other.x && y == other.y) return true; else return false; }
public bool CanSeeTile(int tx, int ty, bool useCollisionInsteadOfSight, int radiusToUse) { bool canSee = false; int radius = radiusToUse; Pos pos = this; if (this.x == tx && this.y == ty) return true; if (tx < pos.x + radius && tx > pos.x - radius) { if (ty < pos.y + radius && ty > pos.y - radius) { int distance = pos.Distance(new Pos(tx, ty)); if (distance <= radius) { int xdir = 0; int ydir = 0; if (tx < pos.x) xdir = -1; if (tx > pos.x) xdir = 1; if (ty < pos.y) ydir = -1; if (ty > pos.y) ydir = 1; int xtravel = Math.Abs(pos.x - tx); int ytravel = Math.Abs(pos.y - ty); Pos cursor = new Pos(pos.x, pos.y); for (int i = 0; i < distance; i++) { cursor.x += xdir; cursor.y += ydir; ytravel--; xtravel--; if (ytravel <= 0) ydir = 0; if (xtravel <= 0) xdir = 0; bool blocked = false; // TODO: implement this //if (useCollisionInsteadOfSight) // blocked = Game.level.CheckCollision(cursor, true); //else // blocked = Game.level.CheckBlocksSight(cursor); if (blocked) { if (i == distance - 1) canSee = true; else canSee = false; break; } else canSee = true; } } } else { canSee = false; } } else { canSee = false; } return canSee; }
public WorldCollisionType CheckCollision(Entity mover, int x, int y, bool aiCalc, Pos dest) { return WorldCollisionType.None; }
public WorldCollisionType CheckCollision(Entity mover, Pos p) { return CheckCollision(mover, p.x, p.y, false, p); }