Example #1
0
        public void TestActorsAt()
        {
            List <GameActorPosition> results = m_atlas.ActorsAt(new Vector2(2, 2)).ToList();

            Assert.IsType <Background>(results[0].Actor);
            Assert.IsType <Avatar>(results[1].Actor);
        }
        public void Update()
        {
            IObjectLayer objectLayer = m_atlas.GetLayer(LayerType.Object) as IObjectLayer;

            Debug.Assert(objectLayer != null, "objectLayer != null");
            // for all game objects
            foreach (IGameObject gameObject in objectLayer.GetGameObjects())
            {
                List <Vector2I> coverTiles = gameObject.PhysicalEntity.CoverTiles();
                // for all covering tiles of this game objects
                foreach (Vector2I coverTile in coverTiles)
                {
                    IEnumerable <GameActorPosition> actorsAt = m_atlas.ActorsAt(new Vector2(coverTile),
                                                                                LayerType.TileLayers);
                    foreach (GameActorPosition result in actorsAt)
                    {
                        var tileDetector = result.Actor as IDetectorTile;

                        if (tileDetector == null)
                        {
                            continue;
                        }
                        if (tileDetector.RequiresCenterOfObject && !Atlas.Layers.Atlas.InsideTile(coverTile, gameObject.Position))
                        {
                            continue;
                        }

                        tileDetector.ObjectDetected(gameObject, m_atlas, m_tilesetTable);
                    }
                }
            }
        }
Example #3
0
        public void Update(IAtlas atlas)
        {
            List <Vector2I> free = atlas.FreePositionsAround(Position, LayerType.Obstacle | LayerType.Object).ToList();

            if (free.Count == 0)
            {
                return;
            }

            // filter out position with PathTiles
            free = free.Where(x => atlas.ActorsAt((Vector2)x, LayerType.Background).First().Actor.GetType() != typeof(PathTile)).ToList();
            if (free.Count == 0)
            {
                return;
            }

            Vector2I targetPosition = free[m_rng.Next(free.Count)];

            object[]          args          = { targetPosition };
            Fruit             fruit         = (Fruit)Activator.CreateInstance(typeof(T), args);
            GameActorPosition fruitPosition = new GameActorPosition(fruit, new Vector2(targetPosition), LayerType.ObstacleInteractable);

            atlas.Add(fruitPosition);

            NextUpdateAfter = m_updatePeriod;
        }
Example #4
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;
                }
            }
        }
        internal static GameActorPosition GetNearest(int x, int y, string type, IAtlas atlas)
        {
            Type t = GameActor.GetGameActorType(type);

            for (int i = 1; i < 20; i++)
            {
                IEnumerable <Vector2I> vonNeumannNeighborhood = Neighborhoods.VonNeumannNeighborhood(new Vector2I(x, y), i);

                foreach (var xy in vonNeumannNeighborhood)
                {
                    foreach (GameActorPosition gameActorPosition in atlas.ActorsAt((Vector2)xy))
                    {
                        if (gameActorPosition.Actor.GetType() == t)
                        {
                            return(gameActorPosition);
                        }
                    }
                }
            }
            return(null);
        }
 public void Update(IAtlas atlas, ITilesetTable table)
 {
     if (Heat < 0)
     {
         // first update - fire starts
         Heat = 0.2f;
         atlas.RegisterHeatSource(this);
         NextUpdateAfter = 60;
     }
     if (Heat >= MAX_HEAT && m_counter > 1000)
     {
         // fourth update - fire is extinguished.
         Heat            = 0;
         NextUpdateAfter = 0;
         var fireplace = new Fireplace(table, Position);
         atlas.UnregisterHeatSource(this);
         atlas.ReplaceWith(ThisGameActorPosition(LayerType.OnGroundInteractable), fireplace);
         return;
     }
     if (Heat < MAX_HEAT)
     {
         // second update - fire is growing
         Heat += 0.4f;
     }
     if (Heat >= MAX_HEAT)
     {
         // third update - fire is stable
         IEnumerable <GameActorPosition> gameActorPositions = atlas.ActorsAt((Vector2)Position, LayerType.All);
         foreach (GameActorPosition gameActorPosition in gameActorPositions)
         {
             ICombustibleGameActor combustible = gameActorPosition.Actor as ICombustibleGameActor;
             if (combustible != null)
             {
                 combustible.Burn(gameActorPosition, atlas, table);
             }
         }
         m_counter++;
     }
 }
 public void Update(IAtlas atlas, ITilesetTable table)
 {
     if (Heat < 0)
     {
         // first update - fire starts
         Heat = 0.2f;
         atlas.RegisterHeatSource(this);
         NextUpdateAfter = 60;
     }
     if (Heat >= MAX_HEAT && m_counter > 1000)
     {
         // fourth update - fire is extinguished.
         Heat = 0;
         NextUpdateAfter = 0;
         var fireplace = new Fireplace(table, Position);
         atlas.UnregisterHeatSource(this);
         atlas.ReplaceWith(ThisGameActorPosition(LayerType.OnGroundInteractable), fireplace);
         return;
     }
     if (Heat < MAX_HEAT)
     {
         // second update - fire is growing
         Heat += 0.4f;
     }
     if(Heat >= MAX_HEAT)
     {
         // third update - fire is stable
         IEnumerable<GameActorPosition> gameActorPositions = atlas.ActorsAt((Vector2) Position, LayerType.All);
         foreach (GameActorPosition gameActorPosition in gameActorPositions)
         {
             ICombustibleGameActor combustible = gameActorPosition.Actor as ICombustibleGameActor;
             if (combustible != null)
             {
                 combustible.Burn(gameActorPosition, atlas, table);
             }
         }
         m_counter++;
     }
 }
Example #8
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;
            }
        }