public static void AlwaysFace <T>(this T obj, IWithPosition other, ICondition condition) where T : IWorldObject { new LambdaAction <T>(obj, UpdatePriority.Behavior, obj.Layer.Scene, condition, (o, t) => { obj.Face(other); }); }
public StayRelativeTo(IWithPosition objectToMove, IWithPositionAndDirection origin, Vector2 offset, IWorldObject root) { Parent = origin; Offset = offset; Object = objectToMove; root.Layer.Scene.AddObject(this); Root = root; }
public static Direction CardinalDirectionTowards(this IWithPosition thisObject, IWithPosition other, Axis axis = GameEngine.Axis.Any) { var thisPos = thisObject.Position.Center; var otherPos = other.Position.Center; bool right = thisPos.X < otherPos.X; bool left = thisPos.X > otherPos.X; bool down = thisPos.Y < otherPos.Y; bool up = thisPos.Y > otherPos.Y; if (axis == GameEngine.Axis.X) { if (left) { return(Direction.Left); } else { return(Direction.Right); } } else if (axis == GameEngine.Axis.Y) { if (up) { return(Direction.Up); } else { return(Direction.Down); } } else { if (left && !up && !down) { return(Direction.Left); } else if (right && !up && !down) { return(Direction.Right); } else if (down && !left && !right) { return(Direction.Down); } else if (up && !left && !right) { return(Direction.Up); } else { return(Direction.None); } } }
public static bool ScanFor(object objectToScan, IWithPosition objectToFind) { var found = false; VisitSyntaxTree <IWithPosition>(objectToScan, x => { found |= objectToFind.Equals(x); }); return(found); }
public Animation(IRemoveable root, IWithPosition parent, Sprite sprite, params int[] frames) { Root = root; Parent = parent; TimePerFrame = new ConfigValue <TimeSpan>("animation frame"); Sprite = sprite; Frames = frames; CurrentFrameIndex = new CyclingInteger(frames.Length); DrawInfo = sprite.DrawInfo; }
public static void Face(this IWithPositionAndDirection obj, IWithPosition other) { if (obj.Position.Center.X < other.Position.Center.X) { obj.Direction = Direction.Right; } else if (obj.Position.Center.X > other.Position.Center.X) { obj.Direction = Direction.Left; } }
public static IWithPosition PutNextTo(this IWithPosition thisPos, IWithPosition otherPos, BorderSide side) { if (side == BorderSide.Bottom) { thisPos.Position.Center = otherPos.Position.Center; thisPos.Position.SetTop(otherPos.Position.Bottom); return(thisPos); } else { throw new NotSupportedException(); } }
public static IWithPosition DockInside(this IWithPosition thisPos, IWithPosition otherPos, BorderSide side) { if (side == BorderSide.Top) { thisPos.Position.Center = otherPos.Position.Center; thisPos.Position.SetTop(otherPos.Position.Top); return(thisPos); } else if (side == BorderSide.Right) { thisPos.Position.Center = otherPos.Position.Center; thisPos.Position.SetRight(otherPos.Position.Right); return(thisPos); } else { throw new NotSupportedException(); } }
public DebugRectangle(IWithPosition obj, Layer layer) { Layer = layer; Object = obj; Layer.AddObject(this); }
public Boundary(IWithPosition area) { Area = area; }
public static Rectangle GetEnclosingArea(this IWithPosition first, IWithPosition second) { return(first.Position.Copy().ExpandToContain(second.Position)); }
public static void SetPosition(this IWithPosition pos, float x, float y) { pos.Position.UpperLeft = new Vector2(x, y); }
public static IWithPosition Nudge(this IWithPosition thisPos, float x, float y) { thisPos.Position.Translate(x, y); return(thisPos); }
public static Direction DirectionAwayFrom(this IWithPosition thisObject, IWithPosition other, Axis axis) { return(thisObject.CardinalDirectionTowards(other, axis).Opposite()); }
public static void StayRelativeTo(this IWithPosition item, IWithPositionAndDirection parent, float xOff, float yOff, IWorldObject root) { new StayRelativeTo(item, parent, new Vector2(xOff, yOff), root); }