Beispiel #1
0
        private void FromWorldMap(Stream dat)
        {
            var map = new Wmap(Manager.GameData);

            Map        = map;
            entityInc  = 0;
            entityInc += Map.Load(dat, 0);

            int w = Map.Width, h = Map.Height;

            Obstacles = new byte[w, h];
            for (var y = 0; y < h; y++)
            {
                for (var x = 0; x < w; x++)
                {
                    try
                    {
                        var        tile = Map[x, y];
                        ObjectDesc desc;
                        if (Manager.GameData.Tiles[tile.TileId].NoWalk)
                        {
                            Obstacles[x, y] = 3;
                        }
                        if (Manager.GameData.ObjectDescs.TryGetValue(tile.ObjType, out desc))
                        {
                            if (desc.Class == "Wall" ||
                                desc.Class == "ConnectedWall" ||
                                desc.Class == "CaveWall")
                            {
                                Obstacles[x, y] = 2;
                            }
                            else if (desc.OccupySquare || desc.EnemyOccupySquare)
                            {
                                Obstacles[x, y] = 1;
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        Log.Error(ex);
                    }
                }
            }
            EnemiesCollision = new CollisionMap <Entity>(0, w, h);
            PlayersCollision = new CollisionMap <Entity>(1, w, h);

            Projectiles.Clear();
            StaticObjects.Clear();
            Enemies.Clear();
            Players.Clear();
            foreach (var i in Map.InstantiateEntities(Manager))
            {
                if (i.ObjectDesc != null &&
                    (i.ObjectDesc.OccupySquare || i.ObjectDesc.EnemyOccupySquare))
                {
                    Obstacles[(int)(i.X - 0.5), (int)(i.Y - 0.5)] = 2;
                }
                EnterWorld(i);
            }
        }
Beispiel #2
0
 public virtual void Dispose()
 {
     Manager       = null;
     Owner         = null;
     WorldInstance = null;
     Name          = null;
     states        = null;
     CurrentState  = null;
     CollisionNode = null;
     Parent        = null;
     projectiles   = null;
     posHistory    = null;
 }
        public IEnumerable <T> GetActiveChunks(CollisionMap <T> from)
        {
            if (from.w != w || from.h != h)
            {
                throw new ArgumentException("from");
            }

            HashSet <T> ret = new HashSet <T>();

            for (int y = 0; y < cH; y++)
            {
                for (int x = 0; x < cW; x++)
                {
                    if (from.chunks[x, y] != null)
                    {
                        for (int i = -ACTIVE_RADIUS; i <= ACTIVE_RADIUS; i++)
                        {
                            for (int j = -ACTIVE_RADIUS; j <= ACTIVE_RADIUS; j++)
                            {
                                if (x + j < 0 || x + j >= cW || y + i < 0 || y + i >= cH)
                                {
                                    continue;
                                }
                                CollisionNode <T> node = chunks[x + j, y + i];
                                while (node != null)
                                {
                                    ret.Add((T)node.Parent);
                                    node = node.Next;
                                }
                            }
                        }
                    }
                }
            }

            return(ret);
        }