예제 #1
0
        private static void FillNamedAreas(IAtlas atlas, Map map)
        {
            ObjectGroup foregroundObjects = map.ObjectGroups.First(x => x.Name == "ForegroundObject");

            List <TmxObject> tmxMapObjects = foregroundObjects.TmxMapObjects;
            List <TmxObject> areaLabels    = tmxMapObjects.Where(x => x.Type.Trim() == "AreaLabel").ToList();

            IEnumerable <Vector2I>           positions      = areaLabels.Select(x => new Vector2I((int)Math.Floor(x.X), (int)Math.Floor(x.Y)));
            IEnumerable <string>             names          = areaLabels.Select(x => x.Name);
            List <Tuple <Vector2I, string> > namesPositions = positions.Zip(names, (x, y) => new Tuple <Vector2I, string>(x, y)).ToList();

            atlas.AreasCarrier = new AreasCarrier((ITileLayer)atlas.GetLayer(LayerType.Background),
                                                  (ITileLayer)atlas.GetLayer(LayerType.Area), namesPositions);
        }
        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);
                    }
                }
            }
        }
예제 #3
0
 public CollisionChecker(IAtlas atlas)
 {
     m_atlas = atlas;
     m_objectLayer = atlas.GetLayer(LayerType.Object) as SimpleObjectLayer;
     if (m_objectLayer != null)
     {
         m_physicalEntities = m_objectLayer.GetPhysicalEntities();
     }
     else
     {
         throw new ArgumentException("ObjectLayer not found.");
     }
 }
예제 #4
0
 public CollisionChecker(IAtlas atlas)
 {
     m_atlas       = atlas;
     m_objectLayer = atlas.GetLayer(LayerType.Object) as SimpleObjectLayer;
     if (m_objectLayer != null)
     {
         m_physicalEntities = m_objectLayer.GetPhysicalEntities();
     }
     else
     {
         throw new ArgumentException("ObjectLayer not found.");
     }
 }
예제 #5
0
        public Vector2 WhereIsObject(string name)
        {
            IObjectLayer layer = (IObjectLayer)m_atlas.GetLayer(LayerType.Object);

            return(layer.GetGameObject(name).Position);
        }
예제 #6
0
        private static void FillNamedAreas(IAtlas atlas, Map map)
        {
            ObjectGroup foregroundObjects = map.ObjectGroups.First(x => x.Name == "ForegroundObject");

            List<TmxObject> tmxMapObjects = foregroundObjects.TmxMapObjects;
            List<TmxObject> areaLabels = tmxMapObjects.Where(x => x.Type.Trim() == "AreaLabel").ToList();

            IEnumerable<Vector2I> positions = areaLabels.Select(x => new Vector2I((int)Math.Floor(x.X), (int)Math.Floor(x.Y)));
            IEnumerable<string> names = areaLabels.Select(x => x.Name);
            List<Tuple<Vector2I, string>> namesPositions = positions.Zip(names, (x, y) => new Tuple<Vector2I, string>(x, y)).ToList();

            atlas.AreasCarrier = new AreasCarrier((ITileLayer)atlas.GetLayer(LayerType.Background),
                (ITileLayer)atlas.GetLayer(LayerType.Area), namesPositions);
        }