Пример #1
0
        private static void SetTileRelations(IAtlas atlas, Map map)
        {
            ObjectGroup foregroundObjects = map.ObjectGroups.FirstOrDefault(x => x.Name == "ForegroundObject");

            Debug.Assert(foregroundObjects != null, "foregroundObjects != null");
            List <TmxObject>        tmxMapObjects = foregroundObjects.TmxMapObjects;
            IEnumerable <TmxObject> switcherToSwitchablePolylines = tmxMapObjects.Where(x => x.Type == "SwitcherToSwitchable");

            foreach (TmxObject switcherToSwitchablePolyline in switcherToSwitchablePolylines)
            {
                Polyline polyline = switcherToSwitchablePolyline.Polyline;
                if (polyline == null)
                {
                    throw new ArgumentException("Foreground object SwitcherToSwitchable is wrong type. Should be Polyline.");
                }
                List <Vector2> polylinePoints = PolylineTransform(map, switcherToSwitchablePolyline).ToList();
                Vector2        source         = polylinePoints.First();
                Vector2        target         = polylinePoints.Last();
                IEnumerable <GameActorPosition> sourceGameActors = atlas.ActorsAt(source);
                GameActorPosition switcherPosition = sourceGameActors.FirstOrDefault(x => x.Actor is ISwitcherGameActor);
                if (switcherPosition == null)
                {
                    Log.Instance.Error("SwitcherToSwitchable polyline expects Switcher type at [" + source.X + ";" + source.Y + "].");
                    return;
                }
                ISwitcherGameActor switcherGameActor = switcherPosition.Actor as ISwitcherGameActor;

                IEnumerable <GameActorPosition> targetGameActors = atlas.ActorsAt(target);
                GameActorPosition switchablePosition             = targetGameActors.FirstOrDefault(x => x.Actor is ISwitchableGameActor);
                if (switchablePosition == null)
                {
                    Log.Instance.Error("SwitcherToSwitchable polyline expects Switchable type at [" + target.X + ";" + target.Y + "].");
                    return;
                }
                ISwitchableGameActor switchable = switchablePosition.Actor as ISwitchableGameActor;

                if (switcherGameActor != null)
                {
                    switcherGameActor.Switchable = switchable;
                }
            }
        }
Пример #2
0
 public void Switch(GameActorPosition gameActorPosition, IAtlas atlas)
 {
     Switchable = Switchable?.SwitchOn(null, atlas);
 }
Пример #3
0
 private void SwitchOff(GameActorPosition gameActorPosition, IAtlas atlas)
 {
     TilesetId  = AlternativeTextures.Id("Off");
     Switchable = Switchable?.Switch(gameActorPosition, atlas);
     m_On       = false;
 }